public async Task <ProductArea> UpdateProductAreaAsync(ProductAreaView productArea, CancellationToken cancellationToken) { if (productArea == null) { throw new ArgumentNullException(nameof(productArea)); } var dbProductArea = await _context.ProductAreas .Where(eq => eq.AreaId == productArea.AreaId && eq.ProductId == productArea.ProductId) .SingleOrDefaultAsync(cancellationToken); dbProductArea.Length = productArea.Length; dbProductArea.Width = productArea.Width; dbProductArea.Income = productArea.Income; dbProductArea.Profit = productArea.Profit; _context.Entry(dbProductArea).State = EntityState.Modified; return(dbProductArea); }
public async Task <ProductArea> AddProductAreaAsync(ProductAreaView productArea, CancellationToken cancellationToken) { if (productArea == null) { throw new ArgumentNullException(nameof(productArea)); } var dbProductArea = new ProductArea { AreaId = productArea.AreaId, ProductId = productArea.ProductId, Length = productArea.Length, Width = productArea.Width, Income = productArea.Income, Profit = productArea.Profit, CreatedAt = DateTime.UtcNow }; await _context.ProductAreas.AddAsync(dbProductArea, cancellationToken); return(dbProductArea); }