private void createAdmin() { AspNetIdentityContext context = new AspNetIdentityContext(); if (context.Users.ToList().Count == 0) { var userManager = new ApplicationUserManager(new UserStore <IdentityUser>(context)); var admin = new IdentityUser { UserName = "******" }; string password = "******"; var result = userManager.Create(admin, password); context.SaveChanges(); Repository <ImagesInfo> imageInfoRepository = new Repository <ImagesInfo>(); imageInfoRepository.Create(new ImagesInfo()); Repository <SetsInfo> setsInfoRepository = new Repository <SetsInfo>(); setsInfoRepository.Create(new SetsInfo()); } }
public ActionResult Create(UserProfile profile, string Password, bool?CreateLoginAndIdentity, bool?SendUserWelcome, bool?SendRegisteredNotify, bool?clientIdChanged) { ViewData.Add("CreateLoginAndIdentity", CreateLoginAndIdentity); ViewData.Add("Password", Password); ViewData.Add("SendWelcomeMessage", SendUserWelcome); ViewData.Add("SendRegisteredNotify", SendRegisteredNotify); AspNetIdentityUser identityUser = null; if (ModelState.IsValid && !(clientIdChanged ?? false)) { AspNetIdentityContext identityCtx = new AspNetIdentityContext(); if (CreateLoginAndIdentity.HasValue && CreateLoginAndIdentity.Value) { if (identityCtx.Users.Any(u => u.UserName == profile.UserName)) { ModelState.AddModelError("UserName", "User Name is already taken, choose a new user name or edit the original user."); } if (identityCtx.Users.Any(u => u.Id == profile.UserId)) { ModelState.AddModelError("UserId", "User Id is already taken, choose a new UserId or edit the original user."); } if (identityCtx.Users.Any(u => u.Email == profile.Email)) { ModelState.AddModelError("Email", "Email is already taken, choose a new UserId or edit the original user."); } if (string.IsNullOrEmpty(Password)) { ModelState.AddModelError("Password", "Password is null, enter a password for this user or uncheck Create Login And Identity."); } else if (Password.Length < 6) { ModelState.AddModelError("Password", "Password is too short. You must have at least 6 characters."); } if (ModelState.IsValid) { identityUser = identityCtx.CreateUserIfNotExists(profile.UserName, profile.Email, null, Password); } } } if (ModelState.IsValid && !(clientIdChanged ?? false)) { UserProfile newProfile = GStoreDb.UserProfiles.Create(profile); newProfile.UpdateAuditFields(CurrentUserProfileOrThrow); if (identityUser != null) { newProfile.UserId = identityUser.Id; } else { newProfile.UserId = profile.Email; } newProfile = GStoreDb.UserProfiles.Add(newProfile); AddUserMessage("User Profile Added", "User Profile '" + profile.FullName.ToHtml() + "' <" + profile.Email.ToHtml() + " > [" + profile.UserProfileId + "] created successfully!", UserMessageType.Success); GStoreDb.SaveChanges(); GStoreDb.LogSecurityEvent_NewRegister(this.HttpContext, RouteData, newProfile, this); if ((SendUserWelcome ?? true) || (SendRegisteredNotify ?? true)) { string notificationBaseUrl = Url.Action("Details", "Notifications", new { id = "" }); CurrentStoreFrontOrThrow.HandleNewUserRegisteredNotifications(this.GStoreDb, Request, newProfile, notificationBaseUrl, SendUserWelcome ?? true, SendRegisteredNotify ?? true, string.Empty); } return(RedirectToAction("Index")); } int?clientId = null; if (profile.ClientId != default(int)) { clientId = profile.ClientId; } int?storeFrontId = null; if (profile.StoreFrontId != default(int)) { storeFrontId = profile.StoreFrontId; } this.BreadCrumbsFunc = htmlHelper => this.UserProfileBreadcrumb(htmlHelper, profile.ClientId, profile.StoreFrontId, profile, false); return(View(profile)); }
public ActionResult Create(UserProfile profile, string Password, bool? CreateLoginAndIdentity, bool? SendUserWelcome, bool? SendRegisteredNotify, bool? clientIdChanged) { ViewData.Add("CreateLoginAndIdentity", CreateLoginAndIdentity); ViewData.Add("Password", Password); ViewData.Add("SendWelcomeMessage", SendUserWelcome); ViewData.Add("SendRegisteredNotify", SendRegisteredNotify); AspNetIdentityUser identityUser = null; if (ModelState.IsValid && !(clientIdChanged ?? false)) { AspNetIdentityContext identityCtx = new AspNetIdentityContext(); if (CreateLoginAndIdentity.HasValue && CreateLoginAndIdentity.Value) { if (identityCtx.Users.Any(u => u.UserName == profile.UserName)) { ModelState.AddModelError("UserName", "User Name is already taken, choose a new user name or edit the original user."); } if (identityCtx.Users.Any(u => u.Id == profile.UserId)) { ModelState.AddModelError("UserId", "User Id is already taken, choose a new UserId or edit the original user."); } if (identityCtx.Users.Any(u => u.Email == profile.Email)) { ModelState.AddModelError("Email", "Email is already taken, choose a new UserId or edit the original user."); } if (string.IsNullOrEmpty(Password)) { ModelState.AddModelError("Password", "Password is null, enter a password for this user or uncheck Create Login And Identity."); } else if (Password.Length < 6) { ModelState.AddModelError("Password", "Password is too short. You must have at least 6 characters."); } if (ModelState.IsValid) { identityUser = identityCtx.CreateUserIfNotExists(profile.UserName, profile.Email, null, Password); } } } if (ModelState.IsValid && !(clientIdChanged ?? false)) { UserProfile newProfile = GStoreDb.UserProfiles.Create(profile); newProfile.UpdateAuditFields(CurrentUserProfileOrThrow); if (identityUser != null) { newProfile.UserId = identityUser.Id; } else { newProfile.UserId = profile.Email; } newProfile = GStoreDb.UserProfiles.Add(newProfile); AddUserMessage("User Profile Added", "User Profile '" + profile.FullName.ToHtml() + "' <" + profile.Email.ToHtml() + " > [" + profile.UserProfileId + "] created successfully!", UserMessageType.Success); GStoreDb.SaveChanges(); GStoreDb.LogSecurityEvent_NewRegister(this.HttpContext, RouteData, newProfile, this); if ((SendUserWelcome ?? true) || (SendRegisteredNotify ?? true)) { string notificationBaseUrl = Url.Action("Details", "Notifications", new { id = "" }); CurrentStoreFrontOrThrow.HandleNewUserRegisteredNotifications(this.GStoreDb, Request, newProfile, notificationBaseUrl, SendUserWelcome ?? true, SendRegisteredNotify ?? true, string.Empty); } return RedirectToAction("Index"); } int? clientId = null; if (profile.ClientId != default(int)) { clientId = profile.ClientId; } int? storeFrontId = null; if (profile.StoreFrontId != default(int)) { storeFrontId = profile.StoreFrontId; } this.BreadCrumbsFunc = htmlHelper => this.UserProfileBreadcrumb(htmlHelper, profile.ClientId, profile.StoreFrontId, profile, false); return View(profile); }