public ActionResult SaveAjax(QualityOfLifeCategory qualityoflifecategory) { //id=0 means add operation, update operation otherwise bool isNew = qualityoflifecategory.ID == 0; //validate data if (ModelState.IsValid) { try { //call repository function to save the data in database qualityoflifecategoryRepository.InsertOrUpdate(qualityoflifecategory); qualityoflifecategoryRepository.Save(); //set status message if (isNew) { qualityoflifecategory.SuccessMessage = "QualityOfLifeCategory has been added successfully"; } else { qualityoflifecategory.SuccessMessage = "QualityOfLifeCategory has been updated successfully"; } } catch (CustomException ex) { qualityoflifecategory.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); qualityoflifecategory.ErrorMessage = Constants.Messages.UnhandelledError; } } else { foreach (var modelStateValue in ViewData.ModelState.Values) { foreach (var error in modelStateValue.Errors) { qualityoflifecategory.ErrorMessage = error.ErrorMessage; break; } if (qualityoflifecategory.ErrorMessage.IsNotNullOrEmpty()) { break; } } } //return the status message in json if (qualityoflifecategory.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = qualityoflifecategory.ErrorMessage })); } else { return(Json(new { success = true, data = qualityoflifecategory.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 qualityoflifecategory QualityOfLifeCategory qualityoflifecategory = new QualityOfLifeCategory(); //return view result return(View(qualityoflifecategory)); }
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 qualityoflifecategory in database QualityOfLifeCategory qualityoflifecategory = qualityoflifecategoryRepository.Find(id); if (qualityoflifecategory == null) { //set error message if it does not exist in database qualityoflifecategory = new QualityOfLifeCategory(); qualityoflifecategory.ErrorMessage = "QualityOfLifeCategory not found"; } else { try { //delete qualityoflifecategory from database qualityoflifecategoryRepository.Delete(qualityoflifecategory); qualityoflifecategoryRepository.Save(); //set success message qualityoflifecategory.SuccessMessage = "QualityOfLifeCategory has been deleted successfully"; } catch (CustomException ex) { qualityoflifecategory.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); qualityoflifecategory.ErrorMessage = Constants.Messages.UnhandelledError; } } //return action status in json to display on a message bar if (qualityoflifecategory.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, qualityoflifecategory) })); } else { return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, qualityoflifecategory) })); } }
public ActionResult EditorAjax(int id) { QualityOfLifeCategory qualityoflifecategory = null; if (id > 0) { //find an existing qualityoflifecategory from database qualityoflifecategory = qualityoflifecategoryRepository.Find(id); if (qualityoflifecategory == null) { //throw an exception if id is provided but data does not exist in database return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "QualityOfLifeCategory not found")); } } else { //create a new instance if id is not provided qualityoflifecategory = new QualityOfLifeCategory(); } //return the html of editor to display on popup return(Content(this.RenderPartialViewToString(Constants.PartialViews.CreateOrEdit, qualityoflifecategory))); }