public ActionResult UpdateCustomer(CustomerChangeModel model) { var cookie = CookieCheck.check(Request.Cookies[FormsAuthentication.FormsCookieName]); if (cookie.Status == cookieStatus.Match && cookie.Authority == Character.Customer) { CustomerService customerService = new CustomerService(); if (model.NewPassword != null) { if (model.NewPassword != model.ConfirmNewPassword) { TempData["Message"] = "二次驗證密碼錯誤"; return(RedirectToAction("Index", "Customer")); } else if (customerService.UpdateCustomerDetail(cookie.Username, model.NewPassword, model.CustomerName, model.Email, model.Phone, model.Address) == false) { TempData["Message"] = "更改失敗,稍後重試"; } return(RedirectToAction("Index", "Customer")); } if (customerService.UpdateCustomerDetail(cookie.Username, model.CustomerName, model.Email, model.Phone, model.Address) == false) { TempData["Message"] = "更改失敗,稍後重試"; } return(RedirectToAction("Index", "Customer")); } else { TempData["Message"] = "請先登入會員"; return(RedirectToAction("Index", "Home")); } }
public IActionResult Edit([FromQuery] CustomerChangeModel model) { if (ModelState.IsValid) { _customerOperations.EditCustomer(model); } else { return(BadRequest()); } return(Ok()); }
public void EditCustomer(CustomerChangeModel model) { _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} started"); var customer = _repositories.Customers.GetSingle(u => u.CustomerId == model.CustomerId); if (customer == null) { throw new LogicException("There is no customer with that Id"); } customer.City = string.IsNullOrEmpty(model.City) ? customer.City : model.City; customer.CompanyName = string.IsNullOrEmpty(model.CompanyName) ? customer.CompanyName : model.CompanyName; customer.ContactName = string.IsNullOrEmpty(model.ContactName) ? customer.ContactName : model.ContactName; customer.ContactTitle = string.IsNullOrEmpty(model.ContactTitle) ? customer.ContactTitle : model.ContactTitle; customer.Country = string.IsNullOrEmpty(model.Country) ? customer.Country : model.Country; customer.Region = string.IsNullOrEmpty(model.Region) ? customer.Region : model.Region; _repositories.Customers.Update(customer); _repositories.SaveChanges(); _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} finished"); }