public async Task <ActionResult <FinanceResponse> > PostFinance(MHKDTO.Models.Finance input) { // Check if the finance object already exists var existingFinanceObject = await _context.Finances .Where(f => f.Month == input.Month && f.Year == input.Year) .FirstOrDefaultAsync(); if (existingFinanceObject != null) { return(Conflict(input)); } var finance = new Data.Models.Finance { BSPE = input.BSPE, Minimum = input.Minimum, Maximum = input.Maximum, Month = input.Month, Year = input.Year, MonthlySum = input.MonthlySum, PeopleCount = input.PeopleCount }; _context.Finances.Add(finance); await _context.SaveChangesAsync(); var result = finance.MapFinanceResponse(); return(CreatedAtAction(nameof(GetFinance), new { id = result.Id }, result)); }
public async Task <IActionResult> PutFinance(int id, MHKDTO.Models.Finance input) { var finance = await _context.Finances.FindAsync(id); if (finance == null) { return(NotFound()); } finance.BSPE = input.BSPE; finance.Minimum = input.Minimum; finance.Maximum = input.Maximum; finance.MonthlySum = input.MonthlySum; finance.PeopleCount = input.PeopleCount; await _context.SaveChangesAsync(); return(NoContent()); }