public ActionResult Create([Bind(Include = "ApplicantId,Title,FullName,Address,Mobile,Email,DOB,Civil_Status")] Applicant applicant) { if (ModelState.IsValid) { db.Applicants.Add(applicant); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(applicant)); }
public static void Init(IServiceProvider serviceProvider) { using var applicantDbContext = new ApplicantDbContext(serviceProvider.GetRequiredService <DbContextOptions <ApplicantDbContext> >()); if (applicantDbContext.Applicants.Any()) { return; } applicantDbContext.Applicants.AddRange( new Core.Applicant.Applicant { FirstName = "Joe", LastName = "Bloggs", DateOfBirth = new DateTime(1970, 05, 7), Email = "*****@*****.**" }, new Core.Applicant.Applicant { FirstName = "Henry", LastName = "Tudor", DateOfBirth = new DateTime(1969, 05, 7), Email = "*****@*****.**" } ); applicantDbContext.SaveChanges(); }
public ActionResult <IEnumerable <Applicant> > Post(Applicant applicant) { ApplicantValidator validator = new ApplicantValidator(); var validateResult = validator.Validate(applicant); if (validateResult.IsValid) { dbContext.Applicants.Add(applicant); dbContext.SaveChanges(); return(CreatedAtAction(nameof(Get), new { id = applicant.ID }, applicant)); } else { string allMessages = validateResult.ToString("~"); return(BadRequest(new { Message = allMessages })); } }
public ActionResult Create([Bind(Include = "ID,FirstName,MiddleName,LastName,CreateTime,SocialSecurityNo,Email,HomePhone,CellPhone,Street,City,State,Zip,DOB,Gender,SchoolName,SchoolCity,GraduationDate,GPA,MathScore,VerbalScore,TotalScore,PAOfInterest,EnrollmentSemester,EnrollmentYear,EnrollmentDecision")] Applicant applicant) { if (ModelState.IsValid) { // Verify that the SSN isn't already in the database. Applicant matchingApplicant = db.Applicants.Where(cm => string.Compare(cm.SocialSecurityNo, applicant.SocialSecurityNo, true) == 0).FirstOrDefault(); if (applicant == null) { return(HttpNotFound()); } if (matchingApplicant != null) { ModelState.AddModelError("SocialSecurityNo", "Social Security Number should be unique."); return(View(applicant)); } applicant.TotalScore = applicant.MathScore + applicant.VerbalScore; if (applicant.GPA < 3) { ModelState.AddModelError("GPA", "Minimum Qualitification for GPA is 3.0"); return(View(applicant)); } if (applicant.TotalScore < 1001) { ModelState.AddModelError("VerbalScore", "Combined SAT Score should be more than 1000."); return(View(applicant)); } db.Applicants.Add(applicant); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(applicant)); }
private static void Seed(ApplicantDbContext context) { var applicants = new[] { new Applicant { Id = 1, Name = "Ahsan", FamilyName = "Raza", Address = "Berlin", EmailAddress = "*****@*****.**", CountryOfOrigin = "Germany", Age = 30, Hired = true }, new Applicant { Id = 2, Name = "JJ", FamilyName = "Kotze", Address = "Berlin", EmailAddress = "*****@*****.**", CountryOfOrigin = "Germany", Age = 26, Hired = true }, new Applicant { Id = 3, Name = "Carl", FamilyName = "Hibbard", Address = "Liverpool", EmailAddress = "*****@*****.**", CountryOfOrigin = "UK", Age = 55, Hired = true } }; context.Applicants.AddRange(applicants); context.SaveChanges(); }
public int Commit() { return(db.SaveChanges()); }