public IList <BusinessModels.Article> GetAll() { _logger.LogInformation($"{typeof(InMemoryArticleRepositoryAdapter).FullName}.GetAll()"); try { var result = new List <BusinessModels.Article>(); IList <EntityModels.InMemory.Article> articleEntities = _articleRepository.GetAll(); foreach (var articleEntity in articleEntities) { BusinessModels.Article article = CreateBusinessModel(articleEntity); result.Add(article); } return(result); } catch (LoggedException) { throw; } catch (Exception ex) { _logger.LogError(ex.Message); throw new LoggedException("Logged exception", ex); } }
public BusinessModels.Article GetByEan(string ean) { _logger.LogInformation($"{typeof(InMemoryArticleRepositoryAdapter).FullName}.GetByEan({ean})"); try { EntityModels.InMemory.Article articleEntity = _articleRepository.GetByEan(ean); BusinessModels.Article article = null; if (articleEntity != null) { article = CreateBusinessModel(articleEntity); } return(article); } catch (LoggedException) { throw; } catch (Exception ex) { _logger.LogError(ex.Message); throw new LoggedException("Logged exception", ex); } }
public void AddArticleToSupplierInventory(long supplierId, BusinessModels.Article article) { _logger.LogInformation($"{typeof(InMemorySupplierRepositoryAdapter).FullName}.AddArticleToSupplierInventory(supplierId={supplierId}, articleId={article.Id})"); try { var inventoryEntity = new EntityModels.InMemory.Inventory() { ArticleId = article.Id, Price = article.Price, Quantity = article.Quantity, SupplierId = supplierId }; _inventoryRepository.Insert(inventoryEntity); } catch (LoggedException) { throw; } catch (Exception ex) { _logger.LogError(ex.Message); throw new LoggedException("Logged exception", ex); } }
private BusinessModels.Supplier CreateBusinessModel(EntityModels.InMemory.Supplier supplierEntity, IList <EntityModels.InMemory.Article> articleEntities, IList <EntityModels.InMemory.Inventory> inventoryEntities) { var result = new BusinessModels.Supplier() { Id = supplierEntity.Id, Name = supplierEntity.Name }; foreach (var item in inventoryEntities) { EntityModels.InMemory.Article articleEntity = articleEntities.First(art => art.Id == item.ArticleId); var articleBusiness = new BusinessModels.Article() { Id = articleEntity.Id, EAN = articleEntity.EAN, Name = articleEntity.Name, Price = item.Price, Quantity = item.Quantity, InventoryId = item.Id }; result.Inventory.Add(articleBusiness.Id, articleBusiness); } return(result); }
private EntityModels.InMemory.Article CreateEntityModel(BusinessModels.Article article) { return(new EntityModels.InMemory.Article() { Id = article.Id, EAN = article.EAN, Name = article.Name }); }
public void Update(BusinessModels.Article article) { _logger.LogInformation($"{typeof(InMemoryArticleRepositoryAdapter).FullName}.Update({article.Id})"); try { EntityModels.InMemory.Article articleEntity = CreateEntityModel(article); _articleRepository.Update(articleEntity); } catch (LoggedException) { throw; } catch (Exception ex) { _logger.LogError(ex.Message); throw new LoggedException("Logged exception", ex); } }
public BusinessModels.Article Insert(BusinessModels.Article article) { _logger.LogInformation($"{typeof(InMemoryArticleRepositoryAdapter).FullName}.Insert({article.EAN})"); try { EntityModels.InMemory.Article articleEntity = CreateEntityModel(article); articleEntity = _articleRepository.Insert(articleEntity); article.Id = articleEntity.Id; return(article); } catch (LoggedException) { throw; } catch (Exception ex) { _logger.LogError(ex.Message); throw new LoggedException("Logged exception", ex); } }