public async Task <IHttpActionResult> GetApplicant(int id) { HRApplicant applicant = await db.HRApplicants.FindAsync(id); if (applicant == null) { return(NotFound()); } return(Ok(applicant)); }
// PUT: api/Patients/5 public HttpResponseMessage PutApplicant(int id, [FromBody] HRApplicant applicant) { if (applicant == null) { return(Request.CreateResponse(HttpStatusCode.OK, "no data sent")); } applicant.Id = id; db.Entry(applicant).State = EntityState.Modified; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, applicant)); }
public async Task <IHttpActionResult> DeleteApplicant(int id) { HRApplicant applicant = await db.HRApplicants.FindAsync(id); if (applicant == null) { return(NotFound()); } db.HRApplicants.Remove(applicant); await db.SaveChangesAsync(); return(Ok(applicant)); }
public async Task <IHttpActionResult> PostApplicant(HRApplicant applicant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } applicant.Timestamp = DateTime.Now; db.HRApplicants.Add(applicant); await db.SaveChangesAsync(); //generate reg number and password if is a new registration if (applicant.ApplicantId.Equals("")) { var facilityInitial = db.KeyValuePairs.FirstOrDefault(e => e.Key_ == "FacilityInittials").Value; var year = DateTime.Now.ToString("yy"); var prefix = "00"; if (applicant.Id > 9) { prefix = "0"; } else if (applicant.Id > 99) { prefix = ""; } var branchId = db.KeyValuePairs.FirstOrDefault(e => e.Key_ == "BranchId").Value; var applicantid = facilityInitial + "/" + branchId + "/" + prefix + applicant.Id + "/" + year; applicant.ApplicantId = applicantid; applicant.Password = applicantid; //consider generating random password } else { applicant.Password = applicant.ApplicantId; } db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = applicant.Id }, applicant)); }