public ActionResult UpdateNews(UpdateNewsViewModel vm) { if (!ModelState.IsValid) { TempData["msg"] = "alert('編輯欄位不能為空,請重新確認');"; return(RedirectToAction("Index")); } var result = newsService.UpdateNews(vm); if (!result.Success) { TempData["msg"] = "alert('Error');"; return(RedirectToAction("Index")); } TempData["msg"] = "alert('修改完成');"; return(RedirectToAction("Index")); }
public IResult UpdateNews(UpdateNewsViewModel vm) { IResult result = new Result(); try { var instance = repository.Get(i => i.Id == vm.Id); instance.Title = vm.Title; instance.Content = vm.Content; repository.Update(instance); result.Success = true; } catch (Exception e) { result.Message = e.ToString(); throw; } return(result); }