public ActionResult Employers(EmployerSignUpView ESV) { if (ModelState.IsValid) { EmployerManager EM = new EmployerManager(); if (!EM.IsLoginNameExist(ESV.Email)) { EM.AddEmployerAccount(ESV); FormsAuthentication.SetAuthCookie(ESV.contactName, false); return(RedirectToAction("Welcome", "Home")); } else { ModelState.AddModelError("", "Login Name already taken."); } } return(View()); }
public void AddEmployerAccount(EmployerSignUpView employer) { using (CareerRescueEntities db = new CareerRescueEntities()) { Employer EMP = new Employer(); Random b = new Random(); EMP.Employer_id = employer.Employer_id < 0 ? employer.Employer_id : b.Next(); //1 EMP.Email = employer.Email; EMP.Password = employer.Password; EMP.companyName = employer.companyName; EMP.contactName = employer.contactName; EMP.business_type = employer.business_type; EMP.Phone = employer.Phone; EMP.website = employer.website; /* EMP.status =employer.ToString(DateTime.Now);*/ db.Employers.Add(EMP); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } //throw; } } }