public long UpdateFeeType(FeeTypeObject feeType) { try { if (feeType == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.FeeTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == feeType.Name.ToLower().Trim().Replace(" ", "") && g.FeeTypeId != feeType.FeeTypeId) > 0) { return(-3); } var feeTypeEntity = ModelMapper.Map <FeeTypeObject, FeeType>(feeType); if (feeTypeEntity == null || feeTypeEntity.FeeTypeId < 1) { return(-2); } db.FeeTypes.Attach(feeTypeEntity); db.Entry(feeTypeEntity).State = EntityState.Modified; db.SaveChanges(); return(feeType.FeeTypeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddFeeType(FeeTypeObject feeType) { try { if (feeType == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.FeeTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == feeType.Name.ToLower().Trim().Replace(" ", "")) > 0) { return(-3); } var feeTypeEntity = ModelMapper.Map <FeeTypeObject, FeeType>(feeType); if (feeTypeEntity == null || string.IsNullOrEmpty(feeTypeEntity.Name)) { return(-2); } var returnStatus = db.FeeTypes.Add(feeTypeEntity); db.SaveChanges(); return(returnStatus.FeeTypeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditFeeType(FeeTypeObject feeType) { var gVal = new GenericValidator(); try { if (!ModelState.IsValid) { gVal.Code = -1; gVal.Error = "Plese provide all required fields and try again."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var stat = ValidateFeeType(feeType); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_feeType"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldfeeType = Session["_feeType"] as FeeTypeObject; if (oldfeeType == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldfeeType.Name = feeType.Name.Trim(); oldfeeType.Description = feeType.Description; var docStatus = new FeeTypeServices().UpdateFeeType(oldfeeType); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Fee Type already exists." : "Fee Type information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldfeeType.FeeTypeId; gVal.Error = "Fee Type information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Fee Type information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public long UpdateFeeType(FeeTypeObject feeType) { try { return(_feeTypeManager.UpdateFeeType(feeType)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult AddFeeType(FeeTypeObject feeType) { var gVal = new GenericValidator(); try { if (!ModelState.IsValid) { gVal.Code = -1; gVal.Error = "Plese provide all required fields and try again."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var importerInfo = GetLoggedOnUserInfo(); if (importerInfo.Id < 1) { gVal.Error = "Your session has timed out"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var validationResult = ValidateFeeType(feeType); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new FeeTypeServices().AddFeeType(feeType); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Fee Type could not be added. Please try again." : "The Fee Type Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Fee Type was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Fee Type processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateFeeType(FeeTypeObject feeType) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(feeType.Name)) { gVal.Code = -1; gVal.Error = "Please provide Fee Type."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "Fee Type Validation failed. Please provide all required fields and try again."; return(gVal); } }