Esempio n. 1
0
        public ActionResult DownloadAllDocuments([Bind(Prefix = "ClientId")] string Number)
        {
            tbl_Folder folder = repository.SelectByNumber(Number);

            //gets all documents for one folder_id
            IEnumerable <tbl_Document> files = documentRepository.SelectAll(folder.Folder_ID.ToString());

            byte[] result; //blank byte array, ready to be used to filled with the tbl_document.ArchivedFile bytes

            //opening a stream to allow data to be moved
            using (var zipArchiveMemoryStream = new MemoryStream())
            {
                //creating a zipArchive obj to be used and disposed of
                using (var zipArchive = new ZipArchive(zipArchiveMemoryStream, ZipArchiveMode.Create, true))
                {
                    foreach (tbl_Document file in files)
                    {
                        DownloadFile(zipArchive, file);
                    }
                }

                zipArchiveMemoryStream.Seek(0, SeekOrigin.Begin); //not exactly sure what this does, I think it pertains to the ziped folders ordering
                result = zipArchiveMemoryStream.ToArray();        //I think this is the ziped item
            }

            return(new FileContentResult(result, "application/zip")
            {
                FileDownloadName = "AllArchivedFilesFor_" + Number + ".zip"
            });
        }
Esempio n. 2
0
        //keep for potential of future testing of db connection

        /*
         * public FolderController(IFolderRepository repository) {
         *  this.repository = repository;
         * }
         */

        //currently the role is coming as a query value, needs to be a role check through better security
        /// <summary>
        /// Takes the ClientId and packages some data up to give to publicVMController
        /// Might just comebine this and PublicVM together, somewhat redudant to have two controllers
        /// </summary>
        /// <param name="Number">The Client Id</param>
        /// <param name="Role">Whether the person has authoratative powers in Archive View</param>
        /// <returns></returns>
        //Since all exceptions go to the same view, dont see any reason to use different handerror attributes
        // GET: Folder
        public ActionResult Index([Bind(Prefix = "ClientId")] string Number, string Role = "", string PublicName = "")
        {
            tbl_Folder folder = null;

            CustomHelpers.InMemoryCache cacheprovider = new CustomHelpers.InMemoryCache();

            folder = repository.SelectByNumber(Number);

            if (folder == null)
            {
                NoResultException exception = new NoResultException("The client may not exist or does not have any available documents.");
                exception.HelpLink          = "Please check over the provided information and try again.";
                exception.Data["Client ID"] = Number;

                throw exception;
            }
            else
            {
                //was told to eventually create a seperate role for ArchiveView
                if (HttpContext.User.IsInRole("westlandcorp\\IT-ops"))
                {
                    TempData["RoleButton"] = "Admin";

                    if (Role == "Admin")
                    {
                        TempData["Role"]       = "Admin";
                        TempData["RoleButton"] = "Client";
                    }
                    else
                    {
                        TempData["Role"] = "Client";
                    }
                }
                else
                {
                    TempData["Role"] = "Client";
                }

                //TempData["Client_Name"] = folder.Name;
                TempData["Client_Name"] = Server.UrlDecode(PublicName);

                TempData["Client_Id"] = folder.Number;
                TempData["Folder_Id"] = folder.Folder_ID; //should be a better way than carrying this variable around
            }

            cacheprovider.removeCache(folder.Folder_ID.ToString());

            return(RedirectToAction("Index", "PublicVM", new { folderId = folder.Folder_ID }));
        }
Esempio n. 3
0
        //keep for potential of future testing of db connection

        /*
         * public FolderController(IFolderRepository repository) {
         *  this.repository = repository;
         * }
         */

        //currently the role is coming as a query value, needs to be a role check through better security
        // GET: Folder
        public ActionResult Index([Bind(Prefix = "ClientId")] string Number, string Role = "")
        {
            tbl_Folder folder = null;

            try {
                folder = repository.SelectByNumber(Number);
            } catch {
                TempData["importance"] = true;
                return(RedirectToAction("Index", "ErrorHandler", null));
            }

            if (folder == null)
            {
                TempData.Clear();
                TempData["Client_Id"]  = Number;
                TempData["error_info"] = "The client may not exist or does not have any available documents.";
                TempData["importance"] = false;

                return(RedirectToAction("Index", "ErrorHandler", null));
            }
            else
            {
                if (HttpContext.User.IsInRole("IT-ops"))
                {
                    TempData["RoleButton"] = "Admin";

                    if (Role == "Admin")
                    {
                        TempData["Role"]       = "Admin";
                        TempData["RoleButton"] = "Client";
                    }
                    else
                    {
                        TempData["Role"] = "Client";
                    }
                }
                else
                {
                    TempData["Role"] = "Client";
                }

                TempData["Client_Name"] = folder.Name;
                TempData["Client_Id"]   = folder.Number;
                TempData["Folder_Id"]   = folder.Folder_ID; //should be a better way than carrying this variable around
            }

            return(RedirectToAction("Index", "PublicVM", new { folderId = folder.Folder_ID }));
        }
Esempio n. 4
0
        //Downloads all documents pertaining to a specific client ID
        public ActionResult DownloadAllDocuments([Bind(Prefix = "ClientId")] string Number)
        {
            tbl_Folder folder = repository.SelectByNumber(Number);

            //gets all documents for one folder_id
            IEnumerable <tbl_Document> files = documentRepository.SelectAll(folder.Folder_ID.ToString());

            byte[] result; //blank byte array, ready to be used to filled with the tbl_document.ArchivedFile bytes

            //opening a stream to allow data to be moved
            using (var zipArchiveMemoryStream = new MemoryStream())
            {
                //creating a zipArchive obj to be used and disposed of
                using (var zipArchive = new ZipArchive(zipArchiveMemoryStream, ZipArchiveMode.Create, true))
                {
                    foreach (var file in files)
                    {
                        if (file.ArchivedFile != null)
                        {
                            //according to Ramin, creation of an ArchivedFile and Submitting an ArchivedFile are different steps, so there could be 'dirty' records/documents in WAS db that has no ArchivedFile Fields records
                            var zipEntry = zipArchive.CreateEntry(file.Document_ID.ToString() + "." + file.FileExtension); //creates a unit of space for the individual file to be placed in

                            using (var entryStream = zipEntry.Open())
                            {
                                using (var tmpMemory = new MemoryStream(file.ArchivedFile))
                                {
                                    tmpMemory.CopyTo(entryStream); //copies the data into the unit space
                                }
                            }
                        }
                    }
                }

                zipArchiveMemoryStream.Seek(0, SeekOrigin.Begin); //not exactly sure what this does, I think it pertains to the ziped folders ordering
                result = zipArchiveMemoryStream.ToArray();        //I think this is the ziped item
            }

            return(new FileContentResult(result, "application/zip")
            {
                FileDownloadName = "AllArchivedFilesFor_" + Number + ".zip"
            });
        }