// // GET: /Menu/Add public ActionResult Add() { var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList<TblApplication>(), "ApplicationId", "ApplicationName").ToList(); var moduleList = SelectListItemExtension.PopulateDropdownList(_moduleRepository.GetAll().ToList<TblModule>(), "ModuleId", "ModuleTitle").ToList(); var parentMenuList = SelectListItemExtension.PopulateDropdownList(_menuRepository.GetAll().ToList<TblMenu>(), "MenuId", "MenuName").ToList(); var viewModel = new MenuViewModel() { MenuId = 0, ddlApplications = applicationList, ddlModules = moduleList, ddlParentMenus = parentMenuList }; //return View(); return PartialView("_AddOrEdit", viewModel); }
// // GET: /Menu/Details/By ID public ActionResult Details(int id) { var errorViewModel = new ErrorViewModel(); try { //var menu = _menuRepository.GetById(id); var menu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == id); if (menu != null) { var singleOrDefaultParentMenu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == menu.ParentMenuId); var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == menu.ApplicationId); var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == menu.ModuleId); if (singleOrDefaultApplication != null && singleOrDefaultModule != null) { var viewModel = new MenuViewModel() { MenuId = menu.MenuId, MenuName = menu.MenuName, MenuCaption = menu.MenuCaption, MenuCaptionBng = menu.MenuCaptionBng, PageUrl = menu.PageUrl, SerialNo = Convert.ToInt32(menu.SerialNo), OrderNo = Convert.ToInt32(menu.OrderNo), ParentMenuId = Convert.ToInt32(menu.ParentMenuId), ParentMenuName = singleOrDefaultParentMenu.MenuName, ApplicationId = menu.ApplicationId, ApplicationName = singleOrDefaultApplication.ApplicationName, ModuleId = menu.ModuleId, ModuleName = singleOrDefaultModule.ModuleName }; return PartialView("_Details", viewModel); } } errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject(); } catch (Exception ex) { errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex); } return PartialView("_ErrorPopup", errorViewModel); }
public ActionResult Save(MenuViewModel menuViewModel) { try { if (ModelState.IsValid) { //add if (menuViewModel.MenuId == 0 && menuViewModel.ActionName == "Add") { var model = new TblMenu() { MenuId = menuViewModel.MenuId, MenuName = menuViewModel.MenuName, MenuCaption = menuViewModel.MenuCaption, MenuCaptionBng = menuViewModel.MenuCaptionBng, PageUrl = menuViewModel.PageUrl, SerialNo = menuViewModel.SerialNo, OrderNo = menuViewModel.OrderNo, ParentMenuId = menuViewModel.ParentMenuId, ApplicationId = menuViewModel.ApplicationId, ModuleId = menuViewModel.ModuleId }; _menuRepository.Insert(model); } else if (menuViewModel.ActionName == "Edit") //edit { TblMenu menu = _menuRepository.GetById(menuViewModel.MenuId); if (menu != null) { menu.MenuId = menuViewModel.MenuId; menu.MenuName = menuViewModel.MenuName; menu.MenuCaption = menuViewModel.MenuCaption; menu.MenuCaptionBng = menuViewModel.MenuCaptionBng; menu.PageUrl = menuViewModel.PageUrl; menu.SerialNo = menuViewModel.SerialNo; menu.OrderNo = menuViewModel.OrderNo; menu.ParentMenuId = menuViewModel.ParentMenuId; menu.ApplicationId = menuViewModel.ApplicationId; menu.ModuleId = menuViewModel.ModuleId; _menuRepository.Update(menu); } else { return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, menuViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject())); } } _menuRepository.Save(); return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, menuViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully.")); } return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, menuViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState))); } catch (Exception ex) { return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, menuViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageFormat(ex))); } }
// // GET: /Menu/Edit/By ID public ActionResult Edit(int id) { var errorViewModel = new ErrorViewModel(); try { //var menu = _menuRepository.GetById(id); var menu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == id); if (menu != null) { var parentMenuList = SelectListItemExtension.PopulateDropdownList(_menuRepository.GetAll().ToList<TblMenu>(), "MenuId", "MenuName", isEdit: true, selectedValue: menu.ParentMenuId.ToString()).ToList(); var moduleList = SelectListItemExtension.PopulateDropdownList(_moduleRepository.GetAll().ToList<TblModule>(), "ModuleId", "ModuleName", isEdit: true, selectedValue: menu.ModuleId.ToString()).ToList(); var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList<TblApplication>(), "ApplicationId", "ApplicationName", isEdit: true, selectedValue: menu.ApplicationId.ToString()).ToList(); var singleOrDefaultParentMenu = _menuRepository.GetAll().SingleOrDefault(x => x.MenuId == menu.ParentMenuId); var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == menu.ApplicationId); var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == menu.ModuleId); if (singleOrDefaultApplication != null && singleOrDefaultModule != null) { var viewModel = new MenuViewModel() { MenuId = menu.MenuId, MenuName = menu.MenuName, MenuCaption = menu.MenuCaption, MenuCaptionBng = menu.MenuCaptionBng, PageUrl = menu.PageUrl, SerialNo = Convert.ToInt32(menu.SerialNo), OrderNo = Convert.ToInt32(menu.OrderNo), ParentMenuId = Convert.ToInt32(menu.ParentMenuId), ParentMenuName = singleOrDefaultParentMenu != null ? singleOrDefaultParentMenu.MenuName : null, ddlParentMenus = parentMenuList, ApplicationId = menu.ApplicationId, ApplicationName = singleOrDefaultApplication != null ? singleOrDefaultApplication.ApplicationName : null, ddlApplications = applicationList, ModuleId = menu.ModuleId, ModuleName = singleOrDefaultModule != null ? singleOrDefaultModule.ModuleName : null, ddlModules = moduleList }; return PartialView("_AddOrEdit", viewModel); } } errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject(); } catch (Exception ex) { errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex); } return PartialView("_ErrorPopup", errorViewModel); }