public HttpResponseMessage DownloadMyWordFile(string language)
        {
            try
            {
                telemetry.TrackEvent("DownloadMyWordFile", new Dictionary <string, string> {
                    { "User", User.Identity.Name }
                });

                var documentManager = new WordDocumentManager();

                var generationData  = GetGenerationData(language);
                var cleanedFullName = !string.IsNullOrEmpty(generationData.Personal.FullName) ? generationData.Personal.FullName.Replace(' ', '_') : string.Empty;

                var bytes = documentManager.GetDocument(generationData);

                var result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new ByteArrayContent(bytes);
                result.Content.Headers.ContentDisposition =
                    new System.Net.Http.Headers.ContentDispositionHeaderValue(
                        "attachment")
                {
                    FileName = $"CV_{cleanedFullName}_{language.ToUpper()}" + ".docx"
                };

                return(result);
            }
            catch (Exception ex)
            {
                telemetry.TrackException(ex);

                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
        public void Test_FileStoring_TestRealData()
        {
            var documentManager = new WordDocumentManager();

            var simpleFile = GetGenerationData();

            var filePath = "E:\\Temp\\Amrop\\Generated\\Docs";
            var fileName = $"{Guid.NewGuid().ToString()}.docx";

            documentManager.SaveDocument(simpleFile, filePath, fileName);
        }
Exemplo n.º 3
0
        public void Test_FileStoring()
        {
            var documentManager = new WordDocumentManager();

            var simpleFile = new GenerationData();

            var filePath = "C:\\temp\\WordGeneration";
            var fileName = $"{Guid.NewGuid().ToString()}.docx";

            documentManager.SaveDocument(simpleFile, filePath, fileName);
        }
        public HttpResponseMessage DownloadWordFile(string language, string id)
        {
            try
            {
                telemetry.TrackEvent("DownloadWordFile", new Dictionary <string, string> {
                    { "User", User.Identity.Name }
                });

                var documentManager = new WordDocumentManager();

                var generationData  = GetGenerationData(language, id);
                var cleanedFullName = !string.IsNullOrEmpty(generationData.Personal.FullName) ? generationData.Personal.FullName.Replace(' ', '_') : string.Empty;

                var bytes = documentManager.GetDocument(GetGenerationData(language, id));

                var result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new ByteArrayContent(bytes);
                result.Content.Headers.ContentDisposition =
                    new System.Net.Http.Headers.ContentDispositionHeaderValue(
                        "attachment")
                {
                    FileName = $"CV_{cleanedFullName}_{language.ToUpper()}" + ".docx"
                };

                using (var db = new ProfileInformationDbContext())
                {
                    db.AuditLogs.Add(new AuditLog
                    {
                        AuditEvent     = AuditEvent.DownloadDoc.ToString(),
                        EventTime      = DateTime.Now,
                        UserAffected   = generationData.Personal.FullName,
                        UserAffectedId = id,
                        Username       = User.Identity.Name
                    });

                    db.SaveChanges();
                }

                return(result);
            }
            catch (Exception ex)
            {
                telemetry.TrackException(ex);

                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 5
0
        public HttpResponseMessage DownloadPdfFile()
        {
            try
            {
                var documentManager = new WordDocumentManager();

                var bytes = documentManager.GetDocument(new GenerationData());

                var result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new ByteArrayContent(bytes);
                result.Content.Headers.ContentDisposition =
                    new System.Net.Http.Headers.ContentDispositionHeaderValue(
                        "attachment")
                {
                    FileName = "Test" + ".docx"
                };

                return(result);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.Gone));
            }
        }