Пример #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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public void IncreaseArticleQuantity(long inventoryId)
        {
            _logger.LogInformation($"{typeof(InMemorySupplierRepositoryAdapter).FullName}.IncreaseArticleQuantity(inventoryId={inventoryId})");

            try
            {
                EntityModels.InMemory.Inventory inventoryEntity = _inventoryRepository.GetById(inventoryId);
                inventoryEntity.Quantity++;
                _inventoryRepository.Update(inventoryEntity);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Пример #5
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
     });
 }