示例#1
0
        public Response <AddRondeToQuizDTO> AddRondeToQuiz(AddRondeToQuizDTO dto)
        {
            try
            {
                RondeQuizValidator validator = new RondeQuizValidator();
                ValidationResult   results   = validator.Validate(dto);

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