public long UpdateFaqCategory(FaqCategoryObject faqCategory) { try { if (faqCategory == null) { return(-2); } var faqCategoryEntity = ModelMapper.Map <FaqCategoryObject, FaqCategory>(faqCategory); if (faqCategoryEntity == null || faqCategoryEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.FaqCategories.Attach(faqCategoryEntity); db.Entry(faqCategoryEntity).State = EntityState.Modified; db.SaveChanges(); return(faqCategory.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddFaqCategory(FaqCategoryObject faqCategory) { try { if (faqCategory == null) { return(-2); } var faqCategoryEntity = ModelMapper.Map <FaqCategoryObject, FaqCategory>(faqCategory); if (faqCategoryEntity == null || string.IsNullOrEmpty(faqCategoryEntity.Name)) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.FaqCategories.Add(faqCategoryEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateFaqCategory(FaqCategoryObject faqCategory) { try { return(_faqCategoryManager.UpdateFaqCategory(faqCategory)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditFaqCategory(FaqCategoryObject faqCategory) { var gVal = new GenericValidator(); try { var stat = ValidateFaqCategory(faqCategory); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_faqCategory"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldfaqCategory = Session["_faqCategory"] as FaqCategoryObject; if (oldfaqCategory == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldfaqCategory.Name = faqCategory.Name.Trim(); oldfaqCategory.Description = faqCategory.Description; var docStatus = new FaqCategoryServices().UpdateFaqCategory(oldfaqCategory); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "FAQ Category already exists." : "FAQ Category information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldfaqCategory.Id; gVal.Error = "FAQ Category information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "FAQ Category information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddFaqCategory(FaqCategoryObject faqCategory) { var gVal = new GenericValidator(); try { var importerInfo = GetLoggedOnUserInfo(); if (importerInfo.Id < 1) { gVal.Error = "Your session has timed out"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var validationResult = ValidateFaqCategory(faqCategory); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new FaqCategoryServices().AddFaqCategory(faqCategory); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "FAQ Category could not be added. Please try again." : "The FAQ Category Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "FAQ Category was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "FAQ Category processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateFaqCategory(FaqCategoryObject faqCategory) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(faqCategory.Name)) { gVal.Code = -1; gVal.Error = "Please provide FAQ Category."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "FAQ Category Validation failed. Please provide all required fields and try again."; return(gVal); } }