public async Task <object> UpdateLoan(LoansDTO loansDTO, Guid Id) { try { var update = await dataContext.loans.Where(p => p.Id == Id).FirstOrDefaultAsync(); if (update != null) { update.FirstName = loansDTO.FirstName; update.AmountRequested = loansDTO.AmountRequested; update.Email = loansDTO.Email; update.LastName = loansDTO.LastName; update.LoanDocument = loansDTO.LoanDocument; update.Location = loansDTO.Location; update.PhoneNumber = loansDTO.PhoneNumber; update.Purpose = loansDTO.Purpose; update.Repaymentsource = loansDTO.Repaymentsource; update.Tenor = loansDTO.Tenor; int result = await dataContext.SaveChangesAsync(); if (result > 0) { res.Success = true; res.Message = "Loan record has been successfully updated"; res.Data = update; return(res); } else { res.Success = false; res.Message = "Db Error"; return(res); } } else { res.Success = false; res.Message = "Loan id does not exist"; res.Data = null; return(res); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> UpdateLoan(LoansDTO loansDTO, Guid Id) { try { dynamic result = await _loan.UpdateLoan(loansDTO, Id); if (result.Success == false) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception ex) { throw new Exception(); } }
public async Task <object> AddLoan(LoansDTO loansDTO, string userID) { try { var data = new Loans { AmountRequested = loansDTO.AmountRequested, Email = loansDTO.Email, FirstName = loansDTO.FirstName, LastName = loansDTO.LastName, LoanDocument = loansDTO.LoanDocument, Location = loansDTO.Location, PhoneNumber = loansDTO.PhoneNumber, Purpose = loansDTO.Purpose, Repaymentsource = loansDTO.Repaymentsource, Tenor = loansDTO.Tenor, UserId = userID, DateCreated = DateTime.Now }; await dataContext.AddAsync(data); int result = await dataContext.SaveChangesAsync(); if (result > 0) { res.Message = "Saved Successful"; res.Success = true; res.Data = "OK"; return(res); } else { res.Success = false; res.Message = "Db Error"; return(res); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> AddLoan(LoansDTO loansDTO) { try { //var userid = _accessor.HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).SingleOrDefault(); var UserId = "B7C60175-B370-4CE4-AC86-08D81D38F5FE"; dynamic result = await _loan.AddLoan(loansDTO, UserId); if (result.Success == false) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception ex) { throw new Exception(); } }