public long UpdateCustomCode(CustomCodeObject customCode)
 {
     try
     {
         if (customCode == null)
         {
             return(-2);
         }
         using (var db = new ImportPermitEntities())
         {
             if (db.CustomCodes.Count(k => k.Name.ToLower().Trim() == customCode.Name.ToLower().Trim() && k.CustomCodeId == customCode.CustomCodeId) > 0)
             {
                 return(-3);
             }
             var customCodeEntity = ModelMapper.Map <CustomCodeObject, CustomCode>(customCode);
             if (customCodeEntity == null || customCodeEntity.CustomCodeId < 1)
             {
                 return(-2);
             }
             db.CustomCodes.Attach(customCodeEntity);
             db.Entry(customCodeEntity).State = EntityState.Modified;
             db.SaveChanges();
             return(customCode.CustomCodeId);
         }
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        public long AddCustomCode(CustomCodeObject customCode)
        {
            try
            {
                if (customCode == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (db.CustomCodes.Count(k => k.Name.ToLower().Trim() == customCode.Name.ToLower().Trim()) > 0)
                    {
                        return(-3);
                    }
                    var customCodeEntity = ModelMapper.Map <CustomCodeObject, CustomCode>(customCode);

                    if (customCodeEntity == null || string.IsNullOrEmpty(customCodeEntity.Name))
                    {
                        return(-2);
                    }
                    var returnStatus = db.CustomCodes.Add(customCodeEntity);
                    db.SaveChanges();
                    return(returnStatus.CustomCodeId);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        public ActionResult EditCustomCode(CustomCodeObject customCode)
        {
            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 = ValidateCustomCode(customCode);

                if (stat.Code < 1)
                {
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                if (Session["_customCode"] == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var oldcustomCode = Session["_customCode"] as CustomCodeObject;

                if (oldcustomCode == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                oldcustomCode.Name = customCode.Name.Trim();
                var docStatus = new CustomCodeServices().UpdateCustomCode(oldcustomCode);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docStatus == -3 ? "Custom Code already exists." : "Custom Code information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldcustomCode.CustomCodeId;
                gVal.Error = "Custom Code information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Custom Code information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #4
0
 public long UpdateCustomCode(CustomCodeObject customCode)
 {
     try
     {
         return(_customCodeManager.UpdateCustomCode(customCode));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        public ActionResult AddCustomCode(CustomCodeObject customCode)
        {
            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 = ValidateCustomCode(customCode);

                if (validationResult.Code == 1)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var appStatus = new CustomCodeServices().AddCustomCode(customCode);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "CustomCode upload failed. Please try again." : "The Custom Code Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "Custom Code was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "Custom Code processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        private GenericValidator ValidateCustomCode(CustomCodeObject customCode)
        {
            var gVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(customCode.Name))
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please provide Custom Code.";
                    return(gVal);
                }

                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Custom Code Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }