public ActionResult SaveAjax(WorkerRolePermissionNew rolepermission) { //id=0 means add operation, update operation otherwise bool isNew = rolepermission.ID == 0; //validate data if (ModelState.IsValid) { try { //call repository function to save the data in database wokerrolepermissionnewRepository.InsertOrUpdate(rolepermission); wokerrolepermissionnewRepository.Save(); //set status message if (isNew) { rolepermission.SuccessMessage = "Role permission has been added successfully"; } else { rolepermission.SuccessMessage = "Role permission has been updated successfully"; } } catch (CustomException ex) { rolepermission.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); rolepermission.ErrorMessage = Constants.Messages.UnhandelledError; } } else { foreach (var modelStateValue in ViewData.ModelState.Values) { foreach (var error in modelStateValue.Errors) { rolepermission.ErrorMessage = error.ErrorMessage; break; } if (rolepermission.ErrorMessage.IsNotNullOrEmpty()) { break; } } } //return the status message in json if (rolepermission.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = rolepermission.ErrorMessage })); } else { return(Json(new { success = true, data = rolepermission.SuccessMessage })); } }
public ActionResult Index([DataSourceRequest(Prefix = "Grid")] DataSourceRequest dsRequest) { if (!ViewBag.HasAccessToAdminModule) { WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action"; return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty })); } //create a new instance of wokerrolepermission WorkerRolePermissionNew wokerrolepermission = new WorkerRolePermissionNew(); //return view result return(View(wokerrolepermission)); }
public ActionResult DeleteAjax(int id) { if (!ViewBag.HasAccessToAdminModule) { BaseModel baseModel = new BaseModel(); baseModel.ErrorMessage = "You are not eligible to do this action"; return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, baseModel) }, JsonRequestBehavior.AllowGet)); } //find the role in database WorkerRolePermissionNew rolepermission = wokerrolepermissionnewRepository.Find(id); if (rolepermission == null) { //set error message if it does not exist in database rolepermission = new WorkerRolePermissionNew(); rolepermission.ErrorMessage = "Role permission not found"; } else { try { //delete rolepermission from database wokerrolepermissionnewRepository.Delete(rolepermission); wokerrolepermissionnewRepository.Save(); //set success message rolepermission.SuccessMessage = "Role permission has been deleted successfully"; } catch (CustomException ex) { rolepermission.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); rolepermission.ErrorMessage = Constants.Messages.UnhandelledError; } } //return action status in json to display on a message bar if (rolepermission.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, rolepermission) })); } else { return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, rolepermission) })); } }
public ActionResult EditorAjax(int id) { WorkerRolePermissionNew rolepermission = null; if (id > 0) { //find an existing rolepermission from database rolepermission = wokerrolepermissionnewRepository.FindByID(id); if (rolepermission == null) { //throw an exception if id is provided but data does not exist in database return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Role permission not found")); } } else { //create a new instance if id is not provided rolepermission = new WorkerRolePermissionNew(); } //rolepermission = new WorkerRolePermissionNew(); //return the html of editor to display on popup return(Content(this.RenderPartialViewToString(Constants.PartialViews.CreateOrEdit, rolepermission))); }