Beispiel #1
0
        public async Task <IActionResult> CreatePageAsync(
            [FromQuery] int organisationId,
            [FromBody] CreatePageRequestDto createPageRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var validationResult = await _addPageRequestValidator.ValidateAsync(createPageRequestDto, token);

                if (!validationResult.IsValid)
                {
                    return(new BadRequestObjectResult(validationResult.Errors.ToValidationErrors()));
                }

                var pageServiceObject = Mapper.Map <PageServiceObject>(createPageRequestDto);
                pageServiceObject.OrganisationId = organisationId;
                var serviceResult = await _pagesService.CreatePageAsync(pageServiceObject, token);

                return(new CreatedResult(string.Empty, Mapper.Map <CreatePageResponseDto>(serviceResult)));
            }
            catch (BadRequestException e)
            {
                return(new BadRequestObjectResult(e.Error));
            }
        }