Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public BusinessModels.Buyer GetById(long id)
        {
            _logger.LogInformation($"{typeof(InMemoryBuyerRepositoryAdapter).FullName}.GetById({id})");

            try
            {
                EntityModels.InMemory.Buyer buyerEntity = _buyerRepository.GetById(id);

                BusinessModels.Buyer buyer = null;

                if (buyerEntity != null)
                {
                    buyer = CreateBusinessModel(buyerEntity);
                }

                return(buyer);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Exemplo n.º 4
0
 private BusinessModels.Buyer CreateBusinessModel(EntityModels.InMemory.Buyer buyerEntity)
 {
     return(new BusinessModels.Buyer()
     {
         Id = buyerEntity.Id,
         Name = buyerEntity.Name
     });
 }
Exemplo n.º 5
0
        public void Update(BusinessModels.Buyer buyer)
        {
            _logger.LogInformation($"{typeof(InMemoryBuyerRepositoryAdapter).FullName}.Update({buyer.Id})");

            try
            {
                EntityModels.InMemory.Buyer buyerEntity = CreateEntityModel(buyer);

                _buyerRepository.Update(buyerEntity);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Exemplo n.º 6
0
        public BusinessModels.Buyer Insert(BusinessModels.Buyer buyer)
        {
            _logger.LogInformation($"{typeof(InMemoryBuyerRepositoryAdapter).FullName}.Insert({buyer.Name})");

            try
            {
                EntityModels.InMemory.Buyer buyerEntity = CreateEntityModel(buyer);

                buyerEntity = _buyerRepository.Insert(buyerEntity);

                buyer.Id = buyerEntity.Id;

                return(buyer);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Exemplo n.º 7
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
     });
 }