public IActionResult Edit(CustomerRegisterView cus, IFormCollection form) { try { var cus_ = db.Customers.Include(u => u.Orders).Single(u => u.Email == cus.Email); if (form["Password"].ToString().Trim() != "") { if (form["Password"].ToString() == form["ConfirmPassword"].ToString()) { cus_.Password = Security_D_E.EncryptString(cus.Password, Security_D_E.key_e_d); } else { Danger(string.Format("<b>Mật khẩu không khớp</b> .", ""), true); return(View(cus)); } } cus_.Fullname = cus.Fullname; cus_.Address = cus.Address; db.SaveChanges(); setCustomerSession(cus_.Email); return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); } catch (Exception e) { Danger(string.Format("<b>Lỗi {0}</b> .", e.Message + e.InnerException), true); return(View(cus)); } }
public async Task <ActionResult> AddUser(String Email, String Password, String Fullname, String[] UserRoles) { var user = new ApplicationUser(); user.UserName = Email; user.Email = Email; var result = await UserManager.CreateAsync(user, Password); if (result.Succeeded) { try { Customer cus = new Customer(); cus.Id = Email; cus.Email = Email; cus.Password = Security_D_E.EncryptString(Password, Security_D_E.key_e_d); cus.Fullname = Fullname; cus.Activated = true; db.Customers.Add(cus); db.SaveChanges(); Success(string.Format("<b>User {0}</b> tạo thành công.", Email), true); } catch (Exception e) { Danger(string.Format("<b>Lỗi thêm Customer {0}</b>", e.Message), true); } try { if (UserRoles.Length > 0 || UserRoles != null) { foreach (var role in UserRoles) { await UserManager.AddToRoleAsync(user, role); } } } catch (Exception e) { Danger(string.Format("<b>Lỗi thêm Customer {0}</b>", e.Message), true); } } return(RedirectToAction("Index")); }
public IActionResult Login(LoginViewModel model, IFormCollection form) { if (ModelState.IsValid) { try { if (_session.GetObject <CustomerSs>("Customer") != null) { return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); } var cus = db.Customers.Where(u => u.Email == model.Email).SingleOrDefault(); if (cus == null) { Danger(string.Format("<b>Sai email </b> .", ""), true); return(View(model)); } else { var descrypt = Security_D_E.DecryptString(cus.Password, Security_D_E.key_e_d); if (descrypt == model.Password) { var cus_ = new CustomerSs() { Id = cus.Id, Fullname = cus.Fullname, Email = cus.Email, Activated = cus.Activated }; _session.SetObject("Customer", cus_); return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); } else { Danger(string.Format("<b>Sai password </b> .", ""), true); return(View(model)); } } } catch (Exception e) { Danger(string.Format("<b>Lỗi {0}</b> .", e.Message + e.InnerException), false); } } Danger(string.Format("<b>Lỗi đăng nhập</b> .", ""), false); return(View(model)); }
public IActionResult Register(CustomerRegisterView model) { try { var cus_ = db.Customers.Count(u => u.Email == model.Email.Trim()); if (cus_ > 0) { Danger(string.Format("<b>Email đã tồn tại</b> .", ""), false); return(View(model)); } else { Customer cus = new Customer() { Id = model.Email, Fullname = model.Fullname, Email = model.Email, Password = Security_D_E.EncryptString(model.Password, Security_D_E.key_e_d), Activated = true, Address = model.Address }; db.Customers.Add(cus); db.SaveChanges(); var cus__ = new CustomerSs() { Id = cus.Id, Fullname = cus.Fullname, Email = cus.Email, Activated = cus.Activated, Address = cus.Address }; _session.SetObject("Customer", cus__); } } catch (Exception e) { Danger(string.Format("<b>Lỗi {0}</b> .", e.Message + e.InnerException), true); return(View(model)); } return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); }