示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Summary,Description,ImgUrl,Industry,Tags")] ReportModel report, IFormFile file)
        {
            if (id != report.Id)
            {
                return(NotFound("Id can NOT be null"));
            }

            if (ModelState.IsValid)
            {
                //Update Report
                await _reportServices.UpdateReport(id, report.Title, report.Summary, report.Description, report.ImgUrl, report.Industry, report.Tags);

                //Check if a new File was uploaded
                if (file != null)
                {
                    //Check that File is a PDF
                    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.");
                    }

                    //Upload Report File to Blob
                    using var stream = file.OpenReadStream();
                    await _blobServices.UploadFileBlobAsync(stream, $"{report.Id}.pdf");
                }

                return(RedirectToAction("ReportPending", "Home"));
            }
            return(RedirectToAction(nameof(Index)));
        }
示例#2
0
        public async Task <IActionResult> Put(int id, [FromBody] ReportModel report)
        {
            var model = await _reportServices.UpdateReport(id, report.Title, report.Summary, report.Description, report.ImgUrl, report.Industry, report.Tags.ToString());

            return(Ok(model));
        }