public ActionResult Edit(EffortViewModel viewModel) { if (ModelState.IsValid) { var effort = db.Efforts.Single(x => x.Id == viewModel.Id); if (!EntityAuthorization.EffortEdit(effort)) { return(HttpNotFound()); } effort.InitFromViewModel(viewModel); effort.ModifiedUserId = Viola.Models.User.GetCurrentUserId(); effort.ModifiedDatetime = DateTime.Now.ToUniversalTime(); db.Entry(effort).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(Viola.Models.User.GetUsersForEffort(), "Id", "FullName", viewModel.UserId); ViewBag.TaskId = new SelectList(Task.GetTasksByRole(), "Id", "Name", viewModel.TaskId); return(View(viewModel)); }
// GET: Efforts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Effort effort = db.Efforts.Find(id); if (effort == null) { return(HttpNotFound()); } if (!EntityAuthorization.EffortEdit(effort)) { return(HttpNotFound()); } ViewBag.UserId = new SelectList(Viola.Models.User.GetUsersForEffort(), "Id", "FullName", effort.UserId); ViewBag.TaskId = new SelectList(Task.GetTasksByRole(), "Id", "Name", effort.TaskId); return(View(Mapper.Map <Effort, EffortViewModel>(effort))); }