public long UpdateIssueCategory(IssueCategoryObject issueCategory) { try { if (issueCategory == null) { return(-2); } var issueCategoryEntity = ModelMapper.Map <IssueCategoryObject, IssueCategory>(issueCategory); if (issueCategoryEntity == null || issueCategoryEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.IssueCategories.Attach(issueCategoryEntity); db.Entry(issueCategoryEntity).State = EntityState.Modified; db.SaveChanges(); return(issueCategory.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddIssueCategory(IssueCategoryObject issueCategory) { try { if (issueCategory == null) { return(-2); } var issueCategoryEntity = ModelMapper.Map <IssueCategoryObject, IssueCategory>(issueCategory); if (issueCategoryEntity == null || string.IsNullOrEmpty(issueCategoryEntity.Name)) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.IssueCategories.Add(issueCategoryEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateIssueCategory(IssueCategoryObject issueCategory) { try { return(_issueCategoryManager.UpdateIssueCategory(issueCategory)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditIssueCategory(IssueCategoryObject issueCategory) { var gVal = new GenericValidator(); try { var stat = ValidateIssueCategory(issueCategory); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_issueCategory"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldissueCategory = Session["_issueCategory"] as IssueCategoryObject; if (oldissueCategory == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldissueCategory.Name = issueCategory.Name.Trim(); var docStatus = new IssueCategoryServices().UpdateIssueCategory(oldissueCategory); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Issue Category already exists." : "Issue Category information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldissueCategory.Id; gVal.Error = "Issue Category information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Issue Category information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddIssueCategory(IssueCategoryObject issueCategory) { 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 = ValidateIssueCategory(issueCategory); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new IssueCategoryServices().AddIssueCategory(issueCategory); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Issue Category could not be added. Please try again." : "The Issue Category Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Issue Category was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Issue Category processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateIssueCategory(IssueCategoryObject issueCategory) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(issueCategory.Name)) { gVal.Code = -1; gVal.Error = "Please provide Issue Category."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "Issue Category Validation failed. Please provide all required fields and try again."; return(gVal); } }