public Result ValidateAddTestDto(AddTestDto addTestDto) { if (string.IsNullOrWhiteSpace(addTestDto.Title)) { return(Result.Fail(-1)); } return(questionValidator.ValidateAddQuestionDtos(addTestDto.Questions)); }
public async Task <IEnumerable <GetTestDto> > AddTestAsync(AddTestDto addTestDto) { Test test = _mapper.Map <Test>(addTestDto); await _context.AddAsync(test); await _context.SaveChangesAsync(); List <Test> tests = await _context.Tests .Include(t => t.Breakage) .Include(t => t.Tags) .ToListAsync(); return(tests.Select(t => _mapper.Map <GetTestDto>(t)).ToList()); }
public async Task <Result> AddTest(AddTestDto addTestDto) { var validationResult = testValidator.ValidateAddTestDto(addTestDto); if (validationResult.Failure) { return(validationResult); } var test = mapper.Map <Test>(addTestDto); dataStorage.Tests.Add(test); await dataStorage.SaveChangesAsync(); return(Result.Ok()); }
public async Task <ActionResult <IEnumerable <GetTestDto> > > AddTest(AddTestDto addTestDto) { return(Ok(await _testRepo.AddTestAsync(addTestDto))); }