public async Task <IActionResult> SendSolution(string subjectName, int examId) { var examModel = await this.examsService.GetExam <ExamViewModel>(examId); var now = DateTime.Now; if (examModel.Open > now) { this.TempData["message"] = "You should wait until the exam became open!"; return(this.RedirectToAction("Themes", "Subjects", new { subjectName })); } if (examModel.Close < now) { this.TempData["message"] = "The exam has already closed!"; return(this.RedirectToAction("Themes", "Subjects", new { subjectName })); } var sendSolutionModel = new ExamSendSolutionInputModel { SubjectName = subjectName, ExamId = examId, }; return(this.View(sendSolutionModel)); }
public async Task <IActionResult> SendSolution(string subjectName, int examId, ExamSendSolutionInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var fileUri = string.Empty; if (input.File != null) { fileUri = await this.themesService .UploadFileToCloudinary(input.File.FileName, input.File.OpenReadStream()); } var studentId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await this.examsService.SendSolutionAsync(studentId, examId, fileUri, input.FileDescription); return(this.RedirectToAction("Themes", "Subjects", new { subjectName })); }