コード例 #1
0
        public async Task <IActionResult> UpdateModuleAsync(
            [FromQuery] int organisationId,
            [FromRoute] int moduleId,
            [FromBody] UpdateModuleRequestDto updateModuleRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var validationResult = await _updateModuleRequestValidator.ValidateAsync(updateModuleRequestDto, token);

                if (!validationResult.IsValid)
                {
                    return(new BadRequestObjectResult(validationResult.Errors.ToValidationErrors()));
                }
                var moduleServiceObject = Mapper.Map <ModuleServiceObject>(updateModuleRequestDto);
                moduleServiceObject.OrganisationId = organisationId;
                moduleServiceObject.Id             = moduleId;
                var serviceResponse = await _modulesService.UpdateModuleAsync(moduleServiceObject, token);

                return(new OkObjectResult(Mapper.Map <UpdateModuleResponseDto>(serviceResponse)));
            }
            catch (BadRequestException e)
            {
                return(new BadRequestObjectResult(e.Error));
            }
        }