public async Task <ActionResult> Register(RegisterViewModel1 model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register1(RegisterViewModel1 model) { ApplicationDbContext db = new ApplicationDbContext(); var name = model.FirstName + " " + model.LastName; var GetName = db.Users.Where(n => n.FullName == name && n.DiaChi == model.DiaChi).Select(n => n.FullName).ToString(); if (string.IsNullOrEmpty(GetName)) { ViewBag.CuaHangId = new SelectList(db.cuaHangs, "CuaHangId", "TenCuaHang", model.CuaHangId); ViewBag.Message = "Trùng tên"; return(View(model)); } if (ModelState.IsValid) { ViewBag.CuaHangId = new SelectList(db.cuaHangs, "CuaHangId", "TenCuaHang", model.CuaHangId); var user = new ApplicationUser { IsAccount = true, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, CuaHangId = model.CuaHangId, FullName = model.FirstName + " " + model.LastName, UserName = model.FirstName + " " + model.LastName, SoDT = model.SoDT, DiaChi = model.DiaChi }; if (model.Password == null) { model.Password = "******"; } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); ViewBag.Message = "Thêm Nhân Viên Thành Công"; return(View()); } AddErrors(result); } ViewBag.CuaHangId = new SelectList(db.cuaHangs, "CuaHangId", "TenCuaHang", model.CuaHangId); // If we got this far, something failed, redisplay form return(View(model)); }