Ejemplo n.º 1
0
        public long AddThroughPut(ThroughPutObject throughPut)
        {
            try
            {
                if (throughPut == null)
                {
                    return(-2);
                }

                var documentEntity = ModelMapper.Map <DocumentObject, Document>(throughPut.DocumentObject);
                if (documentEntity == null || documentEntity.DocumentTypeId < 1)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    var throughPutEntities = (from th in db.ThroughPuts.Where(th => th.Id == throughPut.Id)
                                              join appItem in db.ApplicationItems on th.ApplicationItemId equals appItem.Id
                                              join app in db.Applications on appItem.ApplicationId equals app.Id
                                              select new { th, app }).ToList();

                    if (!throughPutEntities.Any())
                    {
                        return(-2);
                    }

                    var throughPutEntity = throughPutEntities[0].th;
                    var appEntity        = throughPutEntities[0].app;

                    var docEntity = db.Documents.Add(documentEntity);
                    db.SaveChanges();

                    var appDoc = new ApplicationDocument
                    {
                        DocumentId    = docEntity.DocumentId,
                        ApplicationId = appEntity.Id
                    };

                    db.ApplicationDocuments.Add(appDoc);
                    db.SaveChanges();


                    throughPutEntity.DocumentId      = docEntity.DocumentId;
                    throughPutEntity.Quantity        = throughPut.Quantity;
                    throughPutEntity.IPAddress       = throughPut.IPAddress;
                    db.Entry(throughPutEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(throughPutEntity.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
Ejemplo n.º 2
0
 public long UpdateThroughPut(ThroughPutObject throughPut)
 {
     try
     {
         return(_throughPutManager.UpdateThroughPut(throughPut));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
Ejemplo n.º 3
0
        public long UpdateThroughPut(ThroughPutObject throughPut)
        {
            try
            {
                if (throughPut == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (throughPut.DocumentObject != null && throughPut.DocumentObject.DocumentId > 0)
                    {
                        var documentEntities = db.Documents.Where(th => th.DocumentId == throughPut.DocumentObject.DocumentId).ToList();
                        if (!documentEntities.Any())
                        {
                            return(-2);
                        }

                        var documentEntity = documentEntities[0];
                        documentEntity.UploadedById    = throughPut.DocumentObject.UploadedById;
                        documentEntity.IpAddress       = throughPut.DocumentObject.IpAddress;
                        documentEntity.Status          = (int)AppStatus.Pending;
                        documentEntity.DateUploaded    = DateTime.Now;
                        documentEntity.DocumentPath    = throughPut.DocumentObject.DocumentPath;
                        db.Entry(documentEntity).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    var throughPutEntities = db.ThroughPuts.Where(th => th.Id == throughPut.Id).ToList();
                    if (!throughPutEntities.Any())
                    {
                        return(-2);
                    }

                    var throughPutEntity = throughPutEntities[0];
                    throughPutEntity.Quantity        = throughPut.Quantity;
                    throughPutEntity.IPAddress       = throughPut.IPAddress;
                    db.Entry(throughPutEntity).State = EntityState.Modified;
                    db.SaveChanges();

                    return(throughPutEntity.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
Ejemplo n.º 4
0
        public ActionResult AddThroughPutByDepotOwner(ThroughPutObject throughPut)
        {
            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));
                }

                if (throughPut == null)
                {
                    gVal.Error = "Invalid process call.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                if (throughPut.Quantity < 1)
                {
                    gVal.Error = "Please provide Quantity.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(throughPut.TempPath))
                {
                    gVal.Error = "Document processing failed. Please try again.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var path = MoveFile(importerInfo.Id, throughPut.TempPath);
                if (string.IsNullOrEmpty(path))
                {
                    gVal.Error = "Document processing failed. Please try again.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var ip  = ClientIpHelper.GetClientIpAddress(Request);
                var doc = new DocumentObject
                {
                    ImporterId     = importerInfo.Id,
                    DateUploaded   = DateTime.Now,
                    UploadedById   = importerInfo.UserProfileObject.Id,
                    DocumentPath   = path,
                    DocumentTypeId = (int)SpecialDocsEnum.Throughput_agreement,
                    Status         = (int)AppStatus.Pending,
                    IpAddress      = ip
                };

                throughPut.DocumentObject = doc;
                throughPut.IPAddress      = ip;
                var docStatus = new ThroughPutServices().AddThroughPut(throughPut);
                if (docStatus < 1)
                {
                    gVal.Error = "Process failed. Please try again.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = docStatus;
                gVal.Path  = path.Replace("~", string.Empty);
                gVal.Error = "Throughput information was successfully processed.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }

            catch (Exception)
            {
                gVal.Error = "ThroughPut processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
        public ActionResult EditThroughPut(HttpPostedFileBase file, long throughPutId, long documentId, double quantity)
        {
            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));
                }

                if (throughPutId < 1 || quantity < 1)
                {
                    gVal.Error = "Invalid process call.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var doc = new DocumentServices().GetDocument(documentId);
                if (doc.DocumentId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Document could not be processed. Please try again.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var ip   = ClientIpHelper.GetClientIpAddress(Request);
                var path = "";
                if (file != null && file.ContentLength > 0)
                {
                    path = SaveFile2(doc.DocumentPath, file, importerInfo.Id);
                    if (string.IsNullOrEmpty(path))
                    {
                        gVal.Code  = -1;
                        gVal.Error = "Document Could not be processed.";
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    doc.DocumentPath = path;
                    doc.UploadedById = importerInfo.UserProfileObject.Id;
                    doc.IpAddress    = ip;
                    doc.Status       = (int)AppStatus.Pending;
                    doc.DateUploaded = DateTime.Now;
                    doc.IpAddress    = ip;
                }

                var throughPut = new ThroughPutObject {
                    DocumentObject = doc, IPAddress = ip, Id = throughPutId, Quantity = quantity
                };

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

                gVal.Code              = docStatus;
                gVal.Error             = path;
                Session["_throughPut"] = null;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "ThroughPut information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 6
0
        public ActionResult AddThroughPutByApplicant(HttpPostedFileBase file, long throughPutId, double quantity)
        {
            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));
                }

                if (throughPutId < 1 || quantity < 1)
                {
                    gVal.Error = "Invalid process call.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }


                var path = SaveFile2("", file, importerInfo.Id);

                if (string.IsNullOrEmpty(path))
                {
                    gVal.Code  = -1;
                    gVal.Error = "Document information Could not be saved.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var ip  = ClientIpHelper.GetClientIpAddress(Request);
                var doc = new DocumentObject
                {
                    DateUploaded   = DateTime.Now,
                    UploadedById   = importerInfo.UserProfileObject.Id,
                    DocumentPath   = path,
                    DocumentTypeId = (int)SpecialDocsEnum.Throughput_agreement,
                    Status         = (int)AppStatus.Pending,
                    ImporterId     = importerInfo.Id,
                    IpAddress      = ip
                };

                var throughPut = new ThroughPutObject {
                    DocumentObject = doc, IPAddress = ip, Id = throughPutId, Quantity = quantity
                };

                var docStatus = new ThroughPutServices().AddThroughPut(throughPut);
                if (docStatus < 1)
                {
                    gVal.Error = "Process failed. Please try again.";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = docStatus;
                gVal.Error = path;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }

            catch (Exception)
            {
                gVal.Error = "ThroughPut processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }