public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email,model.PasswordQuestion,model.PasswordAnswer); if (createStatus == MembershipCreateStatus.Success) { FormsService.SignIn(model.UserName, false /* createPersistentCookie */); try { MembershipUser thisUsr = Membership.GetUser(model.UserName,true); MemberDetails toCreate = new MemberDetails(); toCreate.Id = Int32.Parse(thisUsr.ProviderUserKey.ToString()); toCreate.PEmail = thisUsr.Email; toCreate.Givennm = model.Givennm; toCreate.bShowPrvInfo = false; Data.Helper.NHibernateHelper.Save<MemberDetails>(toCreate); } catch (Exception ex1) { Data.Helper.NHibernateHelper.Log(new Exception("Problem creating default user profile==>", ex1)); } //****Remove this code block if you already have another "admin".*****// //To delete this "sysadmin" => 1. Create another account>> 2. Assign admin role to new account >> 3. Delete the default "sysadmin" account if ((string.Equals(model.UserName,"sysadmin",StringComparison.InvariantCultureIgnoreCase))&&(Roles.GetAllRoles().Length == 0)) { Roles.CreateRole("Admin"); Roles.AddUserToRole(model.UserName, "Admin"); } //****Remove this code block if you already have a "admin".*****// return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } } else { ModelState.AddModelError("", "Please fill in all required information."); } // If we got this far, something failed, redisplay form ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(model); }
protected bool Equals(MemberDetails entity) { if (entity == null) return false; if (!base.Equals(entity)) return false; if (!Equals(_Id, entity._Id)) return false; return true; }
public ActionResult Edit(MemberDetails model) { if (ModelState.IsValid) { try { MemberDetails usrPartics = NHibernateHelper.UniqueResult<MemberDetails>(null, "Id", LoggedInUserKey); if (usrPartics != null) { NHibernateHelper.Update<MemberDetails>(model); } else { NHibernateHelper.Save<MemberDetails>(model); } TempData["message"] = "Profile updated successfully please click <a href='Index'>here</a> to go to home page."; } catch (Exception ex1) { TempData["message"] = "Error saving profile info=>" + ex1.Message; NHibernateHelper.Log(new Exception("Error saving profile info=>", ex1)); } } else { ModelState.AddModelError("", "Please fill the basic required information."); } return View(model); }