public IHttpActionResult SaveShipmentDraftForm(DirectBookingShipmentDraftDetail directBookingDetail)
        {
            // Change the model
            var GetShipmentInEcommDraftModel = new DirectShipmentRepository().SaveDirectBooking(directBookingDetail);

            return(Ok(GetShipmentInEcommDraftModel));
        }
Esempio n. 2
0
        public void MappingExpressCourierPieceDetail(IntegrtaionResult integrtaionResult, int ExpressShipmentid)
        {
            if (ExpressShipmentid > 0)
            {
                List <int> _shiId = new List <int>();
                for (int i = 0; i < integrtaionResult.PieceTrackingDetails.Count; i++)
                {
                    _shiId = new DirectShipmentRepository().GetExpressDirectShipmentDetailID(ExpressShipmentid);

                    integrtaionResult.PieceTrackingDetails[i].DirectShipmentDetailId = _shiId[i];
                }
            }
        }
Esempio n. 3
0
        public void MappingCourierPieceDetail(IntegrtaionResult integrtaionResult, DirectBookingShipmentDraftDetail directBookingDetail, int DirectShipmentid)
        {
            if (DirectShipmentid > 0)
            {
                int        k = 0, i = 0;
                List <int> _shiId = new List <int>();

                _shiId = new DirectShipmentRepository().GetDirectShipmentDetailID(DirectShipmentid);
                for (i = 0; i < integrtaionResult.PieceTrackingDetails.Count(); i++)
                {
                    integrtaionResult.PieceTrackingDetails[i].DirectShipmentDetailId = _shiId[0];
                }
            }
        }
        public FrayteManifestName GenerateTrackAndTraceExcel(FrayteTrackDirectBooking trackdetail)
        {
            FrayteManifestName result = new FrayteManifestName();
            string             Name   = "";

            if (trackdetail.CustomerName == "ALL")
            {
                var OperationZone = UtilityRepository.GetOperationZone();
                if (OperationZone.OperationZoneId == 1)
                {
                    Name = "All_HK";
                }
                else if (OperationZone.OperationZoneId == 2)
                {
                    Name = "All_UK";
                }
            }
            else
            {
                Name = trackdetail.CustomerName;
            }
            try
            {
                var track = new DirectShipmentRepository().GetTrackAndTraceDetail(trackdetail);
                if (track != null && track.Count > 0)
                {
                    ReportTemplate.Other.TrackAndTraceReport rp = new ReportTemplate.Other.TrackAndTraceReport();
                    rp.DataSource = track;
                    if (File.Exists(HttpContext.Current.Server.MapPath(AppSettings.ReportFolder) + "/" + "Track&Trace" + "/" + Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx"))
                    {
                        File.Delete(HttpContext.Current.Server.MapPath(AppSettings.ReportFolder) + "/" + "Track&Trace" + "/" + Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx");
                        rp.ExportToXlsx(HttpContext.Current.Server.MapPath(AppSettings.ReportFolder) + "/" + "Track&Trace" + "/" + Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx");
                        result.FileName = Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx";
                        result.FilePath = AppSettings.WebApiPath + "ReportFiles/Track&Trace/" + Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx";
                    }
                    else
                    {
                        System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(AppSettings.ReportFolder + "/" + "Track&Trace" + "/"));
                        rp.ExportToXlsx(HttpContext.Current.Server.MapPath(AppSettings.ReportFolder) + "/" + "Track&Trace" + "/" + Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx");
                        result.FileName = Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx";
                        result.FilePath = AppSettings.WebApiPath + "ReportFiles/Track&Trace/" + Name + "_" + "Track_Trace_Detail" + "_" + DateTime.Now.ToString("dd_MM_yyyy") + ".xlsx";
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
Esempio n. 5
0
 public void MappingExpressCourierPieceDetail(IntegrtaionResult integrtaionResult, ExpressShipmentModel expessBookingDetail, int ExpressShipmentid)
 {
     if (ExpressShipmentid > 0)
     {
         int        k = 0, i = 0;
         List <int> _shiId = new List <int>();
         foreach (var Obj in expessBookingDetail.Packages)
         {
             _shiId = new DirectShipmentRepository().GetExpressDirectShipmentDetailID(ExpressShipmentid);
             for (int j = 1; j <= Obj.CartonValue; j++)
             {
                 integrtaionResult.PieceTrackingDetails[k].DirectShipmentDetailId = _shiId[i];
                 k++;
             }
             i++;
         }
     }
 }
 public void MappingCourierPieceDetail(IntegrtaionResult integrtaionResult, DirectBookingShipmentDraftDetail directBookingDetail, int DirectShipmentid)
 {
     if (DirectShipmentid > 0)
     {
         int        k = 0, i = 0;
         List <int> _shiId = new List <int>();
         foreach (var Obj in directBookingDetail.Packages)
         {
             _shiId = new DirectShipmentRepository().GetDirectShipmentDetailID(DirectShipmentid);
             for (int j = 1; j <= Obj.CartoonValue; j++)
             {
                 integrtaionResult.PieceTrackingDetails[k].DirectShipmentDetailId = _shiId[i];
                 k++;
             }
             i++;
         }
     }
 }
Esempio n. 7
0
        public FrayteManifestName CreateCommercialInvoce(int DirectShipmnetId, string CustomerName)
        {
            FrayteManifestName result = new FrayteManifestName();

            var detail = new DirectShipmentRepository().GetCommercilaInvoiceFileName(DirectShipmnetId);

            var invoice = new DirectShipmentRepository().CreateDirectBookingCommercialInvoice(DirectShipmnetId);

            if (invoice != null)
            {
                ReportTemplate.Other.CommercialInvoice cm = new ReportTemplate.Other.CommercialInvoice();
                cm.DataSource = invoice;
                cm.ExportToPdf(HttpContext.Current.Server.MapPath(AppSettings.ReportFolder) + detail.CompanyName + "-Commercial Invoice-" + detail.CreationDate.ToString("yyyy-dd-MM") + "-" + detail.LogisticType + " " + detail.RateType + "-AWB-" + detail.FrayetNo + ".pdf");
                result.FileName   = detail.CompanyName + "-Commercial Invoice-" + detail.CreationDate.ToString("yyyy-dd-MM") + "-" + detail.LogisticType + " " + detail.RateType + "-AWB-" + detail.FrayetNo + ".pdf";
                result.FilePath   = AppSettings.WebApiPath + "ReportFiles/" + detail.CompanyName + "-Commercial Invoice-" + detail.CreationDate.ToString("yyyy-dd-MM") + "-" + detail.LogisticType + " " + detail.RateType + "-AWB-" + detail.FrayetNo + ".pdf";
                result.FileStatus = true;
            }
            else
            {
                result.FileStatus = false;
            }
            return(result);
        }
        public IHttpActionResult UploadShipments(int CustomerId, string LogisticService, string ServiceType)
        {
            //int eCommerceShipmentId = 0;
            List <FrayteUploadshipment> frayteShipment = new List <FrayteUploadshipment>();
            FrayteResult result      = new FrayteResult();
            var          httpRequest = HttpContext.Current.Request;

            if (httpRequest.Files.Count > 0)
            {
                HttpFileCollection files = httpRequest.Files;

                HttpPostedFile file = files[0];

                FrayteSession s = new FrayteSession();
                var           a = s.EmployeeId;
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    string          connString = "";
                    OleDbConnection conn;
                    string          filename = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss_") + file.FileName;
                    string          filepath = HttpContext.Current.Server.MapPath("~/UploadFiles/Shipments/" + filename);
                    file.SaveAs(filepath);
                    connString = new DirectShipmentRepository().getExcelConnectionString(filename, filepath);
                    string fileExtension = "";
                    fileExtension = new DirectShipmentRepository().getFileExtensionString(filename);
                    try
                    {
                        if (!string.IsNullOrEmpty(fileExtension))
                        {
                            var ds = new DataSet();
                            if (fileExtension == FrayteFileExtension.CSV)
                            {
                                using (conn = new OleDbConnection(connString))
                                {
                                    conn.Open();
                                    var query = "SELECT * FROM [" + Path.GetFileName(filename) + "]";
                                    using (var adapter = new OleDbDataAdapter(query, conn))
                                    {
                                        adapter.Fill(ds, "Pieces");
                                    }
                                }
                            }
                            else
                            {
                                using (conn = new OleDbConnection(connString))
                                {
                                    conn.Open();
                                    DataTable dbSchema       = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                                    string    firstSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();
                                    var       query          = "SELECT * FROM " + "[" + firstSheetName + "]";//[Sheet1$]";
                                    using (var adapter = new OleDbDataAdapter(query, conn))
                                    {
                                        adapter.Fill(ds, "Pieces");
                                    }
                                }
                            }

                            var exceldata = ds.Tables[0];


                            if (exceldata != null)
                            {
                                var res = new DirectBookingUploadShipmentRepository().CheckValidWithServiceExcel(exceldata);

                                if (res)
                                {
                                    frayteShipment = new DirectBookingUploadShipmentRepository().GetAllShipments(exceldata, ServiceType, LogisticService);
                                    var flag = false;

                                    foreach (var shipment in frayteShipment)
                                    {
                                        shipment.CollectionTime = shipment.CollectionTime != "" ? new DirectBookingUploadShipmentRepository().ConvertStringToTime(shipment.CollectionTime) : "";
                                        shipment.CollectionDate = shipment.CollectionDate != "" ? new DirectBookingUploadShipmentRepository().ConvertStringToDate(shipment.CollectionDate) : "";
                                        var count       = 0;
                                        var packagelist = new List <UploadShipmentPackage>();
                                        var package     = new List <UploadShipmentPackage>();
                                        packagelist.AddRange(shipment.Package);
                                        shipment.Package.RemoveRange(0, shipment.Package.Count);
                                        foreach (var ship in packagelist)
                                        {
                                            if (ship.CartoonValue == 0 && ship.Content == "" && Convert.ToInt32(ship.Height) == 0 &&
                                                Convert.ToInt32(ship.Length) == 0 && Convert.ToInt32(ship.Value) == 0 &&
                                                Convert.ToInt32(ship.Weight) == 0 && Convert.ToInt32(ship.Width) == 0)
                                            {
                                                //shipment.Package.RemoveAt((packagelist.Count - 1) - count);
                                            }
                                            else
                                            {
                                                shipment.Package.Add(ship);
                                            }
                                            count++;
                                        }
                                    }

                                    // check the validation in the excel
                                    new DirectBookingUploadShipmentRepository().ErrorLog(frayteShipment, ServiceType);

                                    List <FrayteUploadshipment> FUS = new List <FrayteUploadshipment>();
                                    int count1 = 1;

                                    foreach (var shipment in frayteShipment)
                                    {
                                        shipment.ValidationErrors = new List <string>();
                                        if (shipment.ShipFrom.Country == null || (shipment.ShipFrom.Country != null && shipment.ShipFrom.Country.CountryId == 0))
                                        {
                                            shipment.ValidationErrors.Add("From Country is Missing in row " + count1);
                                            flag = true;
                                        }
                                        if (shipment.ShipTo.Country == null || (shipment.ShipTo.Country != null && shipment.ShipTo.Country.CountryId == 0))
                                        {
                                            shipment.ValidationErrors.Add("To Country is Missing in row " + count1);
                                            flag = true;
                                        }
                                        if (shipment.CurrencyCode == null || shipment.CurrencyCode == "")
                                        {
                                            shipment.ValidationErrors.Add("Currency is Missing in row " + count1);
                                            flag = true;
                                        }
                                        count1++;
                                    }
                                    var count2 = 0;
                                    foreach (var shipment in frayteShipment)
                                    {
                                        if (shipment.ValidationErrors.Count > 0)
                                        {
                                            count2++;
                                        }
                                    }
                                    var SessionId = 0;
                                    //if (frayteShipment.Count == count2)
                                    //{

                                    //}
                                    //else
                                    //{
                                    //    SessionId = new DirectBookingUploadShipmentRepository().SaveSession();
                                    //}
                                    //int Count = 1;
                                    //foreach (var shipment in frayteShipment)
                                    //{

                                    //    if (CustomerId > 0)
                                    //    {
                                    //        shipment.CustomerId = CustomerId;
                                    //        shipment.ShipmentStatusId = 14;
                                    //    }
                                    //    if (SessionId > 0)
                                    //    {
                                    //        shipment.SessionId = SessionId;
                                    //    }
                                    //    if (shipment.ValidationErrors.Count == 0 || (
                                    //        !shipment.ValidationErrors[shipment.ValidationErrors.Count - 1].Contains("Currency is Missing in row") &&
                                    //        !shipment.ValidationErrors[shipment.ValidationErrors.Count - 1].Contains("To Country is Missing in row") &&
                                    //        !shipment.ValidationErrors[shipment.ValidationErrors.Count - 1].Contains("From Country is Missing in row")))
                                    //    {
                                    //        result = new DirectBookingUploadShipmentRepository().SaveShipment(shipment, CustomerId, ServiceType);
                                    //    }
                                    //    if (shipment.Errors.Count == 0)
                                    //    {
                                    //        FUS.Add(shipment);
                                    //    }
                                    //    Count++;
                                    //}

                                    if (!flag)
                                    {
                                        SessionId = new DirectBookingUploadShipmentRepository().SaveSession(CustomerId);
                                        foreach (var shipment in frayteShipment)
                                        {
                                            if (CustomerId > 0)
                                            {
                                                shipment.CustomerId       = CustomerId;
                                                shipment.ShipmentStatusId = 14;
                                            }
                                            if (SessionId > 0)
                                            {
                                                shipment.SessionId = SessionId;
                                            }

                                            if (shipment.PackageCalculationType != null && shipment.PackageCalculationType != "" && shipment.PackageCalculationType.ToLower() == "kgtocms")
                                            {
                                                shipment.PackageCalculationType = "kgToCms";
                                            }
                                            else if (shipment.PackageCalculationType != null && shipment.PackageCalculationType != "" && shipment.PackageCalculationType.ToLower() == "lbtoinchs")
                                            {
                                                shipment.PackageCalculationType = "lbToInchs";
                                            }

                                            result = new DirectBookingUploadShipmentRepository().SaveShipment(shipment, CustomerId, ServiceType);
                                        }
                                    }
                                    else
                                    {
                                        return(BadRequest("from country or to country or shipmentcurrency name is missing"));
                                    }
                                    //var Unprocessedshipmentcount = frayteShipment.Count - FUS.Count;
                                    //new eCommerceUploadShipmentRepository().RemoveBatchProcessShipment(frayteShipment[0].CustomerId, frayteShipment.Count);
                                    //new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(Unprocessedshipmentcount, frayteShipment[0].CustomerId);
                                    //if (FUS.Count > 0)
                                    //{
                                    //    PlaceShipmentBatch(FUS);
                                    //}
                                }
                                else
                                {
                                    return(BadRequest("CSV file not valid, missing header name or may be wrong name"));
                                }
                            }
                            conn.Close();
                            if ((System.IO.File.Exists(filepath)))
                            {
                                System.IO.File.Delete(filepath);
                            }
                        }
                        else
                        {
                            //frayteShipmentDetailexcel.Message = "Excel file not valid";
                        }
                    }
                    catch (Exception ex)
                    {
                        return(BadRequest());
                    }
                    finally
                    {
                    }
                }
            }

            var aa = GetUnSuccessfulShipments(CustomerId);

            return(Ok(frayteShipment));
        }
        public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int> DBUploadShipmentParcelHubIntegration(FrayteUploadshipment res)
        {
            FrayteResult      FR     = new FrayteResult();
            IntegrtaionResult result = new IntegrtaionResult();
            var count               = 0;
            int DirectShipmentid    = 0;
            var directBookingDetail = new DirectBookingUploadShipmentRepository().DirectBookingObj(res);

            #region COLLECTION Date

            DateTime mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value;
            DateTime maxdatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);

            if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Sunday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Saturday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(2);
            }

            directBookingDetail.ReferenceDetail.CollectionDate = mindatetime;
            #endregion
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(directBookingDetail);

            // Parcelhub Integration starts
            //Step 2: Shipment Integrations
            #region Parcel Hub Integration

            //Map Direct Booking object with parcel hub objects
            Frayte.Services.Models.ParcelHub.ParcelHubShipmentRequest request = new ParcelHubRepository().MapDirectBookingDetailToShipmentRequest(directBookingDetail);

            //Create shipment in Parcel hub
            Frayte.Services.Models.ParcelHub.ParcelHubResponse response = new ParcelHubRepository().CreateShipment(request);

            if (response.Error.IsMailSend)
            {
                if (directBookingDetail.Error.IsMailSend)
                {
                    //Send error mail to developer
                    new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, response.Error);
                }
            }
            else
            {
                //Mapping ShipmentResonse to IntegrtaionResult
                result = new ParcelHubRepository().MappingParcelHubToIntegrationResult(directBookingDetail, response, null);

                if (result.Status)
                {
                    //Save Shipment Detail Into Our DB
                    DirectShipmentid = new DirectShipmentRepository().SaveShipment(directBookingDetail, result);
                    if (DirectShipmentid > 0)
                    {
                        var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, directBookingDetail.CustomerId);
                    }
                    //Mapping ShipmentResult to IntegrtaionResult
                    new ParcelHubRepository().MappingCourierPieceDetail(result, directBookingDetail, DirectShipmentid);

                    //Save Package Label Tracking detail
                    new ParcelHubRepository().SaveTrackingDetail(directBookingDetail, result, DirectShipmentid);

                    //Start downloading the images from UPS server and making PDF
                    FratyteError Error = new ParcelHubRepository().DownloadParcelHubPackageImage(directBookingDetail, result, DirectShipmentid);
                }
                else
                {
                    if (result.Error.IsMailSend)
                    {
                        new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, res.CustomerId);
                        //Send error mail to developer
                        new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, directBookingDetail.Error);
                    }
                }
            }


            #endregion

            return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
        }
        public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int> DBUploadShipmentDHLIntegration(FrayteUploadshipment res)
        {
            IntegrtaionResult result = new IntegrtaionResult();
            FrayteResult      FR     = new FrayteResult();
            //string xsUserFolder = @"C:\FMS\" + "FrayteSchedularlog.txt";
            string xsUserFolder = @"D:\ProjectFrayte\" + "FrayteScheduler.txt";

            BaseLog.Instance.SetLogFile(xsUserFolder);
            Logger _log                = Get_Log();
            int    DirectShipmentid    = 0;
            var    directBookingDetail = new DirectBookingUploadShipmentRepository().DirectBookingObj(res);

            #region COLLECTION Date

            DateTime mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value;
            DateTime maxdatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);

            if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Sunday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Saturday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(2);
            }

            directBookingDetail.ReferenceDetail.CollectionDate = mindatetime;
            #endregion
            _log.Error("Get direct Booking Object");
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(directBookingDetail);
            _log.Error("saved direct Booking Object");
            //step1. Mapping With directBookingDetail to ShipmentRequestDto
            var shipmentRequestDto = new DHLRepository().MapDirectBookingDetailToDHLShipmentRequestDto(directBookingDetail);

            //Step 2. Create Xml
            var shipmentXML = new DHLRepository().CreateXMLForDHL(shipmentRequestDto);
            _log.Error("done xml dhl shipment");
            _log.Error(shipmentXML);
            string xml_in = "";
            try
            {
                xml_in = File.ReadAllText(shipmentXML);
                //xml_in = File.ReadAllText(@"C:\FMS\app.godemowithus.com\WebApi\UploadFiles\PDFGenerator\HTMLFile\tempDHLShipment.xml");
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
                _log.Error(e.InnerException);
                _log.Error(e.StackTrace);
            }
            _log.Error("reading xml dhl shipment");
            //step 3. Create Shipment
            var DHLResponse = new DHLRepository().CreateShipment(xml_in, shipmentRequestDto);
            // _log.Error("done integration dhl shipment" + DHLResponse.Error.ErrorDescription.ToString());
            //step 4. Mapping ShipmentResonse to IntegrtaionResult
            result = new DHLRepository().MapDHLIntegrationResponse(DHLResponse);
            if (result.Status)
            {
                //step2. After Shipment Create need to save the information in database
                DirectShipmentid = new DirectShipmentRepository().SaveShipment(directBookingDetail, result);
                if (DirectShipmentid > 0)
                {
                    _log.Error("done save dhl shipment in db" + directBookingDetail.CustomerId);
                    var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, directBookingDetail.CustomerId);
                    _log.Error(Id.ToString());
                }
                _log.Error("done save dhl shipment in db");
                if (directBookingDetail.CustomerRateCard.CourierName == FrayteCourierCompany.DHL)
                {
                    //Step 1.1 Mapping ShipmentResult to IntegrtaionResult
                    new DHLRepository().MappingCourierPieceDetail(result, directBookingDetail, DirectShipmentid);
                }

                //Step3 : Save Package Label Tracking detail
                new DHLRepository().SaveTrackingDetail(directBookingDetail, result, DirectShipmentid);

                //Step4:  //Start downloading the images from UPS server and making PDF

                var count      = 1;
                var totalpiece = result.PieceTrackingDetails.Count();
                totalpiece = totalpiece - 1;
                foreach (var data in result.PieceTrackingDetails.Take(totalpiece))
                {
                    if (directBookingDetail.CustomerRateCard.CourierName == FrayteCourierCompany.DHL)
                    {
                        _log.Error("downloading shipment image");
                        //Step3.1
                        data.LabelName = new DHLRepository().DownloadDHLImage(data, totalpiece, count, DirectShipmentid);
                        _log.Error("downloaded shipment image");
                    }

                    //// Step3.2
                    //new DirectShipmentRepository().SavePackageDetail(data, result.CourierName);
                    //_log.Error("saved package detail shipment image");
                    if (!data.PieceTrackingNumber.Contains("AirwayBillNumber_"))
                    {
                        // Step3.2
                        new DirectShipmentRepository().SavePackageDetail(data, result.CourierName);
                    }
                    count++;
                }
                var CourierPieceDetail = result.PieceTrackingDetails.Where(t => t.PieceTrackingNumber.Contains("AirwayBillNumber_")).FirstOrDefault();
                if (CourierPieceDetail != null)
                {
                    var data1 = new DHLRepository().DownloadDHLImage(CourierPieceDetail, totalpiece, 0, DirectShipmentid);
                }
                if (result != null)
                {
                    directBookingDetail.Error        = new FratyteError();
                    directBookingDetail.Error.Status = result.Status;
                }

                return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
            }
            else
            {
                directBookingDetail.Error = result.Error;
                new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, directBookingDetail.CustomerId);
                //Send mail to developer
                new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, directBookingDetail.Error);
            }
            return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
        }
        public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int> DBUploadShipmentUpsIntegration(FrayteUploadshipment res)
        {
            FrayteResult FR               = new FrayteResult();
            var          count            = 0;
            int          DirectShipmentid = 0;

            var result1 = new DirectBookingUploadShipmentRepository().DirectBookingObj(res);

            #region COLLECTION Date

            DateTime mindatetime = result1.ReferenceDetail.CollectionDate.Value;
            DateTime maxdatetime = result1.ReferenceDetail.CollectionDate.Value.AddDays(1);

            if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Sunday)
            {
                mindatetime = result1.ReferenceDetail.CollectionDate.Value.AddDays(1);
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Saturday)
            {
                mindatetime = result1.ReferenceDetail.CollectionDate.Value.AddDays(2);
            }

            result1.ReferenceDetail.CollectionDate = mindatetime;
            #endregion
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(result1);

            //step1. Mapping With directBookingDetail to ShipmentRequestDto
            var shipmentRequestDto = new UPSRepository().MapDirectBookingDetailToShipmentRequestDto(result1);

            //Step2.Create Shipment
            var shipmentResult = new UPSRepository().CreateShipment(shipmentRequestDto, result1.ReferenceDetail);

            //step3 Mapping ShipmentResonse to IntegrtaionResult
            var result = new UPSRepository().MapUPSIntegrationResponse(shipmentResult);

            if (result.Status)
            {
                //step1. After Shipment Create need to save the information in database
                DirectShipmentid = new DirectShipmentRepository().SaveShipment(result1, result);
                if (DirectShipmentid > 0)
                {
                    var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, result1.CustomerId);
                }
                if (result.CourierName == FrayteCourierCompany.UPS)
                {
                    //Step 1.1 Mapping ShipmentResult to IntegrtaionResult
                    new UPSRepository().MappingCourierPieceDetail(result, result1, DirectShipmentid);
                }

                //Step2 : Save Package Label Tracking detail
                new UPSRepository().SaveTrackingDetail(result1, result, DirectShipmentid);

                //Step3:  //Start downloading the images from UPS server and making PDF
                count = 1;
                foreach (var data in result.PieceTrackingDetails)
                {
                    if (result.CourierName == FrayteCourierCompany.UPS)
                    {
                        //Step3.1
                        data.LabelName = new UPSRepository().DownloadUPSImage(data, result.PieceTrackingDetails.Count(), count, DirectShipmentid);
                    }

                    // Step3.2
                    new DirectShipmentRepository().SavePackageDetail(data, result.CourierName);
                    count++;
                }

                result1.Error = new FratyteError()
                {
                    Status = result.Status
                };
                FR.Status = true;
                //FrayteShipmentResponse = new APIShipmentRepository().MappingFrayteShipmentResponse(directBookingDetail, result, DirectShipmentid.ToString(), ratecard, Request.RateCardId);
            }
            else
            {
                FR.Status     = false;
                result1.Error = result.Error;
                new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, res.CustomerId);
                //Send mail to developer
                new ShipmentEmailRepository().SendShipmentErrorMail(result1, result1.Error);
            }
            return(Tuple.Create(FR, result1, DirectShipmentid));
        }
        public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int, TNTResponseDto, List <FraytePackageTrackingDetail> > DBUploadShipmentTNTIntegration(FrayteUploadshipment res)
        {
            FrayteResult FR               = new FrayteResult();
            var          count            = 0;
            int          DirectShipmentid = 0;
            //string xsUserFolder = @"C:\FMS\" + "FrayteSchedularlog.txt";
            string xsUserFolder = @"D:\ProjectFrayte\" + "FrayteScheduler.txt";

            BaseLog.Instance.SetLogFile(xsUserFolder);
            Logger _log = Get_Log();

            _log.Error("entered in else tnt");
            var directBookingDetail = new DirectBookingUploadShipmentRepository().DirectBookingObj(res);

            #region COLLECTION Date

            DateTime mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value;
            DateTime maxdatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);

            if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Sunday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Saturday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(2);
            }

            directBookingDetail.ReferenceDetail.CollectionDate = mindatetime;
            #endregion
            _log.Error("entered in else tnt1");
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(directBookingDetail);
            _log.Error("entered in else tnt2");
            var shipmentPackageTrackingDetail = new List <FraytePackageTrackingDetail>();
            // TNT Integration is for HK as we have account detail for HK only
            _log.Error("entered in else tnt3");
            var TNTObj = new TNTRepository().MapDirectBookingObjToTNTobj(directBookingDetail);
            _log.Error("entered in else tnt4");
            var TNTXml = new TNTRepository().CreateTNTXMl(TNTObj);
            _log.Error("entered in else tnt5");
            var TNTResponse = new TNTRepository().CreateShipment(TNTXml, directBookingDetail.DirectShipmentDraftId);
            _log.Error("entered in else tnt6");
            directBookingDetail.Error = TNTResponse.Error; //TNTIntegration(directBookingDetail, out DirectShipmentid);
            _log.Error("entered in else tnt7");
            if (directBookingDetail.Error != null && directBookingDetail.Error.Status == true)
            {
                //Finally Save the Order Id too to get the information of multiple shpment in Tracking Detail page.
                DirectShipmentid = new DirectShipmentRepository().SaveShipment(directBookingDetail, TNTResponse.TNTShipmentResponse.TrackingCode, directBookingDetail.CustomerId, null, null);
                if (DirectShipmentid > 0)
                {
                    var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, directBookingDetail.CustomerId);
                }
                // save tracking code
                int increment = 0;
                foreach (var package in directBookingDetail.Packages)
                {
                    var trackingDetail = new DirectShipmentRepository().SaveTNTTrackingDeatil(TNTResponse.TNTShipmentResponse.TrackingCode, DirectShipmentid, increment);
                    if (trackingDetail != null)
                    {
                        foreach (var data in trackingDetail)
                        {
                            shipmentPackageTrackingDetail.Add(data);
                        }
                    }
                    increment++;
                }

                if (directBookingDetail != null)
                {
                    directBookingDetail.Error        = new FratyteError();
                    directBookingDetail.Error.Status = directBookingDetail.Error.Status;
                }
            }
            else
            {
                new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, res.CustomerId);
            }


            return(Tuple.Create(FR, directBookingDetail, DirectShipmentid, TNTResponse, shipmentPackageTrackingDetail));
        }
