public ActionResult Edit() { GroupsService groupService = new GroupsService(); GroupEditVM model = new GroupEditVM(); TryUpdateModel(model); if (!ModelState.IsValid) { return(View(model)); } Group g; if (model.ID != 0) { g = groupService.GetByID(model.ID); } else { g = new Group(); } if (g == null) { return(this.RedirectToAction(c => c.List())); } Mapper.Map(model, g); groupService.Save(g); return(this.RedirectToAction(c => c.List())); }
public ActionResult Edit(int?id) { GroupsService groupService = new GroupsService(); GroupEditVM model = new GroupEditVM(); Group group; if (id.HasValue) { group = groupService.GetByID(id.Value); if (group == null) { return(this.RedirectToAction(c => c.List())); } } else { group = new Group(); } Mapper.Map(group, model); return(View(model)); }