예제 #1
0
        public bool SaveFleet(Fleet Fleet, IList <Document> Documents, string CallType)
        {
            string documentXml       = string.Empty;
            string exceptionMessages = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(Fleet.FleetID))
                {
                    exceptionMessages = "FleetID is missing";
                }

                if (string.IsNullOrEmpty(Fleet.CompanyAddressID.ToString()))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Branch ID is missing" : exceptionMessages + ", " + "Branch ID is missing";
                }

                if (string.IsNullOrEmpty(Fleet.Make))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Make is missing" : exceptionMessages + ", " + "Make is missing";
                }
                if (string.IsNullOrEmpty(Fleet.Model))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Model is missing" : exceptionMessages + ", " + "Model is missing";
                }
                if (string.IsNullOrEmpty(Fleet.ModelYear.ToString()))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "ModelYear is missing" : exceptionMessages + ", " + "ModelYear is missing";
                }
                if (string.IsNullOrEmpty(Fleet.Colour))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Colour is missing" : exceptionMessages + ", " + "Colour is missing";
                }
                if (string.IsNullOrEmpty(Fleet.StartingMileage.ToString()))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "StartingMileage is missing" : exceptionMessages + ", " + "StartingMileage is missing";
                }
                if (string.IsNullOrEmpty(Fleet.Payload))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Payload is missing" : exceptionMessages + ", " + "Payload is missing";
                }
                if (string.IsNullOrEmpty(Fleet.OwnerShipType))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OwnerShipType is missing" : exceptionMessages + ", " + "OwnerShipType is missing";
                }
                if (string.IsNullOrEmpty(Fleet.OverallLength))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OverallLength is missing" : exceptionMessages + ", " + "OverallLength is missing";
                }
                if (string.IsNullOrEmpty(Fleet.OverallWidth))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OverallWidth is missing" : exceptionMessages + ", " + "OverallWidth is missing";
                }
                if (string.IsNullOrEmpty(Fleet.OverallHeight))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OverallHeight is missing" : exceptionMessages + ", " + "OverallHeight is missing";
                }

                if (!string.IsNullOrEmpty(exceptionMessages))
                {
                    throw new Exception(exceptionMessages);
                }

                if (CallType == "Portal")
                {
                    if (Documents != null && Documents.Count > 0)
                    {
                        documentXml = Documents.ConvertToXmlWithoutNamespaces <Document>();
                    }
                    return(_userDataAccess.SaveFleet(Fleet, documentXml));
                }
                if (CallType != "Portal")
                {
                    if (Documents != null && Documents.Count > 0)
                    {
                        documentXml = Documents.ConvertToXmlWithoutNamespaces <Document>();
                    }
                    return(_userDataAccess.SaveFleet(Fleet, documentXml));
                }
                return(false);
            }
            catch (Exception ex)
            {
                string eFileName;
                string errorFileName;

                eFileName     = "VehicleError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "VehileFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                if (!string.IsNullOrEmpty(fileName))
                {
                    fileName = fileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");
                    if (string.IsNullOrEmpty(Fleet.FleetID))
                    {
                        Fleet.FleetID = "Empty";
                    }

                    var v = FileManager.FileErrorLog(filePath, ex.Message, Fleet.FleetID);

                    eloggerDataAccess.LogFileImport(fileName, "IMP_FL_FLD", null, null, errorFileName, ImportFileHistoryID);
                }
                return(false);
            }
        }
