Exemplo n.º 1
0
        public ActionResult Delete(ProductsItemsAddViewModel item)
        {
            _context.Remove(item.Id);
            return(RedirectToAction("Index"));

            // return View();
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        { ///
            var product = _context.GetProduct(id);

            if (product != null)
            {
                ProductsItemsAddViewModel model = new ProductsItemsAddViewModel
                {
                    Name         = product.Name,
                    Discription  = product.Discription,
                    Price        = product.Price,
                    CategoryId   = product.Categories.Select(x => x.Id),
                    CategoryList = _context2.Get_All().Select
                                       (x => new SelectItemViewModel
                    {
                        Id   = x.Id,
                        Name = x.Name
                    }
                                       ).ToList()
                };

                return(View(model));
            }
            return(View());
        }
Exemplo n.º 3
0
 public ActionResult Edit(ProductsItemsAddViewModel item)
 {
     if (ModelState.IsValid)
     {
         _context.ChangeProduct(item);
         return(RedirectToAction("Index"));
     }
     return(View(item));
 }
Exemplo n.º 4
0
        public ActionResult Create()
        {
            ProductsItemsAddViewModel model = new ProductsItemsAddViewModel();

            model.CategoryList = _context2.Get_All()
                                 .Select(r => new SelectItemViewModel
            {
                Id   = r.Id,
                Name = r.Name
            }).ToList();
            return(View(model));
        }
Exemplo n.º 5
0
 public ActionResult Create(ProductsItemsAddViewModel item)
 {
     if (ModelState.IsValid)
     {
         _context.AddProduct(item);
         return(RedirectToAction("Index"));
     }
     else
     {
         item.CategoryList = _context2.Get_All()
                             .Select(r => new SelectItemViewModel
         {
             Id   = r.Id,
             Name = r.Name
         }).ToList();
     }
     return(View(item));
 }
Exemplo n.º 6
0
        public void ChangeProduct(ProductsItemsAddViewModel item)
        {
            var product = GetProduct(item.Id);

            if (product != null)
            {
                product.Name        = item.Name;
                product.Price       = item.Price;
                product.Discription = item.Discription;
                product.Categories.Clear();
                if (item.CategoryId != null)
                {
                    product.Categories = (from p in _context.eCategories where item.CategoryId.Contains(p.Id) select p).ToList();
                }
                product.LastChange = DateTime.Now;
                SaveChange();
            }
        }
Exemplo n.º 7
0
        public EProducts AddProduct(ProductsItemsAddViewModel item)
        {
            EProducts product = new EProducts
            {
                Name        = item.Name,
                Discription = item.Discription,
                Price       = item.Price
            };

            if (item.CategoryId != null)
            {
                var category = (from p in _context.eCategories where item.CategoryId.Contains(p.Id) select p).ToList();
                if (category != null)
                {
                    product.Categories = category;
                }
            }


            _context.eProducts.Add(product);
            _context.SaveChanges();
            return(product);
        }