public void MoveFileToScanFolder(MoveFile moveFile)
        {
            moveFile.FileNewName = moveFile.FileNewName.Replace(".pdf.pdf", ".pdf");
            moveFile.FileName = moveFile.FileName.Replace("\n", "");
            moveFile.FilePath = moveFile.FilePath.Replace("\n", "");
            moveFile.Folder = moveFile.Folder.Replace("\n", "");

            try
            {
                moveFile.ID = GetMoveFileId(moveFile.Folder, Utility.GetUserName(), moveFile.DocumentType);
                System.IO.Directory.CreateDirectory(System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName());
                File.Move(moveFile.FilePath, System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName() + "\\" + moveFile.FileNewName);
                moveFile.FilePath = System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName() + "\\" + moveFile.FileNewName;
                AddFileToFolder(moveFile);
                Logging.LogErrors(ConfigurationValues.ErrorLogPath, "File successfully moved");
            }
            catch (Exception er)
            {
                Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
            }
        }
        public bool AddFileToFolder(MoveFile moveFile)
        {
            using (IDbConnection db = new SqlConnection(ConfigurationValues.PostOfficeDatabaseConnection))
            {
                try
                {
                    string query = "INSERT INTO [HoldFiles]"
                        + " ("
                        + " [HoldFolderID]"
                        + " ,[ActiveDirectoryUser]"
                        + " ,[FolderName]"
                        + " ,[FileName]"
                        + " ,[FilePath]"
                        + " ,[DocumentType]"
                        + ")"
                        + " VALUES"
                        + "("
                        + " @HoldFolderID,@ActiveDirectoryUser,@FolderName,@FileName,@FilePath,@DocumentType"
                        + " )";

                    db.Execute(query, new
                    {
                        @HoldFolderID = moveFile.ID,
                        @ActiveDirectoryUser = Utility.GetUserName(),
                        @FolderName = moveFile.Folder,
                        @FileName = moveFile.FileNewName,
                        @FilePath = moveFile.FilePath,
                        @DocumentType = moveFile.DocumentType
                    });
                    return true;
                }
                catch (Exception er)
                {
                    Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
                    return false;
                }
            }
        }
        public void MoveFileToFolder(MoveFile moveFile)
        {
            //1.  Move the file to the new folder
            //2   Insert record giving folder that and name of document

            moveFile.FileNewName = moveFile.FileNewName.Replace(".pdf.pdf", ".pdf");
            moveFile.FileName = moveFile.FileName.Replace("\n","");
            moveFile.FilePath = moveFile.FilePath.Replace("\n", "");
            moveFile.Folder = moveFile.Folder.Replace("\n", "");

            List<InBoundFaxes> inBoundFaxesList = new List<InBoundFaxes>();

            try
            {
                using (IDbConnection db = new SqlConnection(ConfigurationValues.PostOfficeDatabaseConnection))
                {
                    string query = "SELECT [PostOfficeFoldersByUser].[ID],[PostOfficeFoldersByUser].[ActiveDirectoryUser],"
                        + " [PostOfficeFolders].[FriendlyName] as Name,[PostOfficeFolders].[NewPath] as Path "
                        + " FROM [PostOfficeFoldersByUser]"
                        + " inner join [PostOfficeFolders]"
                        + " on [PostOfficeFolders].id = [PostOfficeFoldersByUser].PostOfficeFoldersId"
                        + " where [ActiveDirectoryUser] = @ActiveDirectoryUser";

                    inBoundFaxesList = db.Query<InBoundFaxes>(query, new { @ActiveDirectoryUser = Utility.GetUserName() }).ToList();

                    for (int i = 0; i < inBoundFaxesList.Count; i++)
                    {
                        string[] filePaths = Directory.GetFiles(ConfigurationValues.InboundFaxRoot + inBoundFaxesList[i].Path);

                        if (filePaths.Length > 0)
                        {
                            for (int j = 0; j < filePaths.Length; j++)
                            {
                                string[] fileName = filePaths[j].Split('\\');

                                if (moveFile.FileName == fileName[fileName.Length - 1])
                                {
                                    try
                                    {
                                        moveFile.ID = GetMoveFileId(moveFile.Folder, Utility.GetUserName(), moveFile.DocumentType);
                                        moveFile.FilePath = System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName() + "\\" +  moveFile.FileNewName;
                                        System.IO.Directory.CreateDirectory(System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + Utility.GetUserName());
                                        AddFileToFolder(moveFile);
                                        Logging.LogErrors(ConfigurationValues.ErrorLogPath, "Moving file from " + filePaths[j] + " to " + System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + "\\" + moveFile.FileName);
                                        File.Move(filePaths[j], moveFile.FilePath);
                                        Logging.LogErrors(ConfigurationValues.ErrorLogPath, "File successfully moved");
                                    }
                                    catch (Exception er)
                                    {
                                        Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception er)
            {
                Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
            }
        }