public async Task<ActionResult> Edit(int id, string[] tasksString) { int.TryParse(TempData["Count"].ToString(), out int studentsCountInAcceptancePeriod); int.TryParse(TempData["SelectedAcceptancePeriod"].ToString(), out int SelectedAcceptancePeriod); TempData["ExamId"] = id; double[] tasks = new double[tasksString.Length]; if (studentsCountInAcceptancePeriod > 0) { TempData["ErrorMessage"] = "Šablono keisti negalima, nes prie jo jau yra priskirta kandidatų."; _logger.LogWarning("Can not change Tasks, {Count} students found in this period. User {User}.", studentsCountInAcceptancePeriod, _user); return RedirectToAction("Edit", "TaskParameters", new { id }); } else { var exam = await _context.Exams.FindAsync(id); if (id != exam.Id) { _logger.LogWarning("Can not find Exam by id = {Id}. User {User}.", id, _user); return NotFound(); } if (ModelState.IsValid) { for (int i = 0; i < tasksString.Length; i++) { tasks[i] = double.Parse(tasksString[i], System.Globalization.CultureInfo.InvariantCulture); } TaskParametersMappings.EditTaskParametersEntity(exam, tasks); await _context.SaveChangesAsync(); _logger.LogWarning("Can not find Exam by id = {Id}. User {User}.", id, _user); return Redirect($"/Exams/Index?value={SelectedAcceptancePeriod}"); } _logger.LogError("Something went wrong with modelstate. User {User}.", _user); return View(TaskParametersMappings.ToTaskParameterViewModel(tasks)); } }
public async Task<ActionResult> Edit(int? id) { if (id == null) { _logger.LogWarning("ExamId not found. User {User}.", _user); return NotFound(); } var tasks = await _context.Exams.FindAsync(id); if (tasks == null) { _logger.LogWarning("Tasks not found. User {User}.", _user); return NotFound(); } var setTaskParameterModel = TaskParametersMappings.ToTaskParameterViewModel(tasks); setTaskParameterModel.TaskString = new string[setTaskParameterModel.Tasks.Length]; for (int i = 0; i < setTaskParameterModel.TaskString.Length; i++) { setTaskParameterModel.TaskString[i] = setTaskParameterModel.Tasks[i].ToString().Replace(",", "."); } return View(setTaskParameterModel); }
public async Task <IActionResult> Index(int?id) { if (id == null) { _logger.LogError("Exam id was null. User {User}.", _user); return(NotFound()); } TempData["ExamId"] = id; var studentRequest = _repository.Query <Student>() .Include(x => x.Result) .Include(x => x.ConversationResult) .Where(x => x.Id > 0); var students = await studentRequest.Where(x => x.Result.Exam.Id == id).ToListAsync(); if (students == null) { _logger.LogWarning("No students found. User {User}.", _user); return(NotFound()); } var studentViewModels = new List <StudentsResultViewModel>(); var exam = _repository.Query <Exam>().Include(x => x.City).FirstOrDefault(x => x.Id == id); students.ForEach(x => studentViewModels.Add(StudentsMappings.ToViewModel(x, x.Result))); foreach (var item in students) { foreach (var student in studentViewModels) { student.FinalPoints = student.Tasks?.Sum(x => x) ?? 0; var examDraft = _repository.Query <Exam>().FirstOrDefault(e => e.Id == student.ExamId); double maxPoints = TaskParametersMappings.ToTaskParameterViewModel(examDraft).Tasks.Sum(x => x); student.PercentageGrade = student.FinalPoints * 100 / maxPoints; student.ExamCityAndDate = $"{exam.City.Name}, {exam.Date.ToShortDateString()}"; } } studentViewModels = studentViewModels.OrderByDescending(x => x.FinalPoints).ToList(); _logger.LogInformation($"Found {studentViewModels.Count} students. User {_user}."); return(View(studentViewModels)); }
public async Task <ActionResult> Edit(int?id) { if (id == null) { _logger.LogWarning("ExamId not found. User {User}.", User.Identity.Name); return(NotFound()); } var tasks = await _repository.FindByIdAsync <Exam>(id); if (tasks == null) { _logger.LogWarning("Tasks not found. User {User}.", User.Identity.Name); return(NotFound()); } var setTaskParameterModel = TaskParametersMappings.ToTaskParameterViewModel(tasks); setTaskParameterModel.TaskString = new string[setTaskParameterModel.Tasks.Length]; for (int i = 0; i < setTaskParameterModel.TaskString.Length; i++) { setTaskParameterModel.TaskString[i] = setTaskParameterModel.Tasks[i].ToString().Replace(",", "."); } return(View(setTaskParameterModel)); }