Esempio n. 13
0
        public FrayteCustomerAddressBookExcel UploadAddressBookExcel(int CustomerId)
        {
            FrayteCustomerAddressBookExcel frayteAddressBookexcel = new FrayteCustomerAddressBookExcel();

            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Files.Count > 0)
            {
                HttpFileCollection files = httpRequest.Files;

                HttpPostedFile file = files[0];

                if (!string.IsNullOrEmpty(file.FileName))
                {
                    string connString = "";
                    string filename   = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss_") + file.FileName;
                    string filepath   = HttpContext.Current.Server.MapPath("~/UploadFiles/" + filename);

                    file.SaveAs(filepath);

                    connString = new ShipmentRepository().getExcelConnectionString(filename, filepath);
                    string fileExtension = new DirectShipmentRepository().getFileExtensionString(filename);

                    if (!string.IsNullOrEmpty(fileExtension))
                    {
                        OleDbConnection oledbConn = new OleDbConnection(connString);
                        try
                        {
                            DataSet ds = new DataSet();
                            if (fileExtension == FrayteFileExtension.CSV)
                            {
                                oledbConn.Open();
                                OleDbCommand     cmd   = new OleDbCommand("SELECT * FROM [" + Path.GetFileName(filename) + "]", oledbConn);
                                OleDbDataAdapter oleda = new OleDbDataAdapter();
                                oleda.SelectCommand = cmd;
                                oleda.Fill(ds, "AddressBook");
                            }
                            else
                            {
                                oledbConn.Open();
                                DataTable dbSchema       = oledbConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                                string    firstSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();
                                var       query          = "SELECT * FROM " + "[" + firstSheetName + "]";
                                using (var adapter = new OleDbDataAdapter(query, oledbConn))
                                {
                                    adapter.Fill(ds, "AddressBook");
                                }
                            }

                            var exceldata = ds.Tables[0];

                            string AddressBookColumn = "FirstName,LastName,CompanyName,Email,PhoneNo,Address1,Area,Address2,City,State,Zip,CountryName";
                            bool   IsExcelValid      = new CustomerRepository().CheckUploadExcelColumns(AddressBookColumn, exceldata);
                            if (!IsExcelValid)
                            {
                                frayteAddressBookexcel.Status    = false;
                                frayteAddressBookexcel.RowErrors = new List <string>();
                                frayteAddressBookexcel.RowErrors.Add("Columns are not matching with provided template columns. Please check the column names.");
                                return(frayteAddressBookexcel);
                            }
                            else
                            {
                                if (exceldata != null && exceldata.Rows.Count > 0)
                                {
                                    List <string> _errorrows = new List <string>();
                                    List <FrayteCustomerAddressBook> _addressbook = new CustomerRepository().GetAddressBookDetail(CustomerId, exceldata, ref _errorrows);
                                    if (_errorrows.Count > 0)
                                    {
                                        frayteAddressBookexcel.Status    = false;
                                        frayteAddressBookexcel.RowErrors = new List <string>();
                                        frayteAddressBookexcel.RowErrors = _errorrows;
                                        return(frayteAddressBookexcel);
                                    }
                                    else
                                    {
                                        List <string> _lengtherror = new CustomerRepository().ValidateAddressBookDataLength(_addressbook);
                                        if (_lengtherror.Count > 0)
                                        {
                                            frayteAddressBookexcel.Status    = false;
                                            frayteAddressBookexcel.RowErrors = new List <string>();
                                            frayteAddressBookexcel.RowErrors = _lengtherror;
                                            return(frayteAddressBookexcel);
                                        }
                                        else
                                        {
                                            bool IsInserted = new CustomerRepository().InsertCustomerAddressBook(_addressbook);
                                            if (!IsInserted)
                                            {
                                                frayteAddressBookexcel.Status    = false;
                                                frayteAddressBookexcel.RowErrors = new List <string>();
                                                frayteAddressBookexcel.RowErrors.Add("Address Book Can Not Save");
                                                return(frayteAddressBookexcel);
                                            }
                                            else
                                            {
                                                frayteAddressBookexcel.Status = true;
                                                return(frayteAddressBookexcel);
                                            }
                                        }
                                    }
                                }
                                oledbConn.Close();
                                if ((System.IO.File.Exists(filepath)))
                                {
                                    System.IO.File.Delete(filepath);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            oledbConn.Close();
                            if ((System.IO.File.Exists(filepath)))
                            {
                                System.IO.File.Delete(filepath);
                            }
                        }
                    }
                }
            }
            return(frayteAddressBookexcel);
        }
        public TradelanePackageDetailExcel GetPiecesDetailFromExcel()
        {
            TradelanePackageDetailExcel frayteShipmentDetailexcel = new TradelanePackageDetailExcel();
            var httpRequest = HttpContext.Current.Request;

            List <TradelanePackage> _shipmentdetail = new List <TradelanePackage>();

            if (httpRequest.Files.Count > 0)
            {
                HttpFileCollection files = httpRequest.Files;
                HttpPostedFile     file  = files[0];
                int ShipmentId           = Convert.ToInt32(httpRequest.Form["ShipmentId"].ToString());

                if (!string.IsNullOrEmpty(file.FileName))
                {
                    //int ShipmentId = Convert.ToInt32(httpRequest.Form["ShipmentId"].ToString());
                    string connString = "";
                    string filename   = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss_") + file.FileName;
                    string filepath   = HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + filename);
                    file.SaveAs(filepath);
                    connString = new DirectShipmentRepository().getExcelConnectionString(filename, filepath);

                    string fileExtension = "";
                    fileExtension = new DirectShipmentRepository().getFileExtensionString(filename);
                    try
                    {
                        if (!string.IsNullOrEmpty(fileExtension))
                        {
                            var ds = new DataSet();
                            if (fileExtension == FrayteFileExtension.CSV)
                            {
                                using (var conn = new OleDbConnection(connString))
                                {
                                    conn.Open();
                                    var query = "SELECT * FROM [" + Path.GetFileName(filename) + "]";
                                    using (var adapter = new OleDbDataAdapter(query, conn))
                                    {
                                        adapter.Fill(ds, "Pieces");
                                    }
                                }
                            }
                            else
                            {
                                var excel        = new ExcelQueryFactory("excelFileName");
                                var oldCompanies = (from c in excel.Worksheet <TradelanePackage>("sheet1")
                                                    select c);

                                using (var conn = new OleDbConnection(connString))
                                {
                                    conn.Open();
                                    DataTable dbSchema       = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                                    string    firstSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();
                                    var       query          = "SELECT * FROM " + "[" + firstSheetName + "]";
                                    using (var adapter = new OleDbDataAdapter(query, conn))
                                    {
                                        adapter.Fill(ds, "Pieces");
                                    }
                                }
                            }

                            var exceldata = ds.Tables[0];

                            // Step 1: Validate for excel column

                            string PiecesColumnList = "CartonNumber,CartonQTY,Length,Width,Height,Weight";
                            bool   IsExcelValid     = UtilityRepository.CheckUploadExcelFormat(PiecesColumnList, exceldata);
                            if (!IsExcelValid)
                            {
                                frayteShipmentDetailexcel.Message = "Columns are not matching with provided template columns. Please check the column names.";
                            }
                            else
                            {
                                if (exceldata.Rows.Count > 0)
                                {
                                    frayteShipmentDetailexcel.TotalUploaded = exceldata.Rows.Count;
                                    _shipmentdetail = new TradelaneBookingRepository().GetPiecesDetail(exceldata);
                                    frayteShipmentDetailexcel.Packages        = new List <TradelanePackage>();
                                    frayteShipmentDetailexcel.Packages        = _shipmentdetail;
                                    frayteShipmentDetailexcel.Message         = "OK";
                                    frayteShipmentDetailexcel.SuccessUploaded = _shipmentdetail.Count;
                                    new TradelaneBookingRepository().SavePackagedetailShipment(frayteShipmentDetailexcel.Packages, ShipmentId);
                                }
                                else
                                {
                                    frayteShipmentDetailexcel.Message = "No records found.";
                                }
                            }
                            if ((System.IO.File.Exists(filepath)))
                            {
                                System.IO.File.Delete(filepath);
                            }
                        }
                        else
                        {
                            frayteShipmentDetailexcel.Message = "Excel file not valid";
                        }
                    }
                    catch (Exception ex)
                    {
                        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                        if (ex != null && !string.IsNullOrEmpty(ex.Message) && ex.Message.Contains("Sheet1$"))
                        {
                            frayteShipmentDetailexcel.Message = "Sheet name is invalid.";
                        }
                        else
                        {
                            frayteShipmentDetailexcel.Message = "Error while uploading the excel.";
                        }
                        return(frayteShipmentDetailexcel);
                    }
                }
            }
            return(frayteShipmentDetailexcel);
        }
