Exemple #1
0
        public async Task <IActionResult> CreateProgramAsync(
            [FromBody] Request <ProgramViewModel.Creation> programRequest,
            CancellationToken token = default)
        {
            _logger.LogDebug("CreateProgramAsync");

            if (programRequest.Data is null)
            {
                ModelState.AddModelError(nameof(programRequest.Data), "no request data");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(new ErrorResponse.BadRequest(ModelState)));
            }

            var programEntity = _mapper.Map <ProgramViewModel.Creation, ProgramEntity>(programRequest.Data !);
            var createdEntity = await _programRepository.CreateProgramEntityAsync(
                programEntity,
                token);

            var program = _mapper.Map <ProgramEntity, ProgramViewModel>(createdEntity);

            return(CreatedAtRoute("GetProgramById",
                                  new { programId = program.ProgramId },
                                  new Response <ProgramViewModel>(program)));
        }