Пример #1
0
        public async Task <UseCaseResponse <Asset> > Execute(CreateAssetRequest request)
        {
            var response = new UseCaseResponse <Asset>();

            try
            {
                assetValidator.ValidateAndThrow(request);
                var asset = request.ToAsset();

                var createdAsset = await assetRepository.Create(asset);

                sendMessage(asset);


                return(response.SetCreated(createdAsset));
            }
            catch (ValidationException ex)
            {
                return(response.SetBadRequest("Validation exception", ex.ToErrorMessage().ToArray()));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message, e);
                return(response.SetInternalServerError("Unexpected error: " + e.Message));
            }
        }
Пример #2
0
        public async Task <IActionResult> Update(Guid id, CreateAssetRequest assetUpdated)
        {
            var asset    = assetUpdated.ToAsset(id);
            var response = await updateAssetUseCase.Execute(asset);

            return(actionResultConverter.Convert(response));
        }