public async Task <IActionResult> AddOrEdit(LoanModel model) { long id = default; if (ModelState.IsValid) { var entity = _mapper.Map <Loan>(model); await _loanService.AddAsync(entity); return(RedirectToAction("Detail", new { Id = entity.Id })); } return(View(model)); }
public async Task <ActionResult> Add(LoanViewModel loanViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } if (await _loanService.HasPendingReturnsByPeople(_mapper.Map <Loan>(loanViewModel))) { return(CustomResponse()); } await _loanService.AddAsync(_mapper.Map <Loan>(loanViewModel)); return(CustomResponse(loanViewModel)); }
public async Task <ActionResult> PostAsync([FromBody] Loans item) { if (!ModelState.IsValid) { return(BadRequest()); } try { var exist = await service.GetAsync(x => x.loanid == item.loanid); if (exist != null) { return(Conflict(new Response() { Status = false, Description = "Duplicate record" })); } var result = await service.AddAsync(item); if (result) { var newitem = await service.GetAsync(x => x.loanid == item.loanid); return(StatusCode(201, newitem)); } else { return(BadRequest()); } } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new Response() { Status = false, Description = "System error" })); } }