Esempio n. 15
0
        public FrayteManifestExcel GetManifestDetailFromExcel()
        {
            FrayteManifestExcel frayteManifestDetailexcel = new Services.Models.FrayteManifestExcel();

            //var httpRequest = HttpContext.Current.Request;

            List <Frayte.Services.Models.FrayteManifestOnExcel> _Manifestdetail = new List <Frayte.Services.Models.FrayteManifestOnExcel>();
            //Frayte.Services.Models.FrayteManifestOnExcel frayteManifestDetailexcel;



            //int ShipmentId = Convert.ToInt32(httpRequest.Form["ShipmentId"].ToString());
            string connString = "";
            //string filename = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss_") + file.FileName;
            //var filepath = HttpContext.Current.Server.MapPath(Utility.AppSettings.ManifestFolder);
            //var FilePaths = Directory.EnumerateFiles(Utility.AppSettings.ManifestFolder);
            var filePaths = Directory.GetFiles(Utility.AppSettings.ManifestFolder);


            foreach (var file in filePaths)
            {
                //StreamReader reader = new StreamReader(File.OpenRead(file));
                //List<string> listA = new List<String>();
                //List<string> listB = new List<String>();
                //List<string> listC = new List<String>();
                //List<string> listD = new List<String>();
                ////string vara1, vara2, vara3, vara4;
                //while (!reader.EndOfStream)
                //{
                //    string line = reader.ReadLine();
                //    if (!String.IsNullOrWhiteSpace(line))
                //    {
                //        string[] values = line.Split(',');
                //        if (values.Length >= 3)
                //        {
                //            listA.Add(values[0]);
                //            listB.Add(values[1]);
                //            listC.Add(values[2]);
                //            //listD.Add(values[3]);
                //        }
                //    }
                //}
                //string[] firstlistA = listA.ToArray();
                //string[] firstlistB = listB.ToArray();
                //string[] firstlistC = listC.ToArray();
                //string[] firstlistD = listD.ToArray();

                //file.Normalize();
                //string contents = File.ReadAllText(file);
                var filepath = file;
                var filelen  = file.Length - 15;
                //var sublenget = filelen5;
                //string filename = file.Substring(filelen, 15);
                var filePathLength = file.Length;
                var FileName       = file.Split('\\');
                var FileNameLength = FileName.Length;
                var filename       = FileName[FileNameLength - 1];
                //StreamReader sr = new StreamReader(filepath);
                //string Fulltext = sr.ReadToEnd();
                //string filename = "MNUKCUS0006";
                connString = new DirectShipmentRepository().getExcelConnectionString(filename, filepath);
                string fileExtension = "";
                fileExtension = new DirectShipmentRepository().getFileExtensionString(filename);
                try
                {
                    if (!string.IsNullOrEmpty(fileExtension))
                    {
                        var ds = new DataSet();
                        if (fileExtension == FrayteFileExtension.CSV)
                        {
                            try
                            {
                                using (var conn = new OleDbConnection(connString))
                                {
                                    conn.Open();
                                    var query = "SELECT * FROM [" + Path.GetFileName(filename) + "]";
                                    using (var adapter = new OleDbDataAdapter(query, conn))
                                    {
                                        adapter.Fill(ds, "CustomManifest");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else
                        {
                            using (var conn = new OleDbConnection(connString))
                            {
                                conn.Open();
                                DataTable dbSchema       = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                                string    firstSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();
                                var       query          = "SELECT * FROM " + "[" + firstSheetName + "]";//[Sheet1$]";
                                using (var adapter = new OleDbDataAdapter(query, conn))
                                {
                                    adapter.Fill(ds, "CustomManifest");
                                }
                            }
                        }



                        if (ds.Tables.Count > 0)
                        {
                            var    exceldata        = ds.Tables[0];
                            string PiecesColumnList = "CustomCommoditymap,CustomsEntryType,CustomsTotalValue,CustomsTotalVat,CustomsDuty";
                            //bool IsExcelValid = UtilityRepository.CheckUploadExcelFormat(PiecesColumnList, exceldata);
                            bool IsExcelValid = true;
                            if (!IsExcelValid)
                            {
                                frayteManifestDetailexcel.Message = "Columns are not matching with provided template columns. Please check the column names.";
                            }
                            else
                            {
                                if (exceldata.Rows.Count > 0)
                                {
                                    _Manifestdetail = new eCommerceShipmentRepository().SaveCustomManifestDetail(exceldata);
                                    frayteManifestDetailexcel.FrayteManifestDetail = new List <Frayte.Services.Models.FrayteManifestOnExcel>();
                                    frayteManifestDetailexcel.FrayteManifestDetail = _Manifestdetail;
                                    frayteManifestDetailexcel.Message = "OK";
                                }

                                else
                                {
                                    frayteManifestDetailexcel.Message = "No records found.";
                                }
                            }
                        }
                    }
                    else
                    {
                        frayteManifestDetailexcel.Message = "Excel file not valid";
                    }
                }
                catch (Exception ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                    if (ex != null && !string.IsNullOrEmpty(ex.Message) && ex.Message.Contains("Sheet1$"))
                    {
                        frayteManifestDetailexcel.Message = "Sheet name is invalid.";
                    }
                    else
                    {
                        frayteManifestDetailexcel.Message = "Error while uploading the excel.";
                    }
                    return(frayteManifestDetailexcel);
                }
            }

            return(frayteManifestDetailexcel);
        }