public ActionResult UpdateAccountSettings(tb_employer_registration_data changed_employer_data) { db = new DinJobPortalEntities(); tb_user existing_user_data; try { //tb_user user; existing_user_data = (tb_user)Session["user"]; if (existing_user_data != null) { if (existing_user_data.user_type == "employer") { var previous_email = existing_user_data.email; existing_user_data = db.tb_user.Where(tempuser => tempuser.id == existing_user_data.id).Include(tempuser => tempuser.tb_employer_registration_data).FirstOrDefault <tb_user>(); existing_user_data.email = changed_employer_data.email; existing_user_data.tb_employer_registration_data.FirstOrDefault().email = changed_employer_data.email; existing_user_data.tb_employer_registration_data.FirstOrDefault().first_name = changed_employer_data.first_name; existing_user_data.tb_employer_registration_data.FirstOrDefault().last_name = changed_employer_data.last_name; existing_user_data.tb_employer_registration_data.FirstOrDefault().company_name = changed_employer_data.company_name; existing_user_data.tb_employer_registration_data.FirstOrDefault().mobile = changed_employer_data.mobile; existing_user_data.tb_employer_registration_data.FirstOrDefault().cnic = changed_employer_data.cnic; if (ModelState.IsValid) { db.Entry(existing_user_data).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Session["user"] = existing_user_data; if (previous_email != existing_user_data.email) { Random rnd = new Random(); decimal randomNo = rnd.Next(10000000, 99999999); objUtility = new UtilityMethods.Utility(); bool isEmailSent = objUtility.SendVerificationEmail(existing_user_data.email, randomNo); if (isEmailSent) { Session["user_email"] = existing_user_data.email; Session["verification_code"] = randomNo; return(RedirectToAction("VerifyEmail", "User")); } } return(RedirectToAction("AccountSetting")); } else { return(View("AccountSetting", existing_user_data)); } } } } catch (Exception e) { objUtility = new UtilityMethods.Utility(); objUtility.SaveException_for_ExceptionLog(e); ViewBag.Exception = e.Message; return(RedirectToAction("DbError", "User", e)); } return(View("AccountSetting")); }
public ActionResult ValidateEmployerSignUp(tb_user user, tb_employer_registration_data employer, string password_reenter) //*, string password_reenter, string mobileNo, string cnicNo*?/ { #region Employer Registration Validation try{ user.user_type = "employer"; /* var tempMobile = mobileNo.Split('-'); * employer.mobile = decimal.Parse(tempMobile[0] + tempMobile[1]); * var tempCnic = cnicNo.Split('-'); * employer.cnic = decimal.Parse(tempCnic[0] + tempCnic[1] + tempCnic[2]);*/ List <tb_employer_registration_data> emp = new List <tb_employer_registration_data>(); emp.Add(employer); user.tb_employer_registration_data = emp; if (db.tb_user.Any(usr => usr.email == user.email)) { ModelState.AddModelError("email", "This email already exists"); return(View("MyAccount", user)); } if (!string.IsNullOrEmpty(user.password)) { if (user.password != password_reenter) { ModelState.AddModelError("password", "Kindly Enter Same Password in both fields"); } // if (user.password.Length < 6 || user.password.Length > 32) //{ // ModelState.AddModelError("password", "Kindly Enter Password between 6 and 32 sharacters"); //} } #region Commented /* * else * { * ModelState.AddModelError("password", "Password is required"); * } * * if (string.IsNullOrEmpty(user.tb_employer_registration_data.First().first_name)) * { * ModelState.AddModelError("first_name", "First Name is required"); * } * if (string.IsNullOrEmpty(user.tb_employer_registration_data.FirstOrDefault().last_name)) * { * ModelState.AddModelError("last_name", "Last Name is required"); * } * if (string.IsNullOrEmpty(user.tb_employer_registration_data.FirstOrDefault().company_name)) * { * ModelState.AddModelError("company_name", "Company name is required"); * } * if (user.tb_employer_registration_data.FirstOrDefault().mobile.ToString().Length<9) * { * ModelState.AddModelError("mobile", "Mobile is required and should be Valid"); * } * if (user.tb_employer_registration_data.FirstOrDefault().cnic<12) * { * ModelState.AddModelError("cnic", "CNIC is required"); * } * * if (!string.IsNullOrEmpty(user.email)) * { * string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + * @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + * @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; * Regex re = new Regex(emailRegex); * if (!re.IsMatch(user.email)) * { * ModelState.AddModelError("email", "Email is not valid"); * } * } * else * { * ModelState.AddModelError("email", "Email is required"); * }*/ #endregion if (ModelState.IsValid) { try { PasswordEncryption enc = new PasswordEncryption(); string encPassword = enc.encryptPassword(user.password); user.password = encPassword; db.tb_user.Add(user); db.SaveChanges(); int id = user.id; Random rnd = new Random(); decimal randomNo = rnd.Next(10000000, 99999999); objUtility = new UtilityMethods.Utility(); bool isEmailSent = objUtility.SendVerificationEmail(user.email, randomNo); if (isEmailSent) { Session["user_email"] = user.email; Session["verification_code"] = randomNo; return(RedirectToAction("VerifyEmail", "User")); } } catch (Exception e) { objUtility = new UtilityMethods.Utility(); objUtility.SaveException_for_ExceptionLog(e); ViewBag.Exception = e.Message; return(View("DbError")); } } return(View("MyAccount", user)); } catch (Exception e) { //tb_exception ex = new tb_exception(); //ex.date = System.DateTime.Now; //ex.exception_message = e.Message; //ex.exception_stack_trace = e.StackTrace; //db.tb_exception.Add(ex); objUtility = new UtilityMethods.Utility(); objUtility.SaveException_for_ExceptionLog(e); ViewBag.Exception = e.Message; return(View("DbError")); } #endregion //return View("MyAccount"); }