public async Task <IActionResult> PutPayment([FromRoute] int id, [FromBody] Payment payment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != payment.Id) { return(BadRequest()); } _context.Entry(payment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private async Task <IActionResult> PostDeal([FromBody] Deal deal) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (deal.DealTime == DateTime.MinValue) { deal.DealTime = DateTime.Now; } if (deal.DealPayment.Method == Models.Enums.PaymentMethod.Cash && !deal.DealPayment.Paid) { deal.DealPayment.Amount = 0; } deal.DealPrice.DueDate = deal.DealTime; deal.DealPrice.PayDate = deal.DealTime; deal.DealPrice.Method = Models.Enums.PaymentMethod.DealPrice; deal.DealPrice.Paid = true; if (deal.DealPayment.PayDate == DateTime.MinValue) { deal.DealPayment.PayDate = DateTime.Now; } if (deal.DealPayment.DueDate == DateTime.MinValue) { deal.DealPayment.DueDate = DateTime.Now; } _context.Entry(deal).State = EntityState.Added; deal.Items.ToList().ForEach(i => { _context.Entry(i).State = EntityState.Added; }); _context.Entry(deal.DealPayment).State = EntityState.Added; _context.Entry(deal.DealPrice).State = EntityState.Added; await _context.SaveChangesAsync(); return(CreatedAtAction("GetDeal", new { id = deal.Id }, deal)); }