// GET: Category
        public ActionResult Index()
        {
            CatProdDAO           cdao = new CatProdDAO();
            IList <ProdCategory> cat  = cdao.CategoryList();

            ViewBag.Categorys = cat;
            return(View());
        }
Example #2
0
        public ActionResult Index()
        {
            ProductDAO      pdao = new ProductDAO();
            IList <Product> prod = pdao.ProductList();

            ViewBag.Products = prod;
            CatProdDAO           cdao = new CatProdDAO();
            IList <ProdCategory> cat  = cdao.CategoryList();

            ViewBag.Categorys = cat;
            return(View());
        }
Example #3
0
        public ActionResult Details(int Id)
        {
            ProductDAO           pdao = new ProductDAO();
            CatProdDAO           cdao = new CatProdDAO();
            IList <ProdCategory> cat  = cdao.CategoryList();
            Product      p            = pdao.FindById(Convert.ToInt32(Id));
            ProdCategory catid        = cdao.FindById(Convert.ToInt32(p.CategoryId));

            ViewBag.CatId  = catid;
            ViewBag.ProdId = p;
            return(View());
        }
Example #4
0
        public ActionResult FormUp(string id)
        {
            ProductDAO           pdao = new ProductDAO();
            CatProdDAO           cdao = new CatProdDAO();
            IList <ProdCategory> cat  = cdao.CategoryList();

            ViewBag.Categorys = cat;
            Product prod = pdao.FindById(Convert.ToInt32(id));

            ViewBag.ProdId = prod;
            ProdCategory catid = cdao.FindById(Convert.ToInt32(prod.CategoryId));

            ViewBag.CatId = catid;
            return(View());
        }
Example #5
0
        public ActionResult Update(Product p)   //string id, string name, string description, float price, int quantity, int category
        {
            ProductDAO           pdao = new ProductDAO();
            CatProdDAO           cdao = new CatProdDAO();
            IList <ProdCategory> cat  = cdao.CategoryList();

            ViewBag.Categorys = cat;
            Product prod = pdao.FindById(Convert.ToInt32(p.Id));

            prod.Name        = p.Name;
            prod.Description = p.Description;
            prod.CategoryId  = p.CategoryId;
            prod.Price       = p.Price;
            prod.Quantity    = p.Quantity;
            pdao.Update();
            return(RedirectToAction("Index"));
        }
Example #6
0
        public ActionResult Add(Product p)
        {
            ProductDAO pdao = new ProductDAO();

            if (p.CategoryId.Equals(1) && p.Price < 20000)
            {
                ModelState.AddModelError("p.SUVPrice", "The SUV price must be higher than $20k");
            }
            if (ModelState.IsValid)
            {
                pdao.Insert(p);
                return(RedirectToAction("Index"));
            }
            else
            {
                CatProdDAO cdao = new CatProdDAO();
                ViewBag.Categorys = cdao.CategoryList();
                ViewBag.Class     = "alert alert-danger";
                return(View("frmAdd"));
            }
        }