public IHttpActionResult Create(EmploymentSaveDto employment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } service.Create(employment); //var result = mapper.Map<EmploymentDto>(employment); return(CreatedAtRoute("ApiRoute", new { id = employment.Id }, employment)); }
public ActionResult EmploymentInfo(Employments employments) { var tracker = (Guid)Session["Tracker"]; if (ModelState.IsValid) { var applicant = _applicantService.GetApplicantsByTraker(tracker); var existingEmployment = applicant.Employment.FirstOrDefault(x => x.IsPrimary); if (existingEmployment != null) { _employmentService.Update(existingEmployment); } else { var newEmployment = Mapper.Map <EmploymentDto>(employments.PrimaryEmployer); newEmployment.IsPrimary = true; _employmentService.Create(newEmployment); } var existingPrevious = applicant.Employment.FirstOrDefault(x => x.IsPrimary == false); if (existingPrevious != null) { var newEmployment = Mapper.Map(employments.PreviousEmployer, existingPrevious); _employmentService.Update(existingPrevious); } else { var newEmployment = Mapper.Map <EmploymentDto>(employments.PreviousEmployer); newEmployment.IsPrimary = false; _employmentService.Create(newEmployment); } return(RedirectToAction("VehicleInfo", "Vehicle")); } return(View()); }