public ActionResult SignUp(User userDbModel) { var connectionDB = new NoteMarketplaceEntities(); string email = userDbModel.EmailID; if (IsValidEmail(email)) { if (IsValidPassword(userDbModel.Password)) { var result = connectionDB.Users.Where(db => db.EmailID == email).FirstOrDefault(); if (result == null) { User obj = new User(); obj.FirstName = userDbModel.FirstName; obj.LastName = userDbModel.LastName; obj.EmailID = userDbModel.EmailID; obj.Password = userDbModel.Password; obj.IsEmailVerified = false; obj.IsActive = true; obj.ModifiedBy = null; obj.ModifiedDate = null; obj.CreatedDate = DateTime.Now; obj.CreatedBy = null; obj.RoleID = 103; if (ModelState.IsValid) { db.Users.Add(obj); try { // Your code... // Could also be before try if you know the exception occurs in SaveChanges db.SaveChanges(); ModelState.Clear(); FormsAuthentication.SetAuthCookie(userDbModel.EmailID, true); return(RedirectToAction("FAQ", "User")); } 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); } } } } } else { ViewBag.NotValidEmail = "Email is already exists"; } } else { ViewBag.NotValidPassword = "******"; } } else { ViewBag.NotValidEmail = "Email is not valid"; } return(View("SignUp")); }
public AccountController() { _Context = new NoteMarketplaceEntities(); }