public IActionResult Index(ApplicantSummitDTO applicant) { try { var result = _applicationRepository.SubmitNewApplicant(applicant); return(RedirectToAction("ApplicationResults", new { applicationId = result })); } catch (Exception e) { Console.WriteLine(e); return(BadRequest()); } }
/// <summary> /// Maps new application to its domain object, validates the supplied values and approves application /// The results are maped to a database entity and saved to the database. /// </summary> /// <param name="newApplicant"></param> /// <returns> The database id of the application. </returns> public Guid SubmitNewApplicant(ApplicantSummitDTO newApplicant) { try { var application = _mapper.Map <Applicant>(newApplicant); var resultOfApproval = application.ApproveApplication(); var databaseEntity = _mapper.Map <ApplicationDatabaseEntity>(resultOfApproval); _appDbContext.Add(databaseEntity); _appDbContext.SaveChanges(); return(databaseEntity.Id); } catch (Exception e) { Console.WriteLine(e); throw; } }