public async Task <IActionResult> OnPostAsync(IFormFile newFile) { var fileName = Request.Form["newFile"]; var title = Request.Form["title"]; var referenceName = Request.Form["reference_name"]; var coAuthors = Request.Form["co_authors"]; var topic = Request.Form["topic"]; var author = Int32.Parse(Request.Form["author"]); var version = Int32.Parse(Request.Form["version"]) + 1; try { if (!ModelState.IsValid | String.IsNullOrEmpty(newFile.FileName)) { return(RedirectToPage(Routes.MY_PAPERS, new { id = 1 })); } } catch (NullReferenceException e) { return(RedirectToPage(Routes.MY_PAPERS, new { id = 1 })); } var fileExtension = System.IO.Path.GetExtension(newFile.FileName); Paper paper = new Paper(); paper.status = 1; paper.author = author; paper.version = version; paper.coAuthors = coAuthors; paper.title = title; paper.topic = topic; paper.referenceName = referenceName; paper.fileReference = referenceName + "-" + paper.version.ToString() + fileExtension; paper.submissionDate = DateTime.Now; // Save information Papers papers = new Papers(); int status = papers.addNewPaper(paper); // Create the file. if (status != -1) { var filePath = "wwwroot/papers/" + paper.fileReference; newFile.CopyTo(new FileStream(filePath, FileMode.Create)); return(RedirectToPage(Routes.MY_PAPERS, new { id = 3 })); } return(RedirectToPage(Routes.MY_PAPERS, new { id = 2 })); }
public async Task <IActionResult> OnPostAsync() { int userID = Convert.ToInt32(HttpContext.Session.GetString("userID")); if (!ModelState.IsValid) { return(Page()); } // If all the information on the form is valid. var fileExtension = System.IO.Path.GetExtension(File.FileName); var referenceGuid = Guid.NewGuid().ToString(); paper.status = 1; paper.author = userID; paper.version = 1; paper.finalReview = ""; paper.referenceName = referenceGuid; paper.fileReference = referenceGuid + "-" + paper.version.ToString() + fileExtension; paper.submissionDate = DateTime.Now; // Save information Papers papers = new Papers(); int status = papers.addNewPaper(paper); // Create the file. if (status != -1) { var filePath = "wwwroot/papers/" + paper.fileReference; File.CopyTo(new FileStream(filePath, FileMode.Create)); Notification notificationManager = new Notification(); //Notify PCC new paper has been submitted notificationManager.sendNotifiactionAll(" New Paper Submitted by " + HttpContext.Session.GetString("userEmail"), Roles.PCC, userID); //Notify Author his paper has been submitted notificationManager.sendNotifiactionToOneUser("Your paper has been submitted successfully", userID, userID); return(RedirectToPage(Routes.SUBMIT_PAPER, new { id = 1 })); } return(RedirectToPage(Routes.SUBMIT_PAPER, new { id = 2 })); }