public bool Update(Customer customer) { var cust = _customers.SingleOrDefault(x => x.CustomerId == customer.CustomerId); if (cust == null) return false; _customers.Remove(cust); _customers.Add(customer); return true; }
private bool Update(ControllerContext context, Customer customer) { var result = _repository.Update(customer); //ユーザに対するメッセージを追加 var msg = result ? "Sucsessfully updated." : "Update failed."; context.Controller.TempData["OutputMessage"] = msg; return result; }
private bool Validate(ControllerContext context, Customer customer) { var result = true; var modelState = context.Controller.ViewData.ModelState; if (string.IsNullOrEmpty(customer.Country)) { modelState.AddModelError("Country", "Need input"); //モデルの状態をTempDataに保存 context.Controller.TempData["ModelState"] = modelState; result = false; } return result; }
public ActionResult Update(Customer customer) { var model = _service.TryUpdateCustomer(ControllerContext, customer); return RedirectToAction("edit", new { id = customer.CustomerId }); }
public EditCustomerViewModel TryUpdateCustomer(ControllerContext controllerContext, Customer customer) { if (Validate(controllerContext, customer)) Update(controllerContext, customer); return EditCustomer(customer.CustomerId); }