Esempio n. 1
0
        private static Product NewProduct(string enterpriseId,bool modified)
        {
            var product = new Product
            {
                Id = ProductHelper.GenerateId(),
                Enterprise = enterpriseId,
                Name = RandomString(),
                Prices = new List<ProductPrice>()
            };

            if (RandomBool())
                product.Description = RandomString();

            var productPrices = new List<ProductPrice>();
            for (var k = 0; k < _random.Next(1, 4); k++)
            {
                var productPrice = new ProductPrice { Price = RandomNumber() };
                if (RandomBool())
                    productPrice.Description = RandomString();

                productPrices.Add(productPrice);
            }

            product.Prices = productPrices;

            if (modified)
            {
                if (RandomBool())
                {
                    Mapper.CreateMap<Product, ProductUpdatedVersion>();
                    var updatedProduct = new ProductUpdatedVersion();
                    Mapper.Map(product, updatedProduct);
                    updatedProduct.Description = RandomString();
                    product.UpdatedVersion = updatedProduct;
                }
            }

            return product;
        }
Esempio n. 2
0
        public void UpdateProduct(Product product, string enterpriseId)
        {
            using (var session = _documentStore.OpenSession())
            {
                var enterprise = session.Load<Enterprise>(enterpriseId);

                if (EnterpriseHelper.ValidEditableEnterprise(enterprise, session))
                {
                    //Om det är en ny enterprise eller en som är ägd, spara produkten direkt
                    if (enterprise.IsNew || enterprise.OwnedByAccount)
                    {
                        session.Store(product);
                    }
                    else
                    {
                        if (product.Enterprise == enterpriseId)
                        {
                            //If enterprise is existing, save an updated version of the product for approvement
                            var productInDb = session.Load<Product>(product.Id);
                            Mapper.CreateMap<Product, ProductUpdatedVersion>();
                            var updatedProduct = new ProductUpdatedVersion();
                            Mapper.Map(product, updatedProduct);
                            productInDb.UpdatedVersion = updatedProduct;
                        }
                        else
                        {
                            _logger.Warn(string.Format("Product: {0} belongs to this enterprise: {1} and was about to be updated to {2} Code:[hT882v563]", product.Id, product.Enterprise, enterpriseId));
                        }
                    }
                    _logger.Info(string.Format("Product:{0} was updated. Enterprise: {1}. Code:[poO0789b]",product.Id,enterpriseId));
                    session.SaveChanges();
                }
            }
        }