Beispiel #1
0
        /// <summary>
        /// Allows the user to dowload the file given.
        /// All users.
        /// </summary>
        /// <param name="docKey">They key of the file to be downloaded</param>
        /// <returns>The file to download if successful, otherwise nothing</returns>
        public FileResult Download(string docKey)
        {
            FileStoreService fss = new FileStoreService();

            //gets the file based on the file store key
            var file = fss.GetFile(docKey).ResponseStream;

            var fileType = fss.GetFile(docKey).Headers.ContentType;

            //finds the document title for the download
            var document = db.Revisions.Where(r => r.fileStoreKey == docKey).SingleOrDefault();

            //Service that allows for the use of dowloading
            using (var memoryStream = new MemoryStream())
            {
                //if no a file exists then proceed
                if (file != null)
                {
                    //Begin the dowloading procees
                    file.CopyTo(memoryStream);
                    byte[] fileBytes = memoryStream.ToArray();



                    // Promts the user to download the file. File types are unknown
                    // due to a variety of formats that are supported
                    return(File(fileBytes, fileType, document.DocumentTitle));
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "DocID, RevisionNum, DocumentTitle, Distributees, File")] RevisionViewModel revision)
        {
            ViewBag.isAuthor = isAuthor();
            ViewBag.isAdmin  = isAdmin();
            if (isAuthor())
            {
                if (ModelState.IsValid)
                {
                    //Retrieves the document from the revision being created.
                    var doc            = db.Documents.Where(d => d.id == revision.DocID).SingleOrDefault();
                    var latestRevision = db.Revisions.Where(r => r.document.id == doc.id && r.State == DocumentState.Active).SingleOrDefault();
                    var distributees   = new HashSet <Account>();

                    if (distributees.Count > 0)
                    {
                        distributees = (HashSet <Account>)latestRevision.Distributees;
                    }

                    // Files is looking for the corresponding ID in the view
                    HttpPostedFileBase file = Request.Files["document"];

                    if (file != null)
                    {
                        FileStoreService fss = new FileStoreService();

                        revision.FileStoreKey = fss.UploadFile(file);
                    }

                    //New revision to be added to the database
                    Revision newRevision = new Revision()
                    {
                        //Autogenerated unique identifer
                        id            = Guid.NewGuid().ToString(),
                        DocumentTitle = revision.DocumentTitle,
                        RevisionNum   = revision.RevisionNum,
                        //Revision creation date/time set to the current date/time.
                        DocCreationDate = DateTime.Now,
                        State           = DocumentState.Draft,
                        //Revision activation date/time set the the current date/time.
                        ActivationDate = null,
                        //Revision's document set to the document queryed from database.
                        document = doc,
                        //New empty hash of Accounts.
                        Distributees = distributees.ToList(),
                        fileStoreKey = revision.FileStoreKey
                    };

                    //Adds the new revision to database.
                    db.Revisions.Add(newRevision);
                    db.SaveChanges();
                    //Redirects to the list of distributees.
                    return(RedirectToAction("SelectUsers", "Revisions", new { newRevision.id }));
                }
            }

            this.AddNotification("Sorry! You do not have permisson to access this page!", NotificationType.ERROR);
            return(RedirectToAction("Index", "Home"));
        }