Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        public void Update(BusinessModels.Order order)
        {
            _logger.LogInformation($"{typeof(InMemoryOrderRepositoryAdapter).FullName}.Update({order.Id})");

            try
            {
                EntityModels.InMemory.Order orderEntity = CreateEntityModel(order);

                _orderRepository.Update(orderEntity);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Ejemplo n.º 3
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
     });
 }
Ejemplo n.º 4
0
        public BusinessModels.Order Insert(BusinessModels.Order order)
        {
            _logger.LogInformation($"{typeof(InMemoryOrderRepositoryAdapter).FullName}.Insert(ArticleId={order.Article.Id}, BuyerId={order.Buyer.Id})");

            try
            {
                EntityModels.InMemory.Order orderEntity = CreateEntityModel(order);

                orderEntity = _orderRepository.Insert(orderEntity);

                order.Id = orderEntity.Id;

                return(order);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }