Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] ReportModel report)
        {
            var userId = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier));
            var user   = await _userServices.GetUser(userId);

            var model = await _reportServices.CreateReport(report.Title, report.Summary, report.Description, user.Email, report.ImgUrl, report.Industry, report.Tags.ToString());

            return(Ok(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Summary,Description,Author,ImgUrl,Industry,Tags")] ReportModel report, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                //Validate File Exists
                if (file == null)
                {
                    throw new ArgumentException("Please upload a file.");
                }

                //Validate File Extension
                else
                {
                    string[] permittedExtensions = { ".pdf" };


                    var ext = Path.GetExtension(file.FileName).ToLowerInvariant();

                    if (string.IsNullOrEmpty(ext) || !permittedExtensions.Contains(ext))
                    {
                        throw new ArgumentException("Invalid file format. Please provide a PDF.");
                    }
                }

                //Create Report
                await _reportServices.CreateReport(report.Title, report.Summary, report.Description, report.Author, report.ImgUrl, report.Industry, report.Tags);

                //Get New Report ID
                var reportId = await _reportServices.GetReportsCount();

                //Upload Report File to Blob
                using (var stream = file.OpenReadStream())
                {
                    await _blobServices.UploadFileBlobAsync(stream, $"{reportId}.pdf");
                }
                return(RedirectToAction("ReportPending", "Home"));
            }

            return(RedirectToAction(nameof(Index)));
        }