public ActionResult Edit(int id) { InfoFormat("User #{0} is going to edit Organization #{1}", User.Identity.Name, id); Organization model = _repository.Organizations.SingleOrDefault(x => x.Id == id); if(model == null) { WarnFormat("Non-existing organization #{0}!", id); return RedirectToAction("notfound", "help"); } OrganizationEditViewModel viewModel = new OrganizationEditViewModel(); viewModel.Organization = model; viewModel.Parent = _repository.GetById(model.ParentId); viewModel.Children = _repository.GetByParentId(model.Id); viewModel.Users = _repository.GetUsersInOrganization(model.Id); return View(viewModel); }
public ActionResult Edit(OrganizationEditViewModel model) { try { InfoFormat("User #{0} going to update Organization #{1}", User.Identity.Name, model.Organization.Id); var record = _repository.GetById(model.Organization.Id); UpdateModel(record, "Organization"); _repository.SubmitChanges(); SetTempOkMessage("Organization {0} was successfully updated", model.Organization.Name); return RedirectToAction("list", new { parent = model.Organization.ParentId == 0 ? model.Organization.Id : model.Organization.ParentId }); } catch(Exception ex) { Error("Error updating Organization!", ex); ModelState.AddModelError("", ex.Message); } return View(model); }