public async Task <IActionResult> PostBalanceOfPayment([FromBody] BalanceOfPayment balanceOfPayment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.BalanceOfPayments.Add(balanceOfPayment); await _context.SaveChangesAsync(); var createdBalanceOfPayment = _context.BalanceOfPayments.Include(eR => eR.Year).Include(e => e.Month).Select(xc => new YearViewModel { ID = xc.ID, YearId = xc.Year.ID, BalanceOfPayments = xc.BalanceOfPayments, Name = xc.Year.Name }).FirstOrDefault(e => e.ID == balanceOfPayment.ID); return(Ok(createdBalanceOfPayment)); }
public async Task <IActionResult> PutBalanceOfPayment([FromRoute] int id, [FromBody] BalanceOfPayment balanceOfPayment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != balanceOfPayment.ID) { return(BadRequest()); } _context.Entry(balanceOfPayment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BalanceOfPaymentExists(id)) { return(NotFound()); } else { throw; } } var updatedExchangeRate = _context.BalanceOfPayments.Include(eR => eR.Year).Include(e => e.Month).Select(xc => new YearViewModel { ID = xc.ID, YearId = xc.Year.ID, BalanceOfPayments = xc.BalanceOfPayments, Name = xc.Year.Name }).FirstOrDefault(e => e.ID == id); return(Ok(updatedExchangeRate)); }