Beispiel #1
0
        public Response <AddTeamToQuizDTO> AddTeamToQuiz(AddTeamToQuizDTO dto)
        {
            try
            {
                AddTeamToQuizValidator validator = new AddTeamToQuizValidator();
                ValidationResult       results   = validator.Validate(dto);

                if (results.IsValid)
                {
                    var tussentabelEntity = TussentabelMapper.AddTeamToQuizDTOToEntity(dto);
                    var returnTussentabel = _teamQuizRondeUnitOfWork.QuizTeamTussentabelRepository.Add(tussentabelEntity);
                    _teamQuizRondeUnitOfWork.Commmit();
                    var returnTussentabelDTO = TussentabelMapper.AddTeamToQuizEntityToDTO(returnTussentabel);
                    var response             = new Response <AddTeamToQuizDTO>
                    {
                        DTO = returnTussentabelDTO
                    };
                    return(response);
                }
                else
                {
                    return(new Response <AddTeamToQuizDTO>()
                    {
                        Errors = results.Errors.Select(x => new Error()
                        {
                            Type = ErrorType.ValidationError, Message = x.ErrorMessage
                        }).ToList()
                    });
                }
            }
            catch (Exception ex)
            {
                return(new Response <AddTeamToQuizDTO>()
                {
                    Errors = new List <Error>()
                    {
                        new Error()
                        {
                            Type = ErrorType.Exception, Message = ex.Message
                        }
                    }
                });
            }
        }