protected void Application_Start() { using (BlogContext ent = new BlogContext()) { ent.Database.CreateIfNotExists(); } var usermanager = IdentityTools.NewUserManager(); var rolemanager = IdentityTools.NewRoleManager(); if (usermanager.FindByName("*****@*****.**") == null) { try { ApplicationUser AppUserAdmin = new ApplicationUser() { Name = "Serkan", Surname = "Karışan", Email = "*****@*****.**", UserName = "******", EmailConfirmed = true, SecurityStamp = "d6b253a0-6325-410b-bed4-796ba916e443", PhoneNumber = "5355063330", PhoneNumberConfirmed = true, TwoFactorEnabled = false, LockoutEndDateUtc = null, LockoutEnabled = false, AccessFailedCount = 0 }; IdentityResult result = usermanager.Create(AppUserAdmin, "123Qw."); if (result.Succeeded) { if (rolemanager.FindByName("Admin") != null) { ApplicationRole Rol = rolemanager.FindByName("Admin"); var currentUser = usermanager.FindByName(AppUserAdmin.UserName); usermanager.AddToRole(currentUser.Id, "Admin"); } else { ApplicationRole appRole = new ApplicationRole(); appRole.Name = "Admin"; rolemanager.Create(appRole); var currentUser = usermanager.FindByName(AppUserAdmin.UserName); usermanager.AddToRole(currentUser.Id, "Admin"); } if (rolemanager.FindByName("User") == null) { ApplicationRole appRole = new ApplicationRole(); appRole.Name = "User"; rolemanager.Create(appRole); } } } catch (Exception ex) { string hata = ex.Message; throw; } } AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public ActionResult Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var kullanici = userManager.FindByEmail(model.Email); if (kullanici != null) { ModelState.AddModelError("", "Bu e-mail sistemde kayıtlı"); return(View(model)); } var rolemanager = IdentityTools.NewRoleManager(); ApplicationRole ar = new ApplicationRole(); ar.Name = "User"; rolemanager.Create(ar); ApplicationUser user = new ApplicationUser(); user.Name = model.Name; user.Surname = model.Surname; user.Email = model.Email; user.AccountNo = model.AccountNo; user.PhoneNumber = model.ContactNo; user.UserName = model.Username; var result = userManager.Create(user, model.Password); userManager.AddToRole(user.Id, "User"); if (result.Succeeded) {//üye olan kullanıcıya hediye 5000 bil verdim UserTrans userTrans = new UserTrans(); userTrans.UserId = user.Id; userTrans.PaymentId = true; userTrans.Prize = 5000; userTrans.Loose = 0; userTrans.Balance = 5000; repoUser.Add(userTrans); return(RedirectToAction("Login")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error); } } return(View(model)); }