-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathLocationService.cs
More file actions
63 lines (55 loc) · 2.03 KB
/
LocationService.cs
File metadata and controls
63 lines (55 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using EventsExpress.Core.DTOs;
using EventsExpress.Core.IServices;
using EventsExpress.Db.EF;
using EventsExpress.Db.Entities;
using EventsExpress.Db.Enums;
using NetTopologySuite.Geometries;
namespace EventsExpress.Core.Services
{
public class LocationService : BaseService<EventLocation>, ILocationService
{
public LocationService(AppDbContext context, IMapper mapper)
: base(context, mapper)
{
}
public async Task<Guid> AddLocationToEvent(LocationDto locationDTO)
{
if (locationDTO.Type == LocationType.Map)
{
return LocationByPoint(locationDTO.Point)?.Id ?? await Create(new LocationDto { Id = locationDTO.Id, Point = locationDTO.Point, OnlineMeeting = null, Type = locationDTO.Type });
}
else
{
return LocationByURI(locationDTO.OnlineMeeting)?.Id ?? await Create(new LocationDto { Id = locationDTO.Id, Point = null, OnlineMeeting = locationDTO.OnlineMeeting, Type = locationDTO.Type });
}
}
public async Task<Guid> Create(LocationDto locationDTO)
{
var location = Mapper.Map<LocationDto, EventLocation>(locationDTO);
var result = Insert(location);
await Context.SaveChangesAsync();
return result.Id;
}
public LocationDto LocationByPoint(Point point)
{
var locationDTO = Mapper.Map<LocationDto>(Context.EventLocations
.Where(e =>
e.Point.X == point.X &&
e.Point.Y == point.Y)
.FirstOrDefault());
return locationDTO;
}
public LocationDto LocationByURI(string uri)
{
var locationDTO = Mapper.Map<LocationDto>(Context.EventLocations
.Where(e =>
e.OnlineMeeting == uri)
.FirstOrDefault());
return locationDTO;
}
}
}