Ejemplo n.º 1
0
        public async Task <IActionResult> DocxInsertedForm(SubmitPaperVM submitPaperVM)
        {
            if (ModelState.IsValid)
            {
                Papers newPaper = new Papers
                {
                    Date  = submitPaperVM.Date,
                    Draft = submitPaperVM.Draft,
                    //HashTags = (ICollection<PaperHashes>)submitPaperVM.HashTags,
                    ID        = 0,
                    Paper     = submitPaperVM.Paper,
                    ShrederId = submitPaperVM.ShrederId,
                    Title     = submitPaperVM.Title
                };

                var createdPaper = await _paperRepo.Create(newPaper);



                PaperUpload newUpload = new PaperUpload
                {
                    Css      = submitPaperVM.Css,
                    FilePath = submitPaperVM.FilePath,
                    GuidId   = submitPaperVM.GuidId,
                    ID       = 0,
                    PaperId  = createdPaper.ID
                };

                var createdPaperUpload = await _paperUploadRepo.Create(newUpload);

                return(PartialView("_PaperSubmitted"));
            }

            return(View(submitPaperVM));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UploadFile(UploadFormVM form)
        {
            //get the file
            //var file = Request.Form.Files[0];
            if (ModelState.IsValid)
            {
                var file = form.File;

                //check if the file is there and make sure it has content
                if (file != null && file.Length > 0)
                {
                    //get the uploaded file name.
                    var fileName = Path.GetFileName(file.FileName);

                    var setGuid = Guid.NewGuid();

                    //get the wwwroot path and append the guid dir
                    var filePath = _hostEnv.WebRootPath + "\\uploads\\" + setGuid + "\\";

                    //create the dir
                    Directory.CreateDirectory(filePath);

                    //create img dir
                    Directory.CreateDirectory(filePath + "\\imgs\\");

                    //create the path for the uploaded file
                    var path = Path.Combine(filePath, fileName);

                    //copy the uploaded file to the dir
                    using (var stream = System.IO.File.Create(path))
                    {
                        await file.CopyToAsync(stream);
                    }

                    //convert the uploaded file into html and make picture dir

                    ConvertDocToHtml newConverter = new ConvertDocToHtml(path, fileName, filePath);
                    newConverter.SetConverterSettings();
                    newConverter.Convert();
                    newConverter.CustomizeCss("quote", "span");

                    //
                    PaperUpload newUpload = new PaperUpload
                    {
                        FilePath       = filePath,
                        UniqueFileName = fileName,
                        UploadDate     = DateTime.UtcNow,
                        GuidId         = setGuid,
                        Css            = newConverter.Css
                    };

                    Papers newPaper = new Papers
                    {
                        Paper = newConverter.Html
                    };

                    PaperUploadVM newVM = new PaperUploadVM
                    {
                        PaperUpload = newUpload,
                        Paper       = newPaper
                    };



                    return(Json(newVM));
                }
            }

            return(Json("error"));
        }