예제 #2
0
        public bool SaveUser(LogistikaUser User, IList <Document> Documents)
        {
            string exceptionMessages = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(User.BranchId))
                {
                    exceptionMessages = "BranchId is missing";
                }

                if (string.IsNullOrEmpty(User.FirstName))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "First Name is missing" : exceptionMessages + ", " + "First Name is missing";
                }

                if (string.IsNullOrEmpty(User.LastName))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Last Name is missing" : exceptionMessages + ", " + "Last Name is missing";
                }

                if (User.DateOfBirth == null)
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Date Of Birth is missing" : exceptionMessages + ", " + "Date Of Birth is missing";
                }

                if (string.IsNullOrEmpty(User.Designation))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Employee Role is missing" : exceptionMessages + ", " + "Employee Role is missing";
                }

                if (string.IsNullOrEmpty(User.JobTitle))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Employee Title is missing" : exceptionMessages + ", " + "Employee Title is missing";
                }

                if (string.IsNullOrEmpty(User.Contact.Email))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Primary Email is missing" : exceptionMessages + ", " + "Primary Email is missing";
                }

                if (string.IsNullOrEmpty(User.Password))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Password is missing" : exceptionMessages + ", " + "Password is missing";
                }

                if (string.IsNullOrEmpty(User.Gender))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Gender is missing" : exceptionMessages + ", " + "Gender is missing";
                }

                if (string.IsNullOrEmpty(User.Addresses.FirstOrDefault().AddressLine1))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "AddressLine1 is missing" : exceptionMessages + ", " + "AddressLine1 is missing";
                }

                if (string.IsNullOrEmpty(User.Addresses.FirstOrDefault().Suite))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "House Number/Flat is missing" : exceptionMessages + ", " + "House Number/Flat is missing";
                }

                if (string.IsNullOrEmpty(User.Addresses.FirstOrDefault().City))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "City is missing" : exceptionMessages + ", " + "City is missing";
                }

                if (string.IsNullOrEmpty(User.Addresses.FirstOrDefault().StateCode))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "StateCode is missing" : exceptionMessages + ", " + "StateCode is missing";
                }

                if (string.IsNullOrEmpty(User.Addresses.FirstOrDefault().PostalCode))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "PostalCode is missing" : exceptionMessages + ", " + "PostalCode is missing";
                }

                if (string.IsNullOrEmpty(User.Contact.Phone))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Phone is missing" : exceptionMessages + ", " + "Phone is missing";
                }

                if (string.IsNullOrEmpty(User.Contact.Mobile))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Mobile phone is missing" : exceptionMessages + ", " + "Mobile phone is missing";
                }

                if ((string.IsNullOrEmpty(User.OtherInfo.TryGet("LicenseNumber")) || string.IsNullOrEmpty(User.OtherInfo.TryGet("LicenseClass"))) && (User.Designation == "USR_DRV" || User.Designation == "Driver"))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "License Number and License Class is required" : exceptionMessages + ", " + "License Number and License Class is required";
                }


                if ((string.IsNullOrEmpty(User.OtherInfo.TryGet("Experience")) || string.IsNullOrEmpty(User.OtherInfo.TryGet("MonthlyWage"))))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Experience and MonthlyWage is required" : exceptionMessages + ", " + "Experience and MonthlyWage is required";
                }

                if (User.StartDate == null)
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "StartDate is required" : exceptionMessages + ", " + "StartDate is required";
                }

                if (!string.IsNullOrEmpty(exceptionMessages))
                {
                    throw new Exception(exceptionMessages);
                }

                string documentXml = string.Empty;
                if (Documents != null && Documents.Count > 0)
                {
                    var r = Documents.Where(x => x.DocumentType.ToLower() == "photo").FirstOrDefault();
                    if (r != null)
                    {
                        User.Photo = r.DocumentUrl;
                        Documents.Remove(r);
                    }
                    documentXml = Documents.ConvertToXmlWithoutNamespaces <Document>();
                }
                return(_userDataAccess.SaveUser(User, documentXml));
            }
            catch (Exception ex)
            {
                string eFileName;
                string errorFileName;

                eFileName     = "UserError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "DriverFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                if (!string.IsNullOrEmpty(fileName))
                {
                    fileName = fileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");
                    if (string.IsNullOrEmpty(User.Contact.Email))
                    {
                        User.Contact.Email = "Empty";
                    }
                    var v = FileManager.FileErrorLog(filePath, ex.Message, User.Contact.Email);
                    eloggerDataAccess.LogFileImport(fileName, "IMP_FL_FLD", null, null, errorFileName, ImportFileHistoryID);
                }
                return(false);
            }
        }
예제 #3
0
        //public string LogFileImport(string FileName, string Status, string ValidRecords, string InValidRecords, string ErrorFileName, string ImportFileHistory_PK)
        //{
        //    return _userDataAccess.LogFileImport(FileName, Status, ValidRecords, InValidRecords, ErrorFileName, ImportFileHistory_PK);
        //}

        public string UserFileImport(string FileName, string CallType)
        {
            int ValidRecords   = 0;
            int InValidRecords = 0;

            try
            {
                accessfileName = FileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");
                fileName       = ClaimHelper.CompanyId + "_" + FileName;
                FileName       = fileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");

                string logImport         = null;
                bool   UserResult        = false;
                string rootFolderPath    = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + "driverFile\\";
                string destinationPath   = rootFolderPath + "\\Archive\\";
                string fullPathToExcel   = rootFolderPath + accessfileName;
                string fullpathToArchive = destinationPath + accessfileName;

                LoggerDataAccess loggerDataAccess = new LoggerDataAccess();

                logImport           = loggerDataAccess.LogFileImport(FileName, "IMP_FL_INITIATED", ValidRecords.ToString(), InValidRecords.ToString(), null, null);
                ImportFileHistoryID = logImport;

                if (logImport == "File is already processed.")
                {
                    return("File is already processed.");
                }

                if (string.IsNullOrEmpty(logImport))
                {
                    throw new Exception("Invalid response from Log File Import.");
                }

                if (new FileInfo(fullpathToArchive).Exists == false)
                {
                    string    connString = string.Format("Provider =Microsoft.ACE.OLEDB.12.0;Data Source=" + fullPathToExcel + ";Extended Properties='Excel 12.0;HDR=yes'", fullPathToExcel);
                    DataTable dt         = FileManager.GetDataTable("SELECT * FROM [Sheet1$]", connString);

                    Thread.CurrentThread.CurrentCulture =
                        CultureInfo.CreateSpecificCulture("en-GB");
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

                    var date = DateTime.Now;

                    IList <Country> PhoneCode = null;

                    if (CallType == "User")
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            try
                            {
                                LogistikaUser User = new LogistikaUser()
                                {
                                    BranchId    = dt.Rows[i]["BranchId"].ToString(),
                                    FirstName   = dt.Rows[i]["FirstName"].ToString(),
                                    MiddleName  = dt.Rows[i]["MiddleName"].ToString(),
                                    LastName    = dt.Rows[i]["LastName"].ToString(),
                                    DateOfBirth = Convert.ToDateTime(dt.Rows[i]["DateOfBirth"].ToString()),
                                    Designation = dt.Rows[i]["EmployeeRole"].ToString(),
                                    JobTitle    = dt.Rows[i]["EmployeeTitle"].ToString(),
                                    Contact     = new Contact()
                                    {
                                        Email  = dt.Rows[i]["PrimaryEmail"].ToString(),
                                        Phone  = dt.Rows[i]["Phone"].ToString(),
                                        Mobile = dt.Rows[i]["MobileNo"].ToString(),
                                    },
                                    Password  = dt.Rows[i]["Password"].ToString(),
                                    Gender    = dt.Rows[i]["Gender"].ToString(),
                                    OtherInfo = new List <DropdownData>
                                    {
                                        new DropdownData()
                                        {
                                            Text  = "LicenseNumber",
                                            Value = dt.Rows[i]["LicenseNumber"].ToString(),
                                        },
                                        new DropdownData()
                                        {
                                            Text  = "LicenceClass",
                                            Value = dt.Rows[i]["LicenceClass"].ToString(),
                                        },
                                        new DropdownData()
                                        {
                                            Text  = "Experience",
                                            Value = dt.Rows[i]["Experience"].ToString(),
                                        },
                                        new DropdownData()
                                        {
                                            Text  = "MonthlyWage",
                                            Value = dt.Rows[i]["MonthlyWage"].ToString(),
                                        }
                                    },
                                    StartDate = Convert.ToDateTime(dt.Rows[i]["StartDate"].ToString()),
                                    EndDate   = Convert.ToDateTime(dt.Rows[i]["EndDate"].ToString()),
                                    Active    = Convert.ToBoolean(dt.Rows[i]["IsActive"].ToString()),
                                    Addresses = new List <Address>
                                    {
                                        new Address()
                                        {
                                            AddressLine1 = dt.Rows[i]["AddressLine1"].ToString(),
                                            Suite        = dt.Rows[i]["SuiteNo"].ToString(),
                                            Locality     = dt.Rows[i]["Locality"].ToString(),
                                            City         = dt.Rows[i]["City"].ToString(),
                                            StateCode    = dt.Rows[i]["State"].ToString(),
                                            PostalCode   = dt.Rows[i]["PinCode"].ToString(),
                                            CountryCode  = dt.Rows[i]["CountryCode"].ToString(),
                                            LandMark     = dt.Rows[i]["LandMark"].ToString()
                                        }
                                    }
                                };

                                PhoneCode = _userDataAccess.GetCountryInfo(dt.Rows[i]["CountryCode"].ToString());

                                if (User.Contact.Mobile.StartsWith("0"))
                                {
                                    User.Contact.Mobile = User.Contact.Mobile.TrimStart('0');
                                    User.Contact.Mobile = PhoneCode[0].PhoneCode + User.Contact.Mobile;
                                }
                                else if (!User.Contact.Mobile.StartsWith("0"))
                                {
                                    User.Contact.Mobile = PhoneCode[0].PhoneCode + User.Contact.Mobile;
                                }
                                if (User.Contact.Phone.StartsWith("0"))
                                {
                                    User.Contact.Phone = User.Contact.Phone.TrimStart('0');
                                    User.Contact.Phone = PhoneCode[0].PhoneCode + User.Contact.Phone;
                                }
                                else if (!User.Contact.Phone.StartsWith("0"))
                                {
                                    User.Contact.Phone = PhoneCode[0].PhoneCode + User.Contact.Phone;
                                }

                                UserResult = SaveUser(User, null);
                                //var service = new UserBusinessComponent(new UserDataAccess());
                                if (UserResult)
                                {
                                    ValidRecords = ValidRecords + 1;
                                }
                                if (!UserResult)
                                {
                                    InValidRecords = InValidRecords + 1;
                                }
                            }
                            catch (Exception ex)
                            {
                                logImport = loggerDataAccess.LogFileImport(FileName, "IMP_FL_FLD", ValidRecords.ToString(), InValidRecords.ToString(), ex.Message, ImportFileHistoryID);
                                return(ex.Message);
                            }
                        }
                    }
                    //Console.ReadLine();

                    string[] fileList = Directory.GetFiles(rootFolderPath, FileName);

                    if (Directory.Exists(rootFolderPath))
                    {
                        foreach (string file in fileList)
                        {
                            FileInfo mFile = new FileInfo(file);
                            if (new FileInfo(destinationPath + "\\" + mFile.Name).Exists == false)
                            {
                                mFile.MoveTo(destinationPath + "\\" + mFile.Name);
                            }
                        }
                    }
                }
                else if (new FileInfo(fullpathToArchive).Exists == true)
                {
                    return("File is already processed");
                }
                if (UserResult)
                {
                    logImport = loggerDataAccess.LogFileImport(FileName, "IMP_FL_SCCS", ValidRecords.ToString(), InValidRecords.ToString(), null, ImportFileHistoryID);
                    return(FileName + ":- File imported successully.");
                }
                string eFileName;
                string errorFileName;

                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                eFileName     = "UserError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "DriverFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                var v = FileManager.FileErrorLog(filePath, "Incorrect File Layout/User already exists", "Error while processing file");

                logImport = loggerDataAccess.LogFileImport(FileName, "IMP_FL_FLD", ValidRecords.ToString(), InValidRecords.ToString(), errorFileName, ImportFileHistoryID);
                return(FileName + ":- File import Failed.");
            }
            catch (Exception ex)
            {
                string eFileName;
                string errorFileName;

                eFileName     = "UserError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "DriverFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                if (!string.IsNullOrEmpty(fileName))
                {
                    var v = FileManager.FileErrorLog(filePath, ex.Message, "Error with File");
                    eloggerDataAccess.LogFileImport(FileName, "IMP_FL_FLD", ValidRecords.ToString(), InValidRecords.ToString(), errorFileName, ImportFileHistoryID);
                }
                return(FileName + ":- File import Failed.");
            }
        }
예제 #4
0
        public string FleetFileImport(string FileName, string CallType)
        {
            int ValidRecords   = 0;
            int InValidRecords = 0;

            try
            {
                accessfileName = FileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");
                fileName       = ClaimHelper.CompanyId + "_" + FileName;
                FileName       = fileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");

                string logImport         = null;
                bool   FleetResult       = false;
                string rootFolderPath    = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + "vehicleFile\\";
                string destinationPath   = rootFolderPath + "\\Archive\\";
                string fullPathToExcel   = rootFolderPath + accessfileName;
                string fullpathToArchive = destinationPath + accessfileName;

                LoggerDataAccess loggerDataAccess = new LoggerDataAccess();

                logImport           = loggerDataAccess.LogFileImport(FileName, "IMP_FL_INITIATED", ValidRecords.ToString(), InValidRecords.ToString(), null, null);
                ImportFileHistoryID = logImport;

                if (new FileInfo(fullpathToArchive).Exists == false)
                {
                    string    connString = string.Format("Provider =Microsoft.ACE.OLEDB.12.0;Data Source=" + fullPathToExcel + ";Extended Properties='Excel 12.0;HDR=yes'", fullPathToExcel);
                    DataTable dt         = FileManager.GetDataTable("SELECT * FROM [Sheet1$]", connString);

                    Thread.CurrentThread.CurrentCulture =
                        CultureInfo.CreateSpecificCulture("en-GB");
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

                    var date = DateTime.Now;

                    if (CallType.ToLower() == "fleet")
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            Fleet Fleet = new Fleet()
                            {
                                CompanyAddressID = Convert.ToInt32(dt.Rows[i]["BranchID"].ToString()),
                                FleetID          = dt.Rows[i]["FleetID"].ToString(),
                                Make             = dt.Rows[i]["Make"].ToString(),
                                Model            = dt.Rows[i]["Model"].ToString(),
                                ModelYear        = Convert.ToInt32(dt.Rows[i]["ModelYear"].ToString()),
                                Colour           = dt.Rows[i]["Colour"].ToString(),
                                StartingMileage  = Convert.ToInt32(dt.Rows[i]["StartingMileage"].ToString()),
                                Payload          = dt.Rows[i]["Payload"].ToString(),
                                OwnerShipType    = dt.Rows[i]["OwnerShipType"].ToString(),
                                OverallLength    = dt.Rows[i]["OverallLength"].ToString(),
                                OverallWidth     = dt.Rows[i]["OverallWidth"].ToString(),
                                OverallHeight    = dt.Rows[i]["OverallHeight"].ToString(),
                                IsActive         = Convert.ToBoolean(dt.Rows[i]["IsActive"].ToString())
                            };
                            FleetResult = SaveFleet(Fleet, null, "");
                            if (FleetResult)
                            {
                                ValidRecords = ValidRecords + 1;
                            }
                            if (!FleetResult)
                            {
                                InValidRecords = InValidRecords + 1;
                            }
                        }
                    }
                    //Console.ReadLine();

                    string[] fileList = Directory.GetFiles(rootFolderPath, FileName);

                    if (Directory.Exists(rootFolderPath))
                    {
                        foreach (string file in fileList)
                        {
                            FileInfo mFile = new FileInfo(file);
                            if (new FileInfo(destinationPath + "\\" + mFile.Name).Exists == false)
                            {
                                mFile.MoveTo(destinationPath + "\\" + mFile.Name);
                            }
                        }
                    }
                }
                else if (new FileInfo(fullpathToArchive).Exists == true)
                {
                    return("File is already processed");
                }
                if (FleetResult)
                {
                    logImport = loggerDataAccess.LogFileImport(FileName, "IMP_FL_SCCS", ValidRecords.ToString(), InValidRecords.ToString(), null, ImportFileHistoryID);
                    return(FileName + ":- File imported successully.");
                }
                string eFileName;
                string errorFileName;

                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                eFileName     = "VehicleError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "VehicleFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                var v = FileManager.FileErrorLog(filePath, "Incorrect File Layout/FleetID already exists", "Error while processing file");

                logImport = loggerDataAccess.LogFileImport(FileName, "IMP_FL_FLD", ValidRecords.ToString(), InValidRecords.ToString(), errorFileName, ImportFileHistoryID);
                return(FileName + ":- File import Failed.");
            }
            catch (Exception ex)
            {
                string eFileName;
                string errorFileName;

                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                eFileName     = "VehicleError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "VehileFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                if (!string.IsNullOrEmpty(fileName))
                {
                    var v = FileManager.FileErrorLog(filePath, ex.Message, "Error with File");
                    eloggerDataAccess.LogFileImport(FileName, "IMP_FL_FLD", ValidRecords.ToString(), InValidRecords.ToString(), errorFileName, ImportFileHistoryID);
                }
                return(FileName + ":- File import Failed.");
            }
        }
        public string OrderFileImport(string FileName, string CallType)
        {
            int ValidRecords   = 0;
            int InValidRecords = 0;

            try
            {
                accessfileName = FileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");
                fileName       = ClaimHelper.CompanyId + "_" + FileName;
                FileName       = fileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");

                string logImport         = null;
                string rootFolderPath    = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + "orderFile\\";
                string destinationPath   = rootFolderPath + "\\Archive\\";
                string fullPathToExcel   = rootFolderPath + accessfileName;
                string fullpathToArchive = destinationPath + accessfileName;
                string OrderResult       = null;

                LoggerDataAccess loggerDataAccess = new LoggerDataAccess();

                logImport           = loggerDataAccess.LogFileImport(FileName, "IMP_FL_INITIATED", ValidRecords.ToString(), InValidRecords.ToString(), null, null);
                ImportFileHistoryID = logImport;

                if (logImport == "File is already processed.")
                {
                    return("File is already processed.");
                }

                if (string.IsNullOrEmpty(logImport))
                {
                    throw new Exception("Invalid response from Log File Import.");
                }

                if (new FileInfo(fullpathToArchive).Exists == false)
                {
                    string    connString = string.Format("Provider =Microsoft.ACE.OLEDB.12.0;Data Source=" + fullPathToExcel + ";Extended Properties='Excel 12.0;HDR=yes'", fullPathToExcel);
                    DataTable dt         = FileManager.GetDataTable("SELECT * FROM [Sheet1$]", connString);

                    Thread.CurrentThread.CurrentCulture =
                        CultureInfo.CreateSpecificCulture("en-GB");
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");



                    var date = DateTime.Now;

                    if (CallType == "Order")
                    {
                        if (dt != null)
                        {
                            var distinctOrders = dt.AsEnumerable().Select(c => Convert.ToString(c["VendorOrderID"])).Distinct().ToList <string>();

                            //ValidRecords = distinctOrders.Count();

                            foreach (var order in distinctOrders)
                            {
                                var orders = dt.AsEnumerable().Where(x => Convert.ToString(x["VendorOrderID"]) == order).ToList();
                                if (orders != null && orders.Count() > 0)
                                {
                                    string pickupLatitude   = null;
                                    string pickupLongitude  = null;
                                    string dropoffLatitude  = null;
                                    string dropoffLongitude = null;
                                    var    first            = orders[0];
                                    //first["PICKUPHOUSE_FLATNO"].ToString() + first["PickupAddress"].ToString() + ", " + first["PICKUPCITY"].ToString() + ", " + first["PICKUPSTATE"].ToString() + " " + first["PICKUPPINCODE"].ToString() + ", " + first["PICKUPCOUNTRY"].ToString(),
                                    //AIzaSyB9PgorTUksSwiRCNNTkfEEu1gaHIGG0Rw

                                    string Pickupaddress = first["PickupAddress"].ToString() + ", " + first["PICKUPAREA_LOCALITY"].ToString() + ", " + first["PICKUPCITY"].ToString() + ", " + first["PICKUPSTATE"].ToString() + " " + first["PICKUPPINCODE"].ToString() + ", " + first["PICKUPCOUNTRY"].ToString();

                                    string PickuprequestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false?key=AIzaSyB9PgorTUksSwiRCNNTkfEEu1gaHIGG0Rw", Uri.EscapeDataString(Pickupaddress));

                                    WebRequest  request            = WebRequest.Create(PickuprequestUri);
                                    WebResponse response           = request.GetResponse();
                                    System.Xml.Linq.XDocument xdoc = XDocument.Load(response.GetResponseStream());

                                    XElement result = xdoc.Element("GeocodeResponse").Element("result");
                                    if (result != null)
                                    {
                                        XElement locationElement = result.Element("geometry").Element("location");
                                        XElement pickuplat       = locationElement.Element("lat");
                                        XElement pickuplng       = locationElement.Element("lng");

                                        pickupLatitude  = pickuplat.Value;
                                        pickupLongitude = pickuplng.Value;
                                    }


                                    string DropOffaddress = first["DROPOFFADDRESS"].ToString() + ", " + first["DROPOFFAREA_LOCALITY"].ToString() + ", " + first["DROPOFFCITY"].ToString() + ", " + first["DROPOFFSTATE"].ToString() + " " + first["DROPOFFPINCODE"].ToString() + ", " + first["DROPOFFCOUNTRY"].ToString();

                                    string DropoffrequestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(DropOffaddress));

                                    WebRequest  requestD            = WebRequest.Create(DropoffrequestUri);
                                    WebResponse responseD           = requestD.GetResponse();
                                    System.Xml.Linq.XDocument xdocD = XDocument.Load(responseD.GetResponseStream());

                                    XElement resultD = xdocD.Element("GeocodeResponse").Element("result");
                                    if (resultD != null)
                                    {
                                        XElement locationElementD = resultD.Element("geometry").Element("location");
                                        XElement dropOfflat       = locationElementD.Element("lat");
                                        XElement dropOfflng       = locationElementD.Element("lng");

                                        dropoffLatitude  = dropOfflat.Value;
                                        dropoffLongitude = dropOfflng.Value;
                                    }



                                    LogistikaOrderHeader tOrder = new LogistikaOrderHeader
                                    {
                                        //ClientOrderSource = "FileImport_" + first["ServiceCode"].ToString(),
                                        CallType           = "Portal",
                                        ClientOrderSource  = "FileImport_" + FileName,//Convert.ToString(System.DateTime.Now),
                                        ServiceCode        = first["ServiceCode"].ToString(),
                                        OrderType          = first["OrderType"].ToString(),
                                        FreightType        = first["FreightType"].ToString(),
                                        OrderByName        = first["OrderByName"].ToString(),
                                        OrderByPhoneNumber = first["OrderByPhoneNumber"].ToString(),
                                        OrderByEmail       = first["OrderByEmail"].ToString(),
                                        PickUpDate         = Convert.ToDateTime(first["PickUpDate"].ToString()),
                                        VendorOrderID      = first["VendorOrderID"].ToString(),
                                        Payment            = new Payment
                                        {
                                            Amount        = Convert.ToDouble(first["CHARGEDAMOUNT"].ToString()),
                                            PaymentMethod = first["PAYMENTMODE"].ToString()
                                        },
                                        PickupAddress = new List <Address>
                                        {
                                            new Address()
                                            {
                                                AddressLine1 = first["PickupAddress"].ToString(),
                                                Suite        = first["PICKUPHOUSE_FLATNO"].ToString(),
                                                Locality     = first["PICKUPAREA_LOCALITY"].ToString(),
                                                City         = first["PICKUPCITY"].ToString(),
                                                StateCode    = first["PICKUPSTATE"].ToString(),
                                                PostalCode   = first["PICKUPPINCODE"].ToString(),
                                                CountryCode  = first["PICKUPCOUNTRY"].ToString(),
                                                LandMark     = first["PICKUPLANDMARK"].ToString(),
                                                Instruction  = first["PICKUPINSTRUCTION"].ToString(),
                                                Latitude     = pickupLatitude,
                                                Longitude    = pickupLongitude
                                            }
                                        },
                                        DropoffAddress = new List <Address>
                                        {
                                            new Address()
                                            {
                                                AddressLine1 = first["DROPOFFADDRESS"].ToString(),
                                                Suite        = first["DROPOFFHOUSE_FLATNO"].ToString(),
                                                Locality     = first["DROPOFFAREA_LOCALITY"].ToString(),
                                                City         = first["DROPOFFCITY"].ToString(),
                                                StateCode    = first["DROPOFFSTATE"].ToString(),
                                                PostalCode   = first["DROPOFFPINCODE"].ToString(),
                                                CountryCode  = first["DROPOFFCOUNTRY"].ToString(),
                                                LandMark     = first["DROPOFFLANDMARK"].ToString(),
                                                Instruction  = first["DROPOFFINSTRUCTION"].ToString(),
                                                DropOffDate  = Convert.ToDateTime(first["DropOffDate"].ToString()),
                                                Name         = first["DROPOFFNAME"].ToString(),
                                                PhoneNumber  = first["DROPOFFPHONE"].ToString(),
                                                Latitude     = dropoffLatitude,
                                                Longitude    = dropoffLongitude
                                            }
                                        }
                                    };
                                    tOrder.LineItem = orders.Select(s => new LogistikaOrderLineItem
                                    {
                                        Item = s["ITEM"].ToString(),
                                        //ItemType_FK = Convert.ToInt32(s["ItemType_FK"].ToString()),
                                        ShipmentType            = s["ShipmentType"].ToString(),
                                        GoodsType               = s["GOODSTYPE"].ToString(),
                                        UOM                     = s["UOM"].ToString(),
                                        Quantity                = Convert.ToInt32(s["NOOFITEMS"].ToString()),
                                        Weight                  = Convert.ToDouble(s["WEIGHT"].ToString()),
                                        Length                  = Convert.ToDouble(s["Length"].ToString()),
                                        Width                   = Convert.ToDouble(s["Width"].ToString()),
                                        Height                  = Convert.ToDouble(s["Height"].ToString()),
                                        IsPackagingRequiredFlag = Convert.ToBoolean(s["ISPACKAGINGREQUIRED?"].ToString()),
                                        IsPermitVerifiedFlag    = Convert.ToBoolean(s["ISPERMITVERIFIED?"].ToString())
                                    }).ToList();

                                    OrderResult = createOrder(tOrder);
                                    if (string.IsNullOrEmpty(OrderResult) || OrderResult.Contains("File import Failed"))
                                    {
                                        InValidRecords = InValidRecords + 1;
                                    }
                                    if (OrderResult.StartsWith("H"))
                                    {
                                        ValidRecords = ValidRecords + 1;
                                    }
                                }
                            }
                        }
                    }

                    string[] fileList = Directory.GetFiles(rootFolderPath, FileName);

                    if (Directory.Exists(rootFolderPath))
                    {
                        foreach (string file in fileList)
                        {
                            FileInfo mFile = new FileInfo(file);
                            if (new FileInfo(destinationPath + "\\" + mFile.Name).Exists == false)
                            {
                                mFile.MoveTo(destinationPath + "\\" + mFile.Name);
                            }
                        }
                    }
                }
                else if (new FileInfo(fullpathToArchive).Exists == true)
                {
                    return("File was already processed");
                }
                if (!string.IsNullOrEmpty(OrderResult))
                {
                    logImport = loggerDataAccess.LogFileImport(FileName, "IMP_FL_SCCS", ValidRecords.ToString(), InValidRecords.ToString(), null, ImportFileHistoryID);
                    return(FileName + ":- File imported successully.");
                }
                logImport = loggerDataAccess.LogFileImport(FileName, "IMP_FL_FLD", ValidRecords.ToString(), InValidRecords.ToString(), "IncorrectFileLayout", ImportFileHistoryID);
                return(FileName + ":- File import Failed.");
            }
            catch (Exception ex)
            {
                string           eFileName;
                string           errorFileName;
                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                eFileName     = "OrderError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "OrderFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                if (!string.IsNullOrEmpty(fileName))
                {
                    //fileName = fileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");
                    var v = FileManager.FileErrorLog(filePath, ex.Message, "Error with File");
                    eloggerDataAccess.LogFileImport(FileName, "IMP_FL_FLD", ValidRecords.ToString(), InValidRecords.ToString(), errorFileName, ImportFileHistoryID);
                }
                return(FileName + ":- File import Failed.");
            }
        }
        public string createOrder(LogistikaOrderHeader orderHeader)
        {
            // orderHeader.
            string exceptionMessages = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(orderHeader.PickupAddress[0].AddressLine1) || string.IsNullOrEmpty(orderHeader.DropoffAddress[0].AddressLine1))
                {
                    exceptionMessages = "AddressLine1 is missing";
                    //throw new Exception("AddressLine1 is missing");
                }
                if (string.IsNullOrEmpty(orderHeader.PickupAddress[0].City) || string.IsNullOrEmpty(orderHeader.DropoffAddress[0].City))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "City is missing" : exceptionMessages + ", " + "City is missing";
                    //throw new Exception("City is missing");
                }
                if (string.IsNullOrEmpty(orderHeader.PickupAddress[0].StateCode) || string.IsNullOrEmpty(orderHeader.DropoffAddress[0].StateCode))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "StateCode is missing" : exceptionMessages + ", " + "StateCode is missing";
                    //throw new Exception("StateCode is missing");
                }
                if (string.IsNullOrEmpty(orderHeader.DropoffAddress[0].PhoneNumber))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "DropOff PhoneNumber is missing" : exceptionMessages + ", " + "DropOff PhoneNumber is missing";
                    //throw new Exception("CountryCode is missing");
                }

                if (string.IsNullOrEmpty(orderHeader.PickupAddress[0].CountryCode) || string.IsNullOrEmpty(orderHeader.DropoffAddress[0].CountryCode))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "CountryCode is missing" : exceptionMessages + ", " + "CountryCode is missing";
                    //throw new Exception("CountryCode is missing");
                }

                if (string.IsNullOrEmpty(orderHeader.PickUpDate.ToString()) || string.IsNullOrEmpty(orderHeader.DropoffAddress[0].DropOffDate.ToString()))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Pickup or DropOff Date is missing" : exceptionMessages + ", " + "Pickup or DropOff Date is missing";
                    //throw new Exception("CountryCode is missing");
                }

                if (string.IsNullOrEmpty(orderHeader.FreightType))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "FreightType is missing" : exceptionMessages + ", " + "FreightType is missing";
                    //throw new Exception("FreightType is missing");
                }

                if (string.IsNullOrEmpty(orderHeader.OrderType))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OrderType is missing" : exceptionMessages + ", " + "OrderType is missing";
                    //throw new Exception("OrderType is missing");
                }

                if (string.IsNullOrEmpty(orderHeader.OrderByName))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OrderByName is missing" : exceptionMessages + ", " + "OrderByName is missing";
                    //throw new Exception("OrderType is missing");
                }

                if (string.IsNullOrEmpty(orderHeader.OrderByPhoneNumber))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OrderByPhoneNumber is missing" : exceptionMessages + ", " + "OrderByPhoneNumber is missing";
                }

                if (string.IsNullOrEmpty(orderHeader.OrderByEmail))
                {
                    exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "OrderByEmail is missing" : exceptionMessages + ", " + "OrderByEmail is missing";
                    //throw new Exception("OrderType is missing");
                }

                foreach (var v in orderHeader.LineItem)
                {
                    if (string.IsNullOrEmpty(v.Quantity.ToString()))
                    {
                        exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Quantity is missing" : exceptionMessages + ", " + "Quantity is missing";
                    }
                    if (string.IsNullOrEmpty(v.Weight.ToString()))
                    {
                        exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Weight is missing" : exceptionMessages + ", " + "Weight is missing";
                    }
                    if (string.IsNullOrEmpty(v.Item.ToString()))
                    {
                        exceptionMessages = string.IsNullOrEmpty(exceptionMessages) ? "Item is missing" : exceptionMessages + ", " + "Item is missing";
                    }
                }

                if (!string.IsNullOrEmpty(exceptionMessages))
                {
                    throw new Exception(exceptionMessages);
                }

                return(_orderDataAccess.createOrder(orderHeader));
            }
            catch (Exception ex)
            {
                string eFileName;
                string errorFileName;

                eFileName     = "OrderError_" + fileName + "_" + DateTime.Now.ToString("MMddyyyyHH");
                errorFileName = "OrderFile\\error\\" + eFileName + ".error.txt";
                string filePath = SiteConfigurationManager.GetAppSettingKey("TemplatePath") + errorFileName;

                LoggerDataAccess eloggerDataAccess = new LoggerDataAccess();

                if (!string.IsNullOrEmpty(fileName))
                {
                    if (string.IsNullOrEmpty(orderHeader.VendorOrderID))
                    {
                        orderHeader.VendorOrderID = "Empty";
                    }
                    fileName = fileName + SiteConfigurationManager.GetAppSettingKey("FileImportExtension");
                    var v = FileManager.FileErrorLog(filePath, ex.Message, orderHeader.VendorOrderID);
                    eloggerDataAccess.LogFileImport(fileName, "IMP_FL_FLD", null, null, errorFileName, ImportFileHistoryID);
                }
                return(fileName + ":- File import Failed.");
            }
        }