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