Exemplo n.º 1
0
        public IActionResult Add(Product product)
        {
            int productGroupId;

            if (Int32.TryParse(Request.Form["productGroup"].ToString(), out productGroupId))
            {
                product.ProductGroup = _productGroupLogic.Read(new ProductGroup {
                    Id = productGroupId
                }).First();
            }

            if (product.ProductGroup == null)
            {
                ModelState.AddModelError("ProductGroup", "Необходимо выбрать категорию товара.");
            }

            if (ModelState.IsValid)
            {
                _productLogic.CreateOrUpdate(product);
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.ProductGroups = GetProductGroups(product.ProductGroup != null ? product.ProductGroup.Id.Value : 1);
                return(View("Product", product));
            }
        }
        public IActionResult Index()
        {
            var productGroups = _productGroupLogic.Read(null);
            var productPrices = new Dictionary <Product, double>();

            foreach (var productGroup in productGroups)
            {
                foreach (var product in productGroup.Products)
                {
                    productPrices.Add(product, Math.Round(productGroup.Products.Average(rec => rec.Price), 2));
                }
            }

            ViewBag.ProductPrices = productPrices;

            return(View(productGroups));
        }
Exemplo n.º 3
0
        public IActionResult AddPG(Supplier supplier)
        {
            int productGroupId;

            if (Int32.TryParse(Request.Form["productGroup"].ToString(), out productGroupId))
            {
                supplier.ProductGroups = new List <ProductGroup>();
                supplier.ProductGroups.Add(_productGroupLogic.Read(new ProductGroup {
                    Id = productGroupId
                }).First());
            }

            if (ModelState.IsValid)
            {
                _supplierLogic.CreateOrUpdate(supplier);
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.ProductGroups = GetProductGroups(null);
                return(View("AddPG", supplier));
            }
        }
Exemplo n.º 4
0
        public IActionResult Index()
        {
            var productGroups = _productGroupLogic.Read(null);

            return(View(productGroups));
        }