Exemplo n.º 1
0
        public List <ProductViewModel> GetListProduct(string name = "", long?masp = null, bool?status = null, int?CategoryID = null, int?minQ = null, int?maxQ = null)
        {
            List <Product>         products = db.Products.ToList();
            List <ProductCategory> groups   = db.ProductCategories.ToList();
            var productViewModel            = from u in products
                                              join g in groups
                                              on u.CategoryID equals g.ID
                                              select new ProductViewModel
            {
                product  = u,
                category = g,
            };

            if (!String.IsNullOrEmpty(name))
            {
                productViewModel = productViewModel.Where(x => x.product.Name.Contains(name));
            }

            if (masp != null)
            {
                productViewModel = productViewModel.Where(x => x.product.ID == masp);
            }



            if (status != null)
            {
                productViewModel = productViewModel.Where(x => x.product.Status == status);
            }


            if (CategoryID != null)
            {
                var cateDao = new ProductCategoryDao();
                var cate    = cateDao.ViewDetail(CategoryID.Value);
                if (cate.ParentID != null)
                {
                    productViewModel = productViewModel.Where(x => x.category.ID == CategoryID);
                }
                else
                {
                    productViewModel = productViewModel.Where(x => x.category.ParentID == CategoryID);
                }
            }

            if (minQ != null && maxQ != null)
            {
                productViewModel = productViewModel.Where(x => x.product.Quantity >= minQ && x.product.Quantity <= maxQ);
            }



            return(productViewModel.OrderBy(x => x.product.CreatedDate).ToList());
        }
 public ActionResult Edit(ProductCategory model)
 {
     try
     {
         // TODO: Add update logic here
         var dao = new ProductCategoryDao();
         dao.Update(model);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
        public ActionResult Create(ProductCategory model)
        {
            try
            {
                // TODO: Add insert logic here
                var dao = new ProductCategoryDao();
                var result = dao.Insert(model);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
 // GET: Admin/ProductCategory
 public ActionResult Index()
 {
     var dao = new ProductCategoryDao();
     var model = dao.ListAll();
     return View(model);
 }
 // GET: Admin/ProductCategory/Edit/5
 public ActionResult Edit(long id)
 {
     var dao = new ProductCategoryDao();
     var model = dao.ViewDetail(id);
     return View(model);
 }
 public PartialViewResult ProductCategory()
 {
     var model = new ProductCategoryDao().ListAll();
     return PartialView(model);
 }