Esempio n. 1
0
        public Product CreateProduct(string number, string name, decimal price, int[] categories)
        {
            var culture = _cultureRepository.GetAll().FirstOrDefault(x => x.Name == CultureInfo.CurrentUICulture.Name);

            var product = new Product
            {
                CreatedDate = DateTime.UtcNow,
                Number = number,
                Price = price,
                Cultures = new List<ProductCulture> { new ProductCulture { CultureId = culture.Id, Name = name } },
                Categories = getSelectedCatgories(categories)
            };

            _productRepository.InsertOnCommit(product);
            _productRepository.CommitChanges();

            return product;
        }
Esempio n. 2
0
        void updateProductCultures(IEnumerable<ProductCulture> cultures, ref Product product)
        {
            var filteredCultures = (from x in cultures where x.Name != null select x);

            foreach (var productCulture in product.Cultures.ToList())
            {
                if (!filteredCultures.Any(x => x.CultureId == productCulture.CultureId))
                    product.Cultures.Remove(productCulture);
            }

            foreach (var productCulture in filteredCultures)
            {
                var found = product.Cultures.FirstOrDefault(x => x.CultureId == productCulture.CultureId);

                if (found != null)
                {
                    found.Name = productCulture.Name;
                }
                else
                {
                    product.Cultures.Add(new ProductCulture { CultureId = productCulture.CultureId, Name = productCulture.Name });
                }
            }
        }
Esempio n. 3
0
        void updateProductCategories(int[] categories, ref Product product)
        {
            var selectedCategories = getSelectedCatgories(categories);

            foreach (var category in product.Categories.ToList())
            {
                if (!selectedCategories.Contains(category))
                    product.Categories.Remove(category);
            }

            foreach (var category in selectedCategories)
            {
                if (!product.Categories.Contains(category))
                    product.Categories.Add(category);
            }
        }