コード例 #1
0
        public async Task <ArticleInventoryResponse> EditArticleInventoryAsync(EditArticleInventoryRequest request)
        {
            ArticleInventory existingRecord = await _articleInventoryRespository.GetAsync(request.Id);

            if (existingRecord == null)
            {
                throw new ArgumentException($"Entity with {request.Id} is not present");
            }

            if (request.ArticlePlaceId != null)
            {
                ArticlePlace existingArticlePlace = await _articlePlacesRespository.GetAsync(request.ArticlePlaceId);

                if (existingArticlePlace == null)
                {
                    throw new NotFoundException($"ArticlePlace with {request.ArticlePlaceId} is not present");
                }
            }

            ArticleInventory entity = _articleInventoryMapper.Map(request);
            ArticleInventory result = _articleInventoryRespository.Update(entity);

            int modifiedRecords = await _articleInventoryRespository.UnitOfWork.SaveChangesAsync();

            _logger.LogInformation(Logging.Events.Edit, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords);
            _logger.LogInformation(Logging.Events.Edit, Messages.ChangesApplied_id, result?.Id);

            return(_articleInventoryMapper.Map(result));
        }
コード例 #2
0
        public async Task <ArticlePlaceResponse> DeleteArticlePlaceAsync(DeleteArticlePlaceRequest request)
        {
            if (request?.Id == null)
            {
                throw new ArgumentNullException();
            }

            ArticlePlace result = await _articlePlaceRespository.GetAsync(request.Id);

            if (result == null)
            {
                throw new ArgumentException($"Entity with {request.Id} is not present");
            }

            result.IsInactive = true;

            _articlePlaceRespository.Update(result);
            int modifiedRecords = await _articlePlaceRespository.UnitOfWork.SaveChangesAsync();

            _logger.LogInformation(Logging.Events.Delete, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords);

            return(_articlePlaceMapper.Map(result));
        }