public async Task <IActionResult> DeleteDocument(int id)
        {
            Document docDelete = await dr.GetByIdAsync(id);

            if (docDelete != null)
            {
                string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "documents", docDelete.Name + "." + docDelete.FileType);
                System.IO.File.Delete(filePath);
                await dr.DeleteByIdAsync(docDelete);
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> ConvertToPdf(int id)
        {
            Document docConvert = await dr.GetByIdAsync(id);

            docConvert.ToPdf();
            await dr.AddAsync(new Document
            {
                Name        = "Convert - " + docConvert.Name,
                FileType    = FileType.PDF,
                DirectoryId = 1
            });

            return(RedirectToAction("Index", "Home"));
        }
        public static void ToHtml(this Document docConvert)
        {
            var pathSave = Path.Combine(GetPath(), "Convert - " + docConvert.Name + ".html");

            if (docConvert.FileType == FileType.PDF)
            {
                var pdfFile = new Aspose.Pdf.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                pdfFile.Save(pathSave, Aspose.Pdf.SaveFormat.Html);
            }
            else if (docConvert.FileType == FileType.DOCX || docConvert.FileType == FileType.DOC)
            {
                var docFile = new Aspose.Words.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                docFile.Save(pathSave, Aspose.Words.SaveFormat.Html);
            }
        }
        public static string CompareDocument(this Document doc1, Document doc2)
        {
            if (doc1.FileType != "docx" || doc2.FileType != "docx")
            {
                return("Cant Compare");
            }
            var             document1       = new Aspose.Words.Document(Path.Combine(GetPath(), doc1.Name + "." + doc1.FileType));
            var             document2       = new Aspose.Words.Document(Path.Combine(GetPath(), doc2.Name + "." + doc2.FileType));
            string          compareFileName = "Compare " + doc1.Name + " - " + doc2.Name + ".docx";
            var             documentCompare = new Aspose.Words.Document(Path.Combine(GetPath(), doc1.Name + "." + doc1.FileType));
            DocumentBuilder builder         = new DocumentBuilder(documentCompare);

            //TODO: extends compare (use Revision Document)
            document1.Compare(document2, "nhan1110i", DateTime.Now);
            document1.Save(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Temp", compareFileName));
            return(compareFileName);
        }
        public static void ToPdf(this Document docConvert)
        {
            var pathSave = Path.Combine(GetPath(), "Convert - " + docConvert.Name + ".pdf");

            if (docConvert.FileType == FileType.DOCX || docConvert.FileType == FileType.DOC)
            {
                var wordFile = new Aspose.Words.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                wordFile.Save(pathSave, Aspose.Words.SaveFormat.Pdf);
            }
            else if (docConvert.FileType == FileType.HTML)
            {
                HTMLDocument htmlFile = new HTMLDocument(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));

                Converter.ConvertHTML(htmlFile, new Aspose.Html.Saving.PdfSaveOptions {
                    JpegQuality = 100
                }, pathSave);
            }
        }
        public async Task <FileResult> CompareDocument(int doc1, int doc2)
        {
            Document firstDocument = await dr.GetByIdAsync(doc1);

            Document secondDocument = await dr.GetByIdAsync(doc2);

            //var compareWord = new Aspose.Words.Document(firstDocument.CompareDocument(secondDocument));
            var result = new Document
            {
                Name     = firstDocument.CompareDocument(secondDocument),
                FileType = FileType.DOCX,
                Id       = 0
            };
            string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Temp", result.Name);

            byte[] file = System.IO.File.ReadAllBytes(filePath);
            return(File(file, "application/force-download", result.Name));
        }
        public static void ToWord(this Document docConvert)
        {
            var pathSave = Path.Combine(GetPath(), "Convert - " + docConvert.Name + ".docx");

            if (docConvert.FileType == FileType.PDF)
            {
                var            pdfFile = new Aspose.Pdf.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                DocSaveOptions opt     = new DocSaveOptions()
                {
                    Format = DocSaveOptions.DocFormat.DocX
                };
                pdfFile.Save(pathSave, opt);
            }
            else if (docConvert.FileType == FileType.HTML)
            {
                var htmlFile = new HTMLDocument(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                //TODO: convert
            }
        }