53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using Distribution.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Features.Route;
|
|
|
|
public class RouteRepository(AppDBContext context) : IRouteRepository
|
|
{
|
|
public async Task<Models.Route?> GetByIdAsync(Guid id) =>
|
|
await context.Routes.FindAsync(id);
|
|
|
|
public async Task<List<Models.Route>> GetAllAsync() =>
|
|
await context.Routes.ToListAsync();
|
|
|
|
public async Task AddAsync(Models.Route entity) =>
|
|
await context.Routes.AddAsync(entity);
|
|
|
|
public void Update(Models.Route entity) =>
|
|
context.Routes.Update(entity);
|
|
|
|
public void Remove(Models.Route entity)
|
|
{
|
|
entity.IsActive = false;
|
|
context.Routes.Update(entity);
|
|
}
|
|
|
|
public async Task<Models.User?> GetActiveUserAsync(Guid userId) =>
|
|
await context.Users.FirstOrDefaultAsync(u => u.Id == userId && u.IsActive);
|
|
|
|
public async Task<List<Models.Store>> GetStoresByIdsAsync(List<Guid> storeIds) =>
|
|
await context.Stores.Where(s => storeIds.Contains(s.Id)).ToListAsync();
|
|
|
|
public async Task<Models.Store?> GetStoreByIdAsync(Guid storeId) =>
|
|
await context.Stores.FindAsync(storeId);
|
|
|
|
public void UpdateStore(Models.Store store) =>
|
|
context.Stores.Update(store);
|
|
|
|
public async Task<Models.RouteVisitLog?> GetOpenVisitAsync(Guid routeId, Guid storeId) =>
|
|
await context.RouteVisitLogs
|
|
.Where(v => v.FK_RouteId == routeId && v.FK_StoreId == storeId && v.CheckOutAt == null)
|
|
.OrderByDescending(v => v.CheckInAt)
|
|
.FirstOrDefaultAsync();
|
|
|
|
public async Task AddVisitLogAsync(Models.RouteVisitLog log) =>
|
|
await context.RouteVisitLogs.AddAsync(log);
|
|
|
|
public void UpdateVisitLog(Models.RouteVisitLog log) =>
|
|
context.RouteVisitLogs.Update(log);
|
|
|
|
public async Task<List<Models.RouteVisitLog>> GetVisitsByStoreIdAsync(Guid storeId) =>
|
|
await context.RouteVisitLogs.Where(v => v.FK_StoreId == storeId).ToListAsync();
|
|
}
|