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