protected StudentTaskViewModel GetStudentTaskView(int taskId, string studentId) { var t = _db.StudentTasks.Find(taskId); if (t is null) { return(null); } var solutions = _db.Solutions.Where(s => s.StudentId == studentId && s.TaskId == taskId).ToArray(); var solutionsViewModels = solutions.Select(s => new SolutionViewModel { Id = s.Id, TotalScore = s.Score, Result = s.ResultCode.ToString(), Time = s.Time, }).OrderByDescending(s => s.Time).ToArray(); var stud = _db.Users.Find(studentId); var res = new StudentTaskViewModel { StudentName = stud.FirstName + " " + stud.LastName, StudentId = studentId, TaskId = t.Id, TaskName = t.Name, Description = t.TaskText, Solutions = solutionsViewModels, Deadline = t.To, NumberOfAttempts = t.NumberOfAttempts, CanSend = CanSend(t, studentId, solutions), Result = "Нет решений", FrameworkTypes = _config.CompilerImages.Keys.ToArray() }; var studentResult = _db.StudentResults.Find(studentId, taskId); if (studentResult != null) { res.TotalScore = studentResult.Solution.Score; res.Result = studentResult.Solution.ResultCode.ToString(); } return(res); }
public ActionResult Laboratory(StudentTaskViewModel model) { Task task = taskService.GetAll().Where(x => x.ID == model.ID).FirstOrDefault(); if (task != null) { var identity = (ClaimsIdentity)User.Identity; var id = identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value; userTaskService.Create(new UserTask { TaskID = model.ID, UserID = int.Parse(id), Answer = model.Answer }); return(RedirectToAction("Task")); } return(View()); }