private async Task UpdateSupplierIfChanged(EditCommand command, Domain.Models.PurchaseOrderAggregate.PurchaseOrder order) { if (order.Supplier.Id != command.SupplierId) { _context.Entry(order).Collection(o => o.LineItems).Load(); var supplier = await _context.Supplier.FindAsync(command.SupplierId); order.ChangeSupplier(supplier); } }
protected override async Task Handle(EditProductCategoryCommand request, CancellationToken cancellationToken) { var supplier = await _context.Supplier.FindAsync(request.SupplierId); var category = await _context.Entry(supplier).Collection(s => s.ProductCategories).Query() .Where(c => c.Id == request.CategoryId).SingleAsync(); category.Name = request.Name; await _context.SaveChangesAsync(); }
public async Task <Result> Handle(DeleteProductCommand request, CancellationToken cancellationToken) { var supplier = await _context.Supplier.FindAsync(request.SupplierId); var product = await _context.Entry(supplier).Collection(s => s.Products).Query() .Where(p => p.Id == request.ProductId).SingleAsync(); supplier.RemoveProduct(product); await _context.SaveChangesAsync(); return(new Result(request.SupplierId)); }
public async Task <Result> Handle(EditProductCommand request, CancellationToken cancellationToken) { var supplier = await _context.Supplier.FindAsync(request.SupplierId); var product = await _context.Entry(supplier).Collection(s => s.Products).Query() .Where(p => p.Id == request.ProductId).SingleAsync(); product.ProductCode = request.ProdCode; product.Name = request.ProdName; product.Price = request.Price; product.Category = await DetermineNewCategory(_context, supplier, product.Category, request.CategoryId); await _context.SaveChangesAsync(); return(new Result(request.SupplierId)); }
private async Task <ProductCategory> DetermineNewCategory( PoTrackerDbContext context, Domain.Models.SupplierAggregate.Supplier supplier, ProductCategory modelCategory, int?commandCategoryId) { if (modelCategory != null && commandCategoryId == null) { return(null); } if ((modelCategory == null && commandCategoryId != null) || (modelCategory != null && modelCategory.Id != commandCategoryId)) { return(await context.Entry(supplier).Collection(s => s.ProductCategories).Query() .Where(c => c.Id == commandCategoryId).SingleAsync()); } return(null); }