public long UpdateProcessingHistory(ProcessingHistoryObject processingHistory)
        {
            try
            {
                if (processingHistory == null)
                {
                    return(-2);
                }

                var processingHistoryEntity = ModelMapper.Map <ProcessingHistoryObject, ProcessingHistory>(processingHistory);
                if (processingHistoryEntity == null || processingHistoryEntity.Id < 1)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    db.ProcessingHistories.Attach(processingHistoryEntity);
                    db.Entry(processingHistoryEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(processingHistory.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        public long AddProcessingHistory(ProcessingHistoryObject processingHistory)
        {
            try
            {
                if (processingHistory == null)
                {
                    return(-2);
                }

                var processingHistoryEntity = ModelMapper.Map <ProcessingHistoryObject, ProcessingHistory>(processingHistory);
                if (processingHistoryEntity == null || processingHistoryEntity.ApplicationId < 1)
                {
                    return(-2);
                }
                using (var db = new ImportPermitEntities())
                {
                    var returnStatus = db.ProcessingHistories.Add(processingHistoryEntity);
                    db.SaveChanges();
                    return(returnStatus.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
 public long UpdateProcessingHistory(ProcessingHistoryObject processingHistory)
 {
     try
     {
         return(_processingHistoryManager.UpdateProcessingHistory(processingHistory));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        public ActionResult EditProcessingHistory(ProcessingHistoryObject processingHistory)
        {
            var gVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(processingHistory.ReferenceCode.Trim()))
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please provide ProcessingHistory.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

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

                var oldProcessingHistory = Session["_ProcessingHistory"] as ProcessingHistoryObject;

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


                oldProcessingHistory.ReferenceCode = processingHistory.ReferenceCode.Trim();

                var docStatus = new ProcessingHistoryServices().UpdateProcessingHistory(oldProcessingHistory);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "ProcessingHistory information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldProcessingHistory.Id;
                gVal.Error = "ProcessingHistory information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "ProcessingHistory information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult AddProcessingHistory(ProcessingHistoryObject processingHistory)
        {
            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 = ValidateProcessingHistory(processingHistory);

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

                var appStatus = new ProcessingHistoryServices().AddProcessingHistory(processingHistory);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "ProcessingHistory upload failed. Please try again." : "The ProcessingHistory Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "ProcessingHistory was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "ProcessingHistory processingHistorying failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        private GenericValidator ValidateProcessingHistory(ProcessingHistoryObject processingHistory)
        {
            var gVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(processingHistory.ReferenceCode))
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select provide ProcessingHistory.";
                    return(gVal);
                }


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