Exemple #1
0
        public ActionResult OpenDocument(int documentID, string title)
        {
            Document document    = Repository.Documents.GetByID(documentID);
            var      docBytes    = DocumentStorage.GetBytes(document.Location);
            string   contentType = IOHelper.GetContentType(document.Location);
            string   ext         = System.IO.Path.GetExtension(document.Location).ToLower();

            if (docBytes == null)
            {
                return(RedirectToAction("DocumentNotFound", "Error"));
            }

            return(File(docBytes, contentType, title + ext));
        }
Exemple #2
0
        public ActionResult OpenDocument(int id, string title)
        {
            Document document    = Repository.Documents.GetByID(id);
            var      docBytes    = DocumentStorage.GetBytes(document.Location);
            string   contentType = IOHelper.GetContentType(document.Location);
            string   ext         = Path.GetExtension(document.Location).ToLower();

            FileContentResult result = null;

            if (docBytes != null)
            {
                result = File(docBytes, contentType, title + ext);
            }
            return(result);
        }
Exemple #3
0
        public ActionResult OpenDocument(int id)
        {
            Document document    = Repository.Documents.GetByID(id);
            var      docBytes    = DocumentStorage.GetBytes(document.Location);
            string   contentType = IOHelper.GetContentType(document.Location);
            string   ext         = Path.GetExtension(document.Location).ToLower();

            string title = (from hi in document.HelpItems where hi.DocumentID == id select hi.Title).FirstOrDefault();

            if (String.IsNullOrEmpty(title))
            {
                title = "HelpItem";
            }

            if (docBytes == null)
            {
                return(RedirectToAction("DocumentNotFound", "Error"));
            }

            return(File(docBytes, contentType, title + ext));
        }
Exemple #4
0
        public ActionResult Document(Guid uniqueKey)
        {
            var authResult = CERSSecurityManager.AuthenticateHttpAuthorizationHeader();

            if (authResult.IsAuthenticatedAndAuthorized)
            {
                byte[] docData               = null;
                bool   docNotFound           = false;
                bool   docUniqueKeyNotFound  = false;
                bool   docPhysicallyNotFound = false;

                //Begin Transaction
                using (EDTTransactionScope transScope = new EDTTransactionScope(authResult.Account, EDTEndpoint.RegulatorFacilitySubmittalDocumentQuery, Request.UserHostAddress, authenticationRequestID: authResult.EDTAuthenticationRequestID))
                {
                    try
                    {
                        var dataModel = transScope.Repository.DataModel;
                        var doc       = dataModel.FacilitySubmittalElementDocuments.SingleOrDefault(p => p.Key == uniqueKey && !p.Voided);
                        if (doc != null)
                        {
                            transScope.WriteActivity(string.Format("FacilitySubmittalElementDocument CERSUniqueKey {0} metadata found.", uniqueKey));
                            var edtAuthorizationResult = CERSSecurityManager.EDTAuthorize(authResult.Account, doc.FacilitySubmittalElementResourceDocument.Resource.FacilitySubmittalElement.CERSID, PermissionRole.EDTFacilitySubmittalQuery);
                            transScope.Connect(edtAuthorizationResult.RegulatorID);

                            if (edtAuthorizationResult.Authorized)
                            {
                                if (doc.Document != null)
                                {
                                    transScope.WriteActivity("Document metadata found.");
                                    docData = DocumentStorage.GetBytes(doc.Document.Location);
                                    if (docData != null)
                                    {
                                        transScope.WriteActivity(string.Format("Document physically found in storage file size {0}kb.", doc.FileSize));
                                        transScope.Complete(EDTTransactionStatus.Accepted);
                                    }
                                    else
                                    {
                                        docPhysicallyNotFound = true;
                                        transScope.WriteMessage("Document NOT physically found in storage.", EDTTransactionMessageType.Error);
                                        transScope.Complete(EDTTransactionStatus.Rejected);
                                    }
                                }
                                else
                                {
                                    transScope.WriteMessage("Document metadata not found.", EDTTransactionMessageType.Error);
                                    transScope.Complete(EDTTransactionStatus.Rejected);
                                    docNotFound = true;
                                }
                            }
                            else
                            {
                                string errorMessage = "Account is not authorized to download this document. The account is not affiliated with any regulators associated with this Facility, or the account does not have sufficient rights.";
                                transScope.SetStatus(EDTTransactionStatus.Rejected);
                                transScope.WriteActivity(errorMessage);
                                return(HttpStatusCodeResult(HttpStatusCode.Unauthorized, errorMessage));
                            }
                        }
                        else
                        {
                            transScope.WriteActivity("Document Unique Key Not Found");
                            transScope.Complete(EDTTransactionStatus.Rejected);
                            docUniqueKeyNotFound = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        transScope.WriteActivity("Exception Occurred.", ex);
                        transScope.WriteMessage("Exception Occurred. " + ex.Format(), EDTTransactionMessageType.Error);
                        return(HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Format()));
                    }
                }

                if (docNotFound)
                {
                    return(HttpStatusCodeResult(HttpStatusCode.NotFound, "Document for UniqueKey '" + uniqueKey + "' was not found."));
                }
                else if (docUniqueKeyNotFound)
                {
                    return(HttpStatusCodeResult(HttpStatusCode.NotFound, "A Document does not exists with the UniqueKey '" + uniqueKey + "'."));
                }
                else if (docPhysicallyNotFound)
                {
                    return(HttpStatusCodeResult(HttpStatusCode.NotFound, "The document's metadata exists, but the physical document (filesystem) was not found."));
                }
                else
                {
                    return(File(docData, "application/octet-stream"));
                }
            }
            else
            {
                return(HttpStatusCodeResult(HttpStatusCode.Unauthorized, authResult));
            }
        }