Example #1
0
        public IEnumerable <RondeDTO> GetAllRondes()
        {
            var rondes     = _teamQuizRondeUnitOfWork.RondeRepository.GetAll();
            var rondesDTOs = new List <RondeDTO>();

            foreach (Ronde ronde in rondes)
            {
                rondesDTOs.Add(RondeMapper.MapRondeModelToRondeDTO(ronde));
            }

            return(rondesDTOs);
        }
Example #2
0
        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
                        }
                    }
                });
            }
        }
Example #3
0
        public Response <IEnumerable <RondeDTO> > findAllRondesInAQuiz(int quizid)
        {
            try
            {
                if (quizid <= 0)
                {
                    return(new Response <IEnumerable <RondeDTO> >()
                    {
                        Errors = new List <Error>()
                        {
                            new Error {
                                Type = ErrorType.ValidationError, Message = "De id mag niet 0 zijn"
                            }
                        }
                    });
                }
                var             responseEntities = _teamQuizRondeUnitOfWork.QuizRondeTussentabelRepository.GetWhere(x => x.QuizId == quizid);
                List <RondeDTO> rondeDTOs        = new List <RondeDTO>();

                foreach (var item in responseEntities)
                {
                    var ronde = _teamQuizRondeUnitOfWork.RondeRepository.GetById(item.RondeId);
                    rondeDTOs.Add(RondeMapper.MapRondeModelToRondeDTO(ronde));
                }

                return(new Response <IEnumerable <RondeDTO> >()
                {
                    DTO = rondeDTOs
                });
            }
            catch (Exception ex)
            {
                return(new Response <IEnumerable <RondeDTO> >()
                {
                    Errors = new List <Error>()
                    {
                        new Error {
                            Type = ErrorType.Exception, Message = ex.Message
                        }
                    }
                });
            }
        }
Example #4
0
        public Response <RondeDTO> FindRonde(int id)
        {
            try
            {
                if (id <= 0)
                {
                    return(new Response <RondeDTO>()
                    {
                        Errors = new List <Error>()
                        {
                            new Error {
                                Type = ErrorType.ValidationError, Message = "De id mag niet 0 zijn"
                            }
                        }
                    });
                }
                var ronde       = _teamQuizRondeUnitOfWork.RondeRepository.GetById(id);
                var rondeReturn = RondeMapper.MapRondeModelToRondeDTO(ronde);

                return(new Response <RondeDTO>()
                {
                    DTO = rondeReturn
                });
            }
            catch (Exception ex)
            {
                return(new Response <RondeDTO>()
                {
                    Errors = new List <Error>()
                    {
                        new Error {
                            Type = ErrorType.Exception, Message = ex.Message
                        }
                    }
                });
            }
        }