public IActionResult GetById(int id) { try { var response = _service.FindRonde(id); if (response.DidError) { return(BadRequest(response.Errors)); } var rondeReturn = RondeViewModelMapper.MapRondeDTOToRondeViewModelResponse(response.DTO); return(Ok(rondeReturn)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult GetAll() { var rondesDTOs = _service.GetAllRondes(); if (rondesDTOs == null) { return(null); } var rondesModels = new List <RondeViewModelResponse>(); foreach (var ronde in rondesDTOs) { rondesModels.Add(RondeViewModelMapper.MapRondeDTOToRondeViewModelResponse(ronde)); } return(Ok(rondesModels)); }
public IActionResult GetAllRondesInAQuiz(int id) { var quizRondeDTOs = _service.findAllRondesInAQuiz(id); if (quizRondeDTOs == null) { return(null); } var rondesModels = new List <RondeViewModelResponse>(); foreach (var ronde in quizRondeDTOs.DTO) { rondesModels.Add(RondeViewModelMapper.MapRondeDTOToRondeViewModelResponse(ronde)); } return(Ok(rondesModels)); }
public IActionResult Create(RondeViewModelRequest rondeViewModel) { try { var createDTO = RondeViewModelMapper.MapRondeViewModelRequestToRondeDTO(rondeViewModel); var response = _service.AddRonde(createDTO); if (response.DidError) { return(BadRequest(response.Errors)); } var createdRonde = RondeViewModelMapper.MapRondeDTOToRondeViewModelResponse(response.DTO); return(Created("/api/quiz/GetById/" + createdRonde.Id, createdRonde)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void GetAllRondesCorrect() { var rondeDTOs = new List <RondeDTO>(); rondeDTOs.Add(new RondeDTO { Id = 1, Naam = "Ronde 1" }); IQueryable <RondeDTO> queryableRondeDTOs = rondeDTOs.AsQueryable(); var rondeModels = new List <RondeViewModelResponse>(); foreach (var ronde in rondeDTOs) { rondeModels.Add(RondeViewModelMapper.MapRondeDTOToRondeViewModelResponse(ronde)); } //Arange rondeService.Setup(x => x.GetAllRondes()).Returns(queryableRondeDTOs); //Act var alleRondes = controller.GetAll() as ObjectResult; var ListRondes = alleRondes.Value as List <RondeViewModelResponse>; //Assert Assert.That(ListRondes.Count(), Is.EqualTo(rondeModels.Count())); for (int i = 0; i < ListRondes.Count(); i++) { Assert.That(ListRondes.ToArray()[i].Id, Is.EqualTo(rondeModels.ToArray()[i].Id)); Assert.That(ListRondes.ToArray()[i].Naam, Is.EqualTo(rondeModels.ToArray()[i].Naam)); } }
public IActionResult Update([FromBody] RondeViewModelResponse rondeViewModel) { try { var rondeDTO = RondeViewModelMapper.MapRondeViewModelResponseToRondeDTO(rondeViewModel); var ronde = _service.Update(rondeDTO); if (ronde == null) { return(BadRequest("Error updating ronde")); } if (ronde.DidError) { return(BadRequest(ronde.Errors)); } var rondeReturn = RondeViewModelMapper.MapRondeDTOToRondeViewModelResponse(ronde.DTO); return(Created("/api/quiz/GetById/" + rondeReturn.Id, rondeReturn)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }