public IHttpActionResult Post(ApplicantCreate application) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateApplicantServices(); if (!service.CreateApplicant(application)) { return(InternalServerError()); } return(Ok()); }
public bool CreateApplicant(ApplicantCreate model) { using (var ctx = new ApplicationDbContext()) { var applicant = ctx.Applicants.SingleOrDefault(e => e.OwnerId == _userId); if (applicant != null) { return(false); } var entity = new Applicant() { OwnerId = _userId, ApplicantFirstName = model.ApplicantFirstName, ApplicantEmail = model.ApplicantEmail, ApplicantLastName = model.ApplicantLastName, }; ctx.Applicants.Add(entity); return(ctx.SaveChanges() == 1); } }