Пример #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 ArticleInventory Map(EditArticleInventoryRequest request)
        {
            if (request == null)
            {
                return(null);
            }

            ArticleInventory articleInventory = new ArticleInventory
            {
                Id             = request.Id,
                ArticleId      = request.ArticleId,
                ArticlePlaceId = request.ArticlePlaceId,
            };

            return(articleInventory);
        }