public async Task <IHttpActionResult> CreateAsync([FromBody] CursistToCreateDto dto)
        {
            var cursusFromDto = Mapper.Map <Cursist>(dto);

            var cursusInstantie = await _cursusInstantieService.GetAsync(dto.CursusInstantieId);

            if (cursusInstantieService == null)
            {
                return(BadRequest("CursusInstantie is onbekend"));
            }

            var cursist = await _cursistSerivce.CreateAsync(cursusFromDto);

            if (cursist == null)
            {
                return(BadRequest("Cursist aanmaken is mislukt"));
            }

            var addedDB = await _cursusInstantieService.AddCursist(dto.CursusInstantieId, cursist);

            if (addedDB == null)
            {
                return(BadRequest("Cursist niet aan instantie kunnen toevoegen"));
            }

            var resultDto = Mapper.Map <CursistToDetailsDto>(cursist);

            return(Created(resultDto.Id.ToString(), resultDto));
        }
Example #2
0
        public async Task <IHttpActionResult> GetByIdAsync(int id)
        {
            var cursus = await _cursusInstantieService.GetAsync(id);

            if (cursus == null)
            {
                return(BadRequest("Geen cursus gevonden"));
            }

            var dto = Mapper.Map <CursusInstantieToDetailsDto>(cursus);

            return(Ok(dto));
        }