コード例 #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 <ArticleInventoryResponse> AddArticleInventoryAsync(AddArticleInventoryRequest request)
        {
            ArticleInventory articleInventory = _articleInventoryMapper.Map(request);
            ArticleInventory result           = _articleInventoryRespository.Add(articleInventory);

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

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

            return(_articleInventoryMapper.Map(result));
        }
コード例 #3
0
        public async Task <ArticleInventoryResponse> GetArticleInventoryAsync(Guid id)
        {
            if (id == null)
            {
                throw new ArgumentNullException();
            }

            ArticleInventory entity = await _articleInventoryRespository.GetAsync(id);

            _logger.LogInformation(Events.GetById, Messages.TargetEntityChanged_id, entity?.Id);

            return(_articleInventoryMapper.Map(entity));
        }
コード例 #4
0
        public ArticleInventory Map(AddArticleInventoryRequest request)
        {
            if (request == null)
            {
                return(null);
            }

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

            return(articleInventory);
        }
コード例 #5
0
        public ArticleInventoryResponse Map(ArticleInventory articleInventory)
        {
            if (articleInventory == null)
            {
                return(null);
            }
            ;

            ArticleInventoryResponse response = new ArticleInventoryResponse
            {
                Id             = articleInventory.Id,
                ArticleId      = articleInventory.ArticleId,
                Article        = _articleMapper.Map(articleInventory.Article),
                ArticlePlaceId = articleInventory.ArticlePlaceId,
                ArticlePlace   = _articlePlaceMapper.Map(articleInventory.ArticlePlace)
            };

            return(response);
        }
コード例 #6
0
        public async Task <ArticleInventoryResponse> DeleteArticleInventoryAsync(DeleteArticleInventoryRequest request)
        {
            if (request?.Id == null)
            {
                throw new ArgumentNullException();
            }

            ArticleInventory result = await _articleInventoryRespository.GetAsync(request.Id);

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

            result.IsInactive = true;

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

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

            return(_articleInventoryMapper.Map(result));
        }
コード例 #7
0
 public ArticleInventory Update(ArticleInventory articleInventoriy)
 {
     _context.Entry(articleInventoriy).State = EntityState.Modified;
     return(articleInventoriy);
 }
コード例 #8
0
        public async Task <ArticleInventory> GetAsync(Guid id)
        {
            ArticleInventory articleInventoriy = await _context.ArticleInventories.AsNoTracking().Where(x => x.Id == id).Include(x => x.ArticlePlace).FirstOrDefaultAsync();

            return(articleInventoriy);
        }
コード例 #9
0
 public ArticleInventory Add(ArticleInventory articleInventoriy)
 {
     return(_context.ArticleInventories.Add(articleInventoriy).Entity);
 }