public async Task <ActionResult <SaleResponse> > PostSale(MHKDTO.Models.Sale input) { // Check if the sale object already exists var existingSaleObject = await _context.Sales .Where(s => s.Month == input.Month && s.Year == input.Year) .FirstOrDefaultAsync(); if (existingSaleObject != null) { return(Conflict(input)); } var sale = new Data.Models.Sale { WeightNK = input.WeightNK, Minimum = input.Minimum, Maximum = input.Maximum, Month = input.Month, Year = input.Year, TotalTasks = input.TotalTasks, TasksOnTime = input.TasksOnTime }; _context.Sales.Add(sale); await _context.SaveChangesAsync(); var result = sale.MapSaleResponse(); return(CreatedAtAction(nameof(GetSale), new{ id = result.Id }, result)); }
public async Task <IActionResult> PutSale(int id, MHKDTO.Models.Sale input) { var sale = await _context.Sales.FindAsync(id); if (sale == null) { return(NotFound()); } sale.WeightNK = input.WeightNK; sale.Minimum = input.Minimum; sale.Maximum = input.Maximum; sale.TotalTasks = input.TotalTasks; sale.TasksOnTime = input.TasksOnTime; await _context.SaveChangesAsync(); return(NoContent()); }