Exemple #1
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);
        }
Exemple #2
0
        public BusinessModels.Supplier GetById(long id)
        {
            _logger.LogInformation($"{typeof(InMemorySupplierRepositoryAdapter).FullName}.GetById({id})");

            try
            {
                EntityModels.InMemory.Supplier supplierEntity = _supplierRepository.GetById(id);
                BusinessModels.Supplier        result         = null;

                if (supplierEntity != null)
                {
                    IList <EntityModels.InMemory.Inventory> inventory = _inventoryRepository.GetAll(inv => inv.SupplierId == id);
                    IList <EntityModels.InMemory.Article>   articles  = _articleRepository.GetAll(art => inventory.Any(inv => inv.ArticleId == art.Id));

                    result = CreateBusinessModel(supplierEntity, articles, inventory);
                }

                return(result);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Exemple #3
0
        public void Update(BusinessModels.Supplier supplier)
        {
            _logger.LogInformation($"{typeof(InMemorySupplierRepositoryAdapter).FullName}.Update({supplier.Id})");

            try
            {
                EntityModels.InMemory.Supplier supplierEntity = CreateEntityModel(supplier);

                _supplierRepository.Update(supplierEntity);
            }
            catch (LoggedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new LoggedException("Logged exception", ex);
            }
        }
Exemple #4
0
        public BusinessModels.Supplier Insert(BusinessModels.Supplier supplier)
        {
            _logger.LogInformation($"{typeof(InMemorySupplierRepositoryAdapter).FullName}.Insert({supplier.Name})");

            try
            {
                EntityModels.InMemory.Supplier supplierEntity = CreateEntityModel(supplier);

                supplierEntity = _supplierRepository.Insert(supplierEntity);

                supplier.Id = supplierEntity.Id;

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