public bool IsEmailExist(string emailId) { using (RegistrationDBEntities db = new RegistrationDBEntities()) { var data = db.RegTables.Where(d => d.EmailId == emailId).FirstOrDefault(); return(data != null); } }
public ActionResult Index(Registration obj) { // if (ModelState.IsValid) { RegistrationDBEntities db = new RegistrationDBEntities(); db.Registartion.Add(obj); db.SaveChanges(); } return(View(obj)); }
public ActionResult Index([Bind(Exclude = "IsEmailVerified,ActivationCode")] RegTable users) { bool Status = false; string message = ""; if (ModelState.IsValid) { //Email is already Exist var isExist = IsEmailExist(users.EmailId); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(users)); } users.ActivationCode = Guid.NewGuid(); users.Password = Crypto.Hash(users.Password); users.IsEmailVerified = false; #region Save to Database using (RegistrationDBEntities db = new RegistrationDBEntities()) { db.RegTables.Add(users); db.SaveChanges(); //Send Email to User SendVerificationLinkEmail(users.EmailId, users.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + users.EmailId; Status = true; } #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(users)); }