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)); }
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)); }
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)); }
public ArticleInventory Map(AddArticleInventoryRequest request) { if (request == null) { return(null); } ArticleInventory articleInventory = new ArticleInventory { ArticleId = request.ArticleId, ArticlePlaceId = request.ArticlePlaceId, }; return(articleInventory); }
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); }
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)); }
public ArticleInventory Update(ArticleInventory articleInventoriy) { _context.Entry(articleInventoriy).State = EntityState.Modified; return(articleInventoriy); }
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); }
public ArticleInventory Add(ArticleInventory articleInventoriy) { return(_context.ArticleInventories.Add(articleInventoriy).Entity); }