// // GET: /Role/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 menuList = _menuRepository.GetAll().Select(x => new KendoTreeviewViewModel { Id = x.MenuId.ToString(), Text = x.MenuName }).ToList(); var rightList = _rightRepository.GetAll().Select(x => new KendoTreeviewViewModel { Id = x.RightId.ToString(), Text = x.RightName }).ToList(); var viewModel = new RoleViewModel() { RoleId = 0, ddlApplications = applicationList, ddlModules = moduleList, MenuTreeViewModelList = menuList, RightTreeViewModelList = rightList }; //return View(); return PartialView("_AddOrEdit", viewModel); }
// // GET: /Role/Details/By ID public ActionResult Details(int id) { var errorViewModel = new ErrorViewModel(); try { //var role = _roleRepository.GetById(id); var role = _roleRepository.GetAll().SingleOrDefault(x => x.RoleId == id); if (role != null) { var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == role.ApplicationId); var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == role.ModuleId); if (singleOrDefaultApplication != null && singleOrDefaultModule != null) { var viewModel = new RoleViewModel() { RoleId = role.RoleId, RoleName = role.RoleName, Description = role.Description, ApplicationId = Convert.ToInt32(role.ApplicationId), ApplicationName = singleOrDefaultApplication.ApplicationName, ModuleId = Convert.ToInt32(role.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(RoleViewModel roleViewModel) { try { if (ModelState.IsValid) { //add if (roleViewModel.RoleId == 0 && roleViewModel.ActionName == "Add") { var model = new TblRole() { RoleId = roleViewModel.RoleId, RoleName = roleViewModel.RoleName, Description = roleViewModel.Description, ApplicationId = roleViewModel.ApplicationId, ModuleId = roleViewModel.ModuleId }; //_roleRepository.Insert(model); } else if (roleViewModel.ActionName == "Edit") //edit { TblRole role = _roleRepository.GetById(roleViewModel.RoleId); if (role != null) { role.RoleId = roleViewModel.RoleId; role.RoleName = roleViewModel.RoleName; role.Description = roleViewModel.Description; role.ApplicationId = roleViewModel.ApplicationId; role.ModuleId = roleViewModel.ModuleId; //_roleRepository.Update(role); } else { return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, roleViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject())); } } //_roleRepository.Save(); return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, roleViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully.")); } return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, roleViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState))); } catch (Exception ex) { return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, roleViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageFormat(ex))); } }
// // GET: /Role/Edit/By ID public ActionResult Edit(int id) { var errorViewModel = new ErrorViewModel(); try { //var role = _roleRepository.GetById(id); var role = _roleRepository.GetAll().SingleOrDefault(x => x.RoleId == id); if (role != null) { var moduleList = SelectListItemExtension.PopulateDropdownList(_moduleRepository.GetAll().ToList<TblModule>(), "ModuleId", "ModuleName", isEdit: true, selectedValue: role.ModuleId.ToString()).ToList(); var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList<TblApplication>(), "ApplicationId", "ApplicationName", isEdit: true, selectedValue: role.ApplicationId.ToString()).ToList(); var singleOrDefaultApplication = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == role.ApplicationId); var singleOrDefaultModule = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == role.ModuleId); if (singleOrDefaultApplication != null && singleOrDefaultModule != null) { var viewModel = new RoleViewModel() { RoleId = role.RoleId, RoleName = role.RoleName, Description = role.Description, ApplicationId = Convert.ToInt32(role.ApplicationId), ApplicationName = singleOrDefaultApplication != null ? singleOrDefaultApplication.ApplicationName : null, ddlApplications = applicationList, ModuleId = Convert.ToInt32(role.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); }