-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCityRepository.cs
45 lines (43 loc) · 1.32 KB
/
CityRepository.cs
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
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Weather.Persistence.Models;
using Serilog;
namespace Weather.Persistence.Repositories
{
public class CityRepository : Repository<City>, ICityRepository
{
public CityRepository(IDbContextFactory dbContextFactory, ILogger logger) : base(dbContextFactory, logger)
{
}
/// <summary>
/// GetLastAccessedCityAsync
/// </summary>
/// <returns>City</returns>
public async Task<City> GetLastAccessedCityAsync()
{
var city = await DbContext.Cities.OrderByDescending(x=>x.AccessedDate).FirstOrDefaultAsync();
return city;
}
/// <summary>
/// InsertOrUpdateCityAsync
/// </summary>
/// <param name="city"></param>
/// <returns></returns>
public async Task InsertOrUpdateCityAsync(City city)
{
var entity = await GetEntity(city.Id);
if (entity != null)
{
entity.Name = city.Name;
entity.CountryId = city.CountryId;
entity.AccessedDate = city.AccessedDate;
await UpdateEntity(entity);
}
else
{
await AddEntity(city);
}
}
}
}