Exemplo n.º 1
0
        public IActionResult Products()
        {
            AddNewOrRef    modelobject = new AddNewOrRef();
            List <Product> AllProducts = _db.Products.ToList();

            modelobject.Products = AllProducts;
            return(View(modelobject));
        }
Exemplo n.º 2
0
        public IActionResult Categories()
        {
            AddNewOrRef     modelobject   = new AddNewOrRef();
            List <Category> AllCategories = _db.Categories.OrderByDescending(p => p.Name).ToList();

            modelobject.Categories = AllCategories;
            return(View(modelobject));
        }
Exemplo n.º 3
0
 public IActionResult AddToProduct(int id, AddNewOrRef formobject)
 {
     if (ModelState.IsValid && formobject.Relationship != null)
     {
         formobject.Relationship.ProductId = id;
         _db.Add(formobject.Relationship);
         _db.SaveChanges();
         return(RedirectToAction("Product", new { id = formobject.Relationship.ProductId }));
     }
     return(RedirectToAction("Products"));
 }
Exemplo n.º 4
0
        public IActionResult NewProduct(AddNewOrRef formobject)
        {
            if (ModelState.IsValid)
            {
                _db.Add(formobject.Product);
                _db.SaveChanges();
                return(RedirectToAction("Products"));
            }
            AddNewOrRef    modelobject = new AddNewOrRef();
            List <Product> AllProducts = _db.Products.OrderByDescending(p => p.Price).ToList();

            modelobject.Products = AllProducts;
            return(View("Products", modelobject));
        }
Exemplo n.º 5
0
        public IActionResult NewCategory(AddNewOrRef formobject)
        {
            if (ModelState.IsValid)
            {
                _db.Add(formobject.Category);
                _db.SaveChanges();
                return(RedirectToAction("Categories"));
            }
            AddNewOrRef     modelobject   = new AddNewOrRef();
            List <Category> AllCategories = _db.Categories.OrderByDescending(p => p.Name).ToList();

            modelobject.Categories = AllCategories;
            return(View("Categories", modelobject));
        }
Exemplo n.º 6
0
        public IActionResult Product(int id)
        {
            Product GetProductById = _db.Products
                                     .Include(c => c.Categories)
                                     .ThenInclude(pc => pc.Category)
                                     .FirstOrDefault(p => p.ProductId == id);

            if (GetProductById != null)
            {
                AddNewOrRef     modelobject  = new AddNewOrRef();
                List <Category> CategoryList = _db.Categories
                                               .Include(c => c.Products)
                                               .ThenInclude(pc => pc.Product)
                                               .Where(c => !c.Products.Any(p => p.ProductId == id))
                                               .ToList();
                modelobject.Categories = CategoryList;
                modelobject.Product    = GetProductById;
                return(View(modelobject));
            }
            return(RedirectToAction("Products"));
        }
Exemplo n.º 7
0
        public IActionResult Category(int id)
        {
            Category GetCategoryById = _db.Categories
                                       .Include(c => c.Products)
                                       .ThenInclude(pc => pc.Product)
                                       .FirstOrDefault(c => c.CategoryId == id);

            if (GetCategoryById != null)
            {
                AddNewOrRef    modelobject = new AddNewOrRef();
                List <Product> ProductList = _db.Products
                                             .Include(c => c.Categories)
                                             .ThenInclude(pc => pc.Category)
                                             .Where(p => !p.Categories.Any(c => c.CategoryId == id))
                                             .ToList();
                modelobject.Products = ProductList;
                modelobject.Category = GetCategoryById;
                return(View(modelobject));
            }
            return(RedirectToAction("Categories"));
        }