public async Task <IActionResult> Edit(string id, [Bind("Id,Name,Date,Principle,Interest")] Recoveries recoveries, string PreviousUrl) { if (id != recoveries.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(recoveries); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecoveriesExists(recoveries.Id)) { return(NotFound()); } else { throw; } } return(Redirect(PreviousUrl)); } return(View(recoveries)); }
public async Task <IActionResult> PutRecoveries(string id, Recoveries recoveries) { if (id != recoveries.Id) { return(BadRequest()); } _context.Entry(recoveries).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecoveriesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Recover(string id, [Bind("Id,Name,Address,Phone,Asset,Principle,Interest,Rate,Amount,Idate,Rdate,Penalty,Times,Period,Status")] Loan loan, string Type, float Penalty, string PreviousUrl) { if (id != loan.Id) { return(NotFound()); } if (ModelState.IsValid) { try { loan = await _context.Loans.FindAsync(id); Recoveries recovery = new Recoveries { Id = Guid.NewGuid().ToString(), Date = DateTime.Today, Name = loan.Name }; loan.Penalty = Penalty; if (Type.Equals("Interest")) { recovery.Interest = loan.Interest + loan.Penalty; loan.Rdate = loan.Rdate.AddDays(loan.Period); loan.Status = "Not Paid"; } else if (Type.Equals("Principle")) { recovery.Principle = loan.Principle + loan.Penalty; loan.Status = "Principle Paid"; } else if (Type.Equals("Complete")) { recovery.Interest = loan.Interest + loan.Penalty; recovery.Principle = loan.Principle; loan.Status = "Paid"; } else { throw new InvalidOperationException("Invalid Recovery Type"); } _context.Add(recovery); _context.Update(loan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoanExists(loan.Id)) { return(NotFound()); } else { throw; } } return(Redirect(PreviousUrl)); } return(View(loan)); }
public async Task <ActionResult <Recoveries> > PostRecoveries(RecoveryApi recoveryApi) { Recoveries recovery = new Recoveries { Id = Guid.NewGuid().ToString() }; if (recoveryApi.Id != recoveryApi.loan.Id) { return(NotFound()); } try { recoveryApi.loan = await _context.Loans.FindAsync(recoveryApi.Id); recovery.Date = DateTime.Today; recovery.Name = recoveryApi.loan.Name; if (recoveryApi.Type.Equals("Interest")) { recovery.Interest = recoveryApi.loan.Interest; recoveryApi.loan.Status = "Interest Paid"; } else if (recoveryApi.Type.Equals("Principle")) { recovery.Principle = recoveryApi.loan.Principle; recoveryApi.loan.Status = "Principle Paid"; } else if (recoveryApi.Type.Equals("Complete")) { recovery.Interest = recoveryApi.loan.Interest; recovery.Principle = recoveryApi.loan.Principle; recoveryApi.loan.Status = "Paid"; } else { throw new InvalidOperationException("Invalid Recovery Type"); } _context.Add(recovery); _context.Update(recoveryApi.loan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecoveriesExists(recoveryApi.Id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("GetRecoveries", new { id = recovery.Id }, recovery)); }