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 ActionResult Register(CustomerRegisterView RegisterMember) { if (ModelState.IsValid) { RegisterMember.newCustomer.CustomerPassword = RegisterMember.CustomerPassword; customerService.CreateCustomer(RegisterMember.newCustomer); TempData["Message"] = "註冊成功"; return(RedirectToAction("Index", "Home")); } RegisterMember.CustomerPassword = null; RegisterMember.PasswordCheck = null; return(RedirectToAction("Index", "Home")); }
public IActionResult Edit(string id) { // Customer cus=new Customer(); try { var cus_ = db.Customers.Where(u => u.Email == id).SingleOrDefault(); CustomerRegisterView cus = new CustomerRegisterView() { Fullname = cus_.Fullname, Address = cus_.Address, Email = cus_.Email }; return(View(cus)); } catch { return(Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }))); } }
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" }))); }
//判斷註冊帳號是否已被註冊過Action public JsonResult AccountCheck(CustomerRegisterView RegisterMember) { return(Json(customerService.AccountCheck(RegisterMember.newCustomer.CustomerID), JsonRequestBehavior.AllowGet)); }