public Response <QuizDTO> AddQuiz(QuizDTO quizDTO) { try { QuizValidator validator = new QuizValidator(); ValidationResult results = validator.Validate(quizDTO); if (results.IsValid) { var quiz = QuizMapper.MapQuizDTOToQuizModel(quizDTO); var quizEntity = _teamQuizRondeUnitOfWork.QuizRepository.Add(quiz); _teamQuizRondeUnitOfWork.Commmit(); var quizEntityDTO = QuizMapper.MapQuizModelToQuizDTO(quizEntity); var response = new Response <QuizDTO> { DTO = quizEntityDTO }; return(response); } else { return(new Response <QuizDTO>() { Errors = results.Errors.Select(x => new Error() { Type = ErrorType.ValidationError, Message = x.ErrorMessage }).ToList() }); } } catch (Exception ex) { return(new Response <QuizDTO>() { Errors = new List <Error>() { new Error() { Type = ErrorType.Exception, Message = ex.Message } } }); } }
public Response <RondeDTO> AddRonde(RondeDTO rondeDTO) { try { RondeRequestValidator validator = new RondeRequestValidator(); ValidationResult results = validator.Validate(rondeDTO); if (results.IsValid) { var ronde = RondeMapper.MapRondeDTOToRondeModel(rondeDTO); var rondeEntity = _teamQuizRondeUnitOfWork.RondeRepository.Add(ronde); _teamQuizRondeUnitOfWork.Commmit(); var rondeEntityDTO = RondeMapper.MapRondeModelToRondeDTO(rondeEntity); var response = new Response <RondeDTO> { DTO = rondeEntityDTO }; return(response); } else { return(new Response <RondeDTO>() { Errors = results.Errors.Select(x => new Error() { Type = ErrorType.ValidationError, Message = x.ErrorMessage }).ToList() }); } } catch (Exception ex) { return(new Response <RondeDTO>() { Errors = new List <Error>() { new Error() { Type = ErrorType.Exception, Message = ex.Message } } }); } }