Beispiel #1
0
        public BusinessModels.Order GetById(long id)
        {
            _logger.LogInformation($"{typeof(InMemoryOrderRepositoryAdapter).FullName}.GetById({id})");

            try
            {
                EntityModels.InMemory.Order orderEntity = _orderRepository.GetById(id);
                BusinessModels.Order        result      = null;

                if (orderEntity != null)
                {
                    EntityModels.InMemory.Inventory inventoryEntity = _inventoryRepository.GetById(orderEntity.InventoryId);
                    EntityModels.InMemory.Article   articleEntity   = _articleRepository.GetById(inventoryEntity.ArticleId);
                    EntityModels.InMemory.Buyer     buyerEntity     = _buyerRepository.GetById(orderEntity.BuyerId);

                    result = CreateBusinessModel(orderEntity, articleEntity, inventoryEntity, buyerEntity);
                }

                return(result);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        public IList <BusinessModels.Order> GetAll()
        {
            _logger.LogInformation($"{typeof(InMemoryOrderRepositoryAdapter).FullName}.GetAll()");

            try
            {
                var result = new List <BusinessModels.Order>();

                IList <EntityModels.InMemory.Order> orderEntities = _orderRepository.GetAll();


                foreach (var orderEntity in orderEntities)
                {
                    EntityModels.InMemory.Inventory inventoryEntity = _inventoryRepository.GetById(orderEntity.InventoryId);
                    EntityModels.InMemory.Article   articleEntity   = _articleRepository.GetById(inventoryEntity.ArticleId);
                    EntityModels.InMemory.Buyer     buyerEntity     = _buyerRepository.GetById(orderEntity.BuyerId);

                    BusinessModels.Order order = CreateBusinessModel(orderEntity, articleEntity, inventoryEntity, buyerEntity);

                    result.Add(order);
                }

                return(result);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 private BusinessModels.Article CreateBusinessModel(EntityModels.InMemory.Article articleEntity)
 {
     return(new BusinessModels.Article()
     {
         Id = articleEntity.Id,
         EAN = articleEntity.EAN,
         Name = articleEntity.Name
     });
 }
Beispiel #6
0
        public IList <BusinessModels.Supplier> GetSuppliersWithArticleInInventory(string ean, double maxExpectedPrice)
        {
            _logger.LogInformation($"{typeof(InMemorySupplierRepositoryAdapter).FullName}.GetSuppliersWithArticleInInventory(ean={ean}, maxExpectedPrice={maxExpectedPrice})");

            try
            {
                EntityModels.InMemory.Article articleEntity = _articleRepository.GetByEan(ean);

                IList <BusinessModels.Supplier> result = new List <BusinessModels.Supplier>();

                if (articleEntity == null)
                {
                    return(result);
                }

                IList <EntityModels.InMemory.Inventory> inventoryItems = _inventoryRepository.GetAll(inv => inv.ArticleId == articleEntity.Id && inv.Quantity > 0 && inv.Price <= maxExpectedPrice);

                if (inventoryItems.Count == 0)
                {
                    return(result);
                }

                IList <EntityModels.InMemory.Supplier> suppliers = _supplierRepository.GetAll(sup => inventoryItems.Any(inv => inv.SupplierId == sup.Id));

                IList <EntityModels.InMemory.Article> articleEntities = new List <EntityModels.InMemory.Article>()
                {
                    articleEntity
                };

                foreach (var supplier in suppliers)
                {
                    var supplierInventoryItems = inventoryItems.Where(inv => inv.ArticleId == articleEntity.Id && inv.SupplierId == supplier.Id).ToList();

                    BusinessModels.Supplier supplierBusiness = CreateBusinessModel(supplier, articleEntities, supplierInventoryItems);

                    result.Add(supplierBusiness);
                }

                return(result);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
 private BusinessModels.Order CreateBusinessModel(EntityModels.InMemory.Order orderEntity, EntityModels.InMemory.Article articleEntity,
                                                  EntityModels.InMemory.Inventory inventoryEntity, EntityModels.InMemory.Buyer buyerEntity)
 {
     return(new BusinessModels.Order()
     {
         Id = orderEntity.Id,
         Article = new BusinessModels.Article()
         {
             Id = articleEntity.Id,
             EAN = articleEntity.EAN,
             InventoryId = inventoryEntity.Id,
             Name = articleEntity.Name,
             Price = inventoryEntity.Price,
             // Only 1 can be purchased
             Quantity = 1
         },
         Buyer = new BusinessModels.Buyer()
         {
             Id = buyerEntity.Id,
             Name = buyerEntity.Name
         },
         Date = orderEntity.DateSold
     });
 }