Esempio n. 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));
            }
        }
Esempio n. 2
0
        public async Task <UseCaseResponse <IEnumerable <Asset> > > Execute()
        {
            var response = new UseCaseResponse <IEnumerable <Asset> >();

            try
            {
                var assets = await assetRepository.List();

                return(response.SetResult(assets));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message, e);
                return(response.SetInternalServerError("Unexpected error: " + e.Message));
            }
        }
Esempio n. 3
0
        public async Task <UseCaseResponse <bool> > Execute(Guid id)
        {
            var response = new UseCaseResponse <bool>();

            try
            {
                await assetRepository.Delete(id);

                return(response.SetResult(true));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message, e);
                return(response.SetInternalServerError("Unexpected error: " + e.Message));
            }
        }