public ActionResult Edit(int?id, FormCollection forms) { IEnumerable <SelectListItem> menuTypes = GetMenuTypes(); var vm = new ViewModelMenuItem { MenuTypes = menuTypes }; if (id == null) { return(CreateNewMenuItem(vm, menuTypes, forms)); } vm.MenuItem = menuService.LoadMenuItem(id.Value); int newId; int prevId = 0; if (null != vm.MenuItem.Entry) { prevId = vm.MenuItem.Entry.Id; } UpdateModel(vm.MenuItem, "MenuItem", new[] { "Id", "CreatedAt", "MenuId", "Title", "NavigateUrl", "Visible" }, forms.ToValueProvider()); bool isExternal = false; bool.TryParse(Request.Form.GetValues("MenuItem.IsExternalUrl")[0], out isExternal); if (isExternal) { vm.MenuItem.Entry = null; } else { vm.MenuItem.NavigateUrl = string.Empty; } if (Int32.TryParse(forms["MenuItem.Entry.Id"], out newId) && newId != prevId) { vm.MenuItem.Entry = pageService.Load(newId); menuService.SaveMenuItem(vm.MenuItem); } else { menuService.SaveMenuItem(vm.MenuItem); } TempData["SuccessResult"] = "MenuItem was successfully updated"; return(RedirectToAction("Edit", "MenuItem", new { id = vm.MenuItem.Id })); }
private RedirectToRouteResult CreateNewMenuItem(ViewModelMenuItem vm, IEnumerable <SelectListItem> menuTypes, FormCollection forms) { vm.MenuItem = new CmsMenuItem(); TryUpdateModel(vm, forms.ToValueProvider()); menuService.SaveMenuItem(vm.MenuItem); TempData["SuccessResult"] = "MenuItem was successfully created"; return(RedirectToAction("Edit", "MenuItem", new { id = vm.MenuItem.Id })); }
public ActionResult Edit(int? id, FormCollection forms) { IEnumerable<SelectListItem> menuTypes = GetMenuTypes(); var vm = new ViewModelMenuItem { MenuTypes = menuTypes }; if (id == null) { return CreateNewMenuItem(vm, menuTypes, forms); } vm.MenuItem = menuService.LoadMenuItem(id.Value); int newId; int prevId = 0; if (null != vm.MenuItem.Entry) { prevId = vm.MenuItem.Entry.Id; } UpdateModel(vm.MenuItem, "MenuItem", new[] {"Id", "CreatedAt", "MenuId", "Title", "NavigateUrl", "Visible"}, forms.ToValueProvider()); bool isExternal = false; bool.TryParse(Request.Form.GetValues("MenuItem.IsExternalUrl")[0], out isExternal); if (isExternal) { vm.MenuItem.Entry = null; } else { vm.MenuItem.NavigateUrl = string.Empty; } if (Int32.TryParse(forms["MenuItem.Entry.Id"], out newId) && newId != prevId) { vm.MenuItem.Entry = pageService.Load(newId); menuService.SaveMenuItem(vm.MenuItem); } else { menuService.SaveMenuItem(vm.MenuItem); } TempData["SuccessResult"] = "MenuItem was successfully updated"; return RedirectToAction("Edit", "MenuItem", new {id = vm.MenuItem.Id}); }
private RedirectToRouteResult CreateNewMenuItem(ViewModelMenuItem vm, IEnumerable<SelectListItem> menuTypes, FormCollection forms) { vm.MenuItem = new CmsMenuItem(); TryUpdateModel(vm, forms.ToValueProvider()); menuService.SaveMenuItem(vm.MenuItem); TempData["SuccessResult"] = "MenuItem was successfully created"; return RedirectToAction("Edit", "MenuItem", new {id = vm.MenuItem.Id}); }