public EditScheduledTestsValidator(ITestInstancesRepository testInstancesRepository) { _testInstancesRepository = testInstancesRepository; RuleFor(x => x.Duration).GreaterThanOrEqualTo(1) .WithMessage("Duration must be greater or equal to 1"); RuleFor(x => x).Custom((x, context) => { var testInstance = _testInstancesRepository.GetByIdAsync(x.Id).Result; if (testInstance == null) { context.AddFailure("Id", "Id must be valid"); } if (x.StartDateTime < DateTime.Now) { context.AddFailure("StartDate", "StartDate must valid"); } }); }
public async Task <IActionResult> Finished(Guid id) { var testInstance = await _testInstancesRepository.GetByIdAsync(id); if (testInstance == null) { return(NotFound()); } var test = await _testsRepository.GetByIdAsync(testInstance.TestId); if (test == null) { return(NotFound()); } var finishedTestsViewModel = new FinishedTestsViewModel(); finishedTestsViewModel.Description = test.Description; finishedTestsViewModel.Name = test.Name; return(View(finishedTestsViewModel)); }
public EditTestTemplateValidator(ITestInstancesRepository testInstancesRepository) { _testInstancesRepository = testInstancesRepository; RuleFor(x => x.Name) .NotEmpty().WithMessage(string.Format(CoreConfigurationConstants.FieldEmptyMessage, "Name")) .MaximumLength(CoreConfigurationConstants.MaxLength) .WithMessage(string.Format(CoreConfigurationConstants.FieldMaximumLengthMessage, "Name", CoreConfigurationConstants.MaxLength)); RuleFor(x => x.Description) .NotEmpty().WithMessage(string.Format(CoreConfigurationConstants.FieldEmptyMessage, "Description")) .MaximumLength(CoreConfigurationConstants.MaxLength) .WithMessage(string.Format(CoreConfigurationConstants.FieldMaximumLengthMessage, "Description", CoreConfigurationConstants.MaxLength)); RuleFor(x => x).Custom((x, context) => { var testInstance = _testInstancesRepository.GetByIdAsync(x.Id).Result; if (testInstance == null) { context.AddFailure("Id", "Id must be valid"); } }); }
public async Task <IActionResult> Details(Guid id) { var testInstance = await _testInstancesRepository.GetByIdAsync(id); if (testInstance == null) { return(NotFound()); } var test = await _testsRepository.GetByIdAsync(testInstance.TestId); if (test == null) { return(NotFound()); } var testType = _testTypesRepository.GetByIdAsync(test.TestTypeId).Result.Type; if (testType == null) { return(NotFound()); } var group = await _groupsRepository.GetByIdAsync(testInstance.GroupId); if (group == null) { return(NotFound()); } var userList = DetailsGetAllUsersOfGroupByGroupId(group.Id); if (userList == null) { return(NotFound()); } var exercises = await _exercisesRepository.GetAllExercisesOfTestAsync(test.Id); if (exercises == null) { return(NotFound()); } var exerciseList = new List <ScheduledTestDetailsExercise>(); foreach (var item in exercises) { exerciseList.Add(new ScheduledTestDetailsExercise() { Description = item.Description, Answers = await _answersRepository.GetAllAnswersOfExerciseAsync(item.Id) }); } var detailsScheduledTestViewModel = new DetailsScheduledTestViewModel(); var testDetails = new ScheduledTestDetailsTest(); testDetails.TestType = testType; testDetails.Description = test.Description; testDetails.Name = test.Name; testDetails.Exercises = exerciseList; var groupDetails = new ScheduledTestDetailsGroup(); groupDetails.Description = group.Description; groupDetails.Name = group.Name; groupDetails.Users = userList; detailsScheduledTestViewModel.TestDetails = testDetails; detailsScheduledTestViewModel.GroupDetails = groupDetails; detailsScheduledTestViewModel.Id = id; detailsScheduledTestViewModel.Duration = testInstance.Duration; detailsScheduledTestViewModel.StartDateTime = testInstance.StartedAt; return(View(detailsScheduledTestViewModel)); }