// // GET: /Module/Add public ActionResult Add() { var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList<TblApplication>(), "ApplicationId", "ApplicationName").ToList(); var viewModel = new ModuleViewModel() { ModuleId = 0, ddlApplications = applicationList }; //return View(); return PartialView("_AddOrEdit", viewModel); }
// // GET: /Module/Details/By ID public ActionResult Details(int id) { var errorViewModel = new ErrorViewModel(); try { //var module = _moduleRepository.GetById(id); var module = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == id); if (module != null) { var singleOrDefault = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == module.ApplicationId); if (singleOrDefault != null) { var viewModel = new ModuleViewModel() { ModuleId = module.ModuleId, ModuleName = module.ModuleName, Description = module.Description, ModuleTitle = module.ModuleTitle, ApplicationId = module.ApplicationId, ApplicationName = singleOrDefault.ApplicationName }; return PartialView("_Details", viewModel); } } errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject(); } catch (Exception ex) { errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex); } return PartialView("_ErrorPopup", errorViewModel); }
public ActionResult Save(ModuleViewModel moduleViewModel) { try { if (ModelState.IsValid) { //add if (moduleViewModel.ModuleId == 0 && moduleViewModel.ActionName == "Add") { var model = new TblModule() { ModuleId = moduleViewModel.ModuleId, ModuleName = moduleViewModel.ModuleName, Description = moduleViewModel.Description, ModuleTitle = moduleViewModel.ModuleTitle, ApplicationId = moduleViewModel.ApplicationId }; _moduleRepository.Insert(model); } else if (moduleViewModel.ActionName == "Edit") //edit { TblModule module = _moduleRepository.GetById(moduleViewModel.ModuleId); if (module != null) { module.ModuleId = moduleViewModel.ModuleId; module.ModuleName = moduleViewModel.ModuleName; module.Description = moduleViewModel.Description; module.ModuleTitle = moduleViewModel.ModuleTitle; module.ApplicationId = moduleViewModel.ApplicationId; _moduleRepository.Update(module); } else { return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject())); } } _moduleRepository.Save(); return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, moduleViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully.")); } return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, MessageType.success.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState))); } catch (Exception ex) { return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, MessageType.success.ToString(), ExceptionHelper.ExceptionMessageFormat(ex))); } }
// // GET: /Module/Edit/By ID public ActionResult Edit(int id) { var errorViewModel = new ErrorViewModel(); try { //var module = _moduleRepository.GetById(id); var module = _moduleRepository.GetAll().SingleOrDefault(x => x.ModuleId == id); if (module != null) { var applicationList = SelectListItemExtension.PopulateDropdownList(_applicationRepository.GetAll().ToList<TblApplication>(), "ApplicationId", "ApplicationName", isEdit: true, selectedValue: module.ApplicationId.ToString()).ToList(); var singleOrDefault = _applicationRepository.GetAll().SingleOrDefault(x => x.ApplicationId == module.ApplicationId); if (singleOrDefault != null) { var viewModel = new ModuleViewModel() { ModuleId = module.ModuleId, ModuleName = module.ModuleName, Description = module.Description, ModuleTitle = module.ModuleTitle, ApplicationId = module.ApplicationId, ApplicationName = singleOrDefault.ApplicationName, ddlApplications = applicationList }; return PartialView("_AddOrEdit", viewModel); } } errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject(); } catch (Exception ex) { errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex); } return PartialView("_ErrorPopup", errorViewModel); }