6d8b6b3e59
Implemented DeliveryTask, Payment, and Sale entities with full CRUD, business logic, and API endpoints. Updated Order/OrderItem for sale linkage and fulfillment tracking. Registered new DbSets and DI services. Revised documentation for delivery, sale, and payment workflows.
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using Distribution.Data;
|
|
using Distribution.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Features.Order;
|
|
|
|
public class OrderRepository(AppDBContext context) : IOrderRepository
|
|
{
|
|
public async Task<Models.Order?> GetByIdAsync(Guid id) =>
|
|
await context.Orders.FindAsync(id);
|
|
|
|
public async Task<List<Models.Order>> GetAllAsync() =>
|
|
await context.Orders.ToListAsync();
|
|
|
|
public async Task<Models.Order?> GetBySaleIdAsync(Guid saleId) =>
|
|
await context.Orders.FirstOrDefaultAsync(o => o.FK_SaleId == saleId && o.IsActive);
|
|
|
|
public async Task AddAsync(Models.Order entity) =>
|
|
await context.Orders.AddAsync(entity);
|
|
|
|
public void Update(Models.Order entity) =>
|
|
context.Orders.Update(entity);
|
|
|
|
public void Remove(Models.Order entity)
|
|
{
|
|
entity.Status = Models.OrderStatus.Cancelled;
|
|
entity.IsActive = false;
|
|
context.Orders.Update(entity);
|
|
}
|
|
|
|
public async Task<List<Models.OrderItem>> GetItemsByOrderIdAsync(Guid orderId) =>
|
|
await context.OrderItems.Where(oi => oi.FK_OrderId == orderId).ToListAsync();
|
|
|
|
public async Task<List<Models.Order>> GetByStoreIdAsync(Guid storeId) =>
|
|
await context.Orders.Where(o => o.FK_StoreId == storeId && o.IsActive).ToListAsync();
|
|
|
|
public async Task AddItemsAsync(IEnumerable<Models.OrderItem> items) =>
|
|
await context.OrderItems.AddRangeAsync(items);
|
|
|
|
public async Task<List<Models.Order>> GetPendingByRouteIdAsync(Guid routeId) =>
|
|
await context.Orders
|
|
.Include(o => o.Store)
|
|
.Include(o => o.OrderItems)
|
|
.ThenInclude(i => i.Item)
|
|
.Where(o => o.IsActive
|
|
&& o.Store.FK_RouteId == routeId
|
|
&& (o.Status == OrderStatus.Pending || o.Status == OrderStatus.PartiallyFulfilled))
|
|
.ToListAsync();
|
|
}
|