public void PayQuote(int id, decimal amount) { var quote = _context.Quotes.Single(x => x.QuoteId == id); var quoteDetail = _context.QuoteDetails.Single(x => x.QuoteDetailsId == quote.QuoteDetailsId); var Loc = _context.LOCs.Single(x => x.LOCId == quoteDetail.LocId); if (quoteDetail.Currency != "Soles") { var newamount = CurrencyConverterPen(amount); Loc.AvalibleLineOfCredit += newamount; } else { } var client = _context.Customers.Single(x => x.CustomerId == Loc.CustomerId); if (amount < quote.Value + quote.Interest) { quote.Value -= amount; _transactionService.Create(new TransactionCreateDto { CustomerId = client.CustomerId, Description = "Se ha pagado la cuota parcialmente en valor de: " + amount, Status = "Accepted" }); } else if (quote.Interest + quote.Value == amount) { Loc.AvalibleLineOfCredit += quote.Value; quote.Value -= amount; _transactionService.Create(new TransactionCreateDto { CustomerId = client.CustomerId, Description = "Se ha pagado la cuota totalmente en valor de: " + amount, Status = "Accepted" }); Remove(id); } decimal DeudaTotal = 0; List <Quote> cuotas = _context.Quotes.Where(x => x.QuoteDetailsId == quoteDetail.QuoteDetailsId).ToList(); if (cuotas.Count == 0) { _quoteDetailService.Remove(quoteDetail.QuoteDetailsId); } else { quoteDetail.Debt = cuotas.ElementAt(0).Value; foreach (Quote cuota in cuotas) { DeudaTotal += cuota.Value; } quoteDetail.LastTotal = DeudaTotal; } _context.SaveChanges(); }
public ActionResult Remove(int id) { _quoteDetailService.Remove(id); return(NoContent()); }