Example #1
0
        public ActionResult UpdateCart(int Id, FormCollection fr)
        {
            var product = new ProductF().GetProductDetail(Id);

            var cart = (Cart)Session[Common.Session.CART_SESSION];

            if (cart != null)
            {
                int NewQuantity = int.Parse(fr["txtQuantity"].ToString());
                if (NewQuantity >= product.soLuong)
                {
                    ModelState.AddModelError("", "Không đủ số lượng"); return(RedirectToAction("Index", "Cart"));
                }
                else
                {
                    cart.UpdateItem(product, NewQuantity);
                    // Gán vào session
                    Session[Common.Session.CART_SESSION] = cart;
                }
            }
            else
            {
                //tạo mới đối tượng cart item
                cart = new Cart();
                cart.AddItem(product, 1);
                //Gán vào session
                Session[Common.Session.CART_SESSION] = cart;
            }
            return(RedirectToAction("Index"));
        }
Example #2
0
        public ActionResult Create()
        {
            IEnumerable <Product> model = new ProductF().accessDatabase;

            ViewBag.ProductID = new SelectList(model, "id", "Name");
            return(View());
        }
Example #3
0
        public ActionResult Edit(string id)
        {
            IEnumerable <Product> model = new ProductF().accessDatabase;

            ViewBag.ProductID = new SelectList(model, "id", "Name", id);
            return(View());
        }
Example #4
0
        // GET: AdminArea/Product
        public ActionResult Index(int page = 1, int pageSize = 5)
        {
            IEnumerable <Product> product = new ProductF().accessDatabase.OrderByDescending(x => x.Name).ToPagedList(page, pageSize);

            ViewBag.Model = product;
            return(View(product));
        }
Example #5
0
        public ActionResult Delete(Product product)
        {
            // phần xoá liên quan tới nhiều bảng khác anh em phải xoá các mấy bảng khác mới xoá được
            ProductF model = new ProductF();

            model.Delete(product.id);
            model.Save();
            return(RedirectToAction("Index", "ProductAdmin"));
        }
Example #6
0
        public ActionResult Edit(Image model)
        {
            if (ModelState.IsValid)
            {
                ProductImageF productImageF = new ProductImageF();
                productImageF.Update(model);
                return(RedirectToAction("Index", "PDAdmin"));
            }
            IEnumerable <Product> productList = new ProductF().accessDatabase;

            ViewBag.ProductID = new SelectList(productList, "id", "Name", model.id);
            return(View());
        }
Example #7
0
        public ActionResult Edit(Product model)
        {
            if (ModelState.IsValid)
            {
                ProductF productF = new ProductF();
                productF.Update(model);
                return(RedirectToAction("Index", "ProductAdmin"));
            }
            IEnumerable <Species> specieslist = new SpecciesF().accessDatabase;

            ViewBag.speciesID = new SelectList(specieslist, "id", "Name", model.id);
            return(View());
        }
Example #8
0
        public ActionResult Create(Product model)
        {
            ProductF productf = new ProductF();

            if (ModelState.IsValid)
            {
                productf.Insert(model);
                return(RedirectToAction("Index", "ProductAdmin"));
            }
            IEnumerable <Species> specieslist = new SpecciesF().accessDatabase;

            ViewBag.speciesID = new SelectList(specieslist, "id", "Name");
            return(View());
        }
Example #9
0
        // GET: /Cart/Details/5
        public JsonResult RemoveLine(int Id)
        {
            var product = new ProductF().FindEntity(Id);

            var cart = (Cart)Session[Common.Session.CART_SESSION];

            cart.RemoveLine(product);
            //Gán vào session
            Session[Common.Session.CART_SESSION] = cart;
            return(Json(new
            {
                status = true
            }));
        }
Example #10
0
        public ActionResult Create(ProductDetail model)
        {
            ProductDetailF productdetailf = new ProductDetailF();

            if (ModelState.IsValid)
            {
                productdetailf.Insert(model);
                return(RedirectToAction("Index", "PDAdmin"));
            }
            IEnumerable <Product> productlist = new ProductF().accessDatabase;

            ViewBag.ProductID = new SelectList(productlist, "id", "Name");
            return(View());
        }
        // GET: Product
        public ActionResult Index(int?GroupID, int?CategoryID, int?SupplierID, string search, int?page, int?NumberPage)
        {
            //  service.ListAll(
            List <Product> model = new ProductF().ProductSell.ToList();

            ViewBag.category   = CategoryID;
            ViewBag.Supplier   = SupplierID;
            ViewBag.group      = GroupID;
            ViewBag.numberpage = NumberPage;
            ViewBag.search     = search;

            if (CategoryID != null)
            {
                model = model.Where(p => p.IdCategories == CategoryID).ToList();
                Category category = new CategoryF().FindEntity(CategoryID.GetValueOrDefault(0));
                ViewBag.Parent = category.Name;
                ViewBag.ID     = CategoryID;
            }
            if (SupplierID != null)
            {
                model = model.Where(p => p.IdSuppnier == SupplierID).ToList();
                Supplier supplier = new SupplierF().FindEntity(SupplierID.GetValueOrDefault(0));
                ViewBag.Parent = supplier.Name;
                ViewBag.ID     = SupplierID;
            }
            if (GroupID != null)
            {
                List <Category> category = new CategoryF().Categorys.Where(p => p.IdGroup == GroupID).ToList();
                List <Product>  product  = new ProductF().ProductSell.ToList();
                model.Clear();
                foreach (var item in product)
                {
                    if (category.Exists(x => x.Id == item.IdCategories))
                    {
                        model.Add(new ProductF().FindEntity(item.Id));
                    }
                }

                ViewBag.Parent = new GroupF().FindEntity((int)GroupID).Name;
                ViewBag.ID     = GroupID;
            }
            if (search != null)
            {
                model = new ProductF().Products.Where(p => p.Name.Contains(search)).ToList();
                //model = client.ListAll().Where(p => p.Name.Contains(search)).ToList();
            }
            return(View(model.ToPagedList(page ?? 1, NumberPage ?? 6)));
        }
Example #12
0
        public PartialViewResult ProductList(Menu Parent)
        {
            ViewBag.menu = Parent;
            List <ProductCategory> category = new ProductCategoryF().ProductCategories.Where(x => x.ParentID == Parent.ID).ToList();
            List <Product>         product  = new ProductF().Products.ToList();
            List <Product>         model    = new List <Product>();

            foreach (Product item in product)
            {
                if (category.Exists(x => x.ID == item.CaterogyID))
                {
                    model.Add(new ProductF().FindEntity(item.ID));
                }
            }
            return(PartialView(model));
        }
Example #13
0
        public ActionResult Index(int?ParentID)
        {
            ViewBag.parentID = ParentID;
            List <ProductCategory> category = new ProductCategoryF().ProductCategories.Where(x => x.ParentID == ParentID).ToList();
            List <Product>         product  = new ProductF().Products.ToList();
            List <Product>         model    = new List <Product>();

            foreach (Product item in product)
            {
                if (category.Exists(x => x.ID == item.CaterogyID))
                {
                    model.Add(new ProductF().FindEntity(item.ID));
                }
            }
            return(View(model));
        }
Example #14
0
        public ActionResult AddItem(long productID, int quantity)
        {
            string url = "/Home/Index";

            try
            {
                url = System.Web.HttpContext.Current.Request.UrlReferrer.ToString();
            }
            catch { }
            var product = new ProductF().FindEntity(productID);
            var cart    = Session[Common.Session.CartSession];

            if (cart != null)
            {
                var      list = (List <CartItem>)cart;
                CartItem line = list.Where(l => l.Product.ID == productID).FirstOrDefault();
                if (line != null)
                {
                    line.Quantity += quantity;
                    if (line.Quantity <= 0)
                    {
                        Delete(line.Product.ID);
                    }
                }
                else
                {
                    var item = new CartItem();
                    item.Product  = product;
                    item.Quantity = quantity;
                    list.Add(item);
                }
                Session[Common.Session.CartSession] = list;
            }
            else
            {
                var item = new CartItem();
                item.Product  = new Product();
                item.Product  = product;
                item.Quantity = quantity;
                var list = new List <CartItem>();
                list.Add(item);
                //Gan vao session
                Session[Common.Session.CartSession] = list;
            }
            return(Redirect(url));
        }
 public ActionResult ChinhSuaSP(Product Pro)
 {
     if (ModelState.IsValid)
     {
         var  dao = new ProductF();
         bool id  = dao.Update(Pro);
         if (id)
         {
             return(RedirectToAction("ChiTietLoai", "QuanLySanPham", new { id = Pro.IdCategories }));
         }
         else
         {
             ModelState.AddModelError("", "Không thành công");
         }
     }
     ViewBag.l = db.Categories.Where(x => x.Id.Equals(Pro.IdCategories)).FirstOrDefault();
     return(View("ChiTietLoai"));
 }
        public ActionResult AddReview(string Status, int IdProduct)
        {
            Review re = new Review();

            re.Status = Status;
            Account acc = (Account)Session[Common.Session.USER_SESSION];

            re.Username  = acc.UserName;
            re.ProductID = IdProduct;
            re.date      = DateTime.Now;
            try
            {
                var id    = new ReviewF().Insert(re);
                var model = new ProductF().GetProductDetail(IdProduct);
                return(View("Productdetail", model));
            }
            catch { }
            return(View("Index", "Home"));
        }
        public ActionResult ThemSP(Product Pro)
        {
            ViewBag.IdSupplier = new SelectList(db.Suppliers.ToList().OrderBy(n => n.Id), "Id", "Name");

            if (ModelState.IsValid)
            {
                var dao = new ProductF();
                Pro.Id = -1;
                bool id = dao.Insert(Pro);
                if (id)
                {
                    return(RedirectToAction("ChiTietLoai", "QuanLySanPham", new { id = Pro.IdCategories }));
                }
                else
                {
                    ModelState.AddModelError("", "Them loại không thành công");
                }
            }
            ViewBag.l = db.Categories.Where(x => x.Id.Equals(Pro.IdCategories)).FirstOrDefault();
            return(View("ChiTietLoai"));
        }
Example #18
0
        public JsonResult AddItem(int Id)
        {
            string url = "/Home/Index";

            try
            {
                url = System.Web.HttpContext.Current.Request.UrlReferrer.ToString();
            }
            catch { }
            var product = new ProductF().GetProductDetail(Id);

            if (product.soLuong == 0)
            {
                return(Json(new
                {
                    status = false
                }));
            }

            var cart = (Cart)Session[Common.Session.CART_SESSION];

            if (cart != null)
            {
                cart.AddItem(product, 1);
                //Gán vào session
                Session[Common.Session.CART_SESSION] = cart;
            }
            else
            {
                //tạo mới đối tượng cart item
                cart = new Cart();
                cart.AddItem(product, 1);
                //Gán vào session
                Session[Common.Session.CART_SESSION] = cart;
            }
            return(Json(new
            {
                status = true
            }));
        }
Example #19
0
        public ActionResult AddCart(string productID, int quality)
        {
            var product = new ProductF().FindProduct(productID);
            var cart    = Session[CartSession];

            if (cart != null)
            {
                var list = (List <DetailBill>)cart;
                if (list.Exists(x => x.ProductID == productID))
                {
                    foreach (var item in list)
                    {
                        if (item.ProductID == productID)
                        {
                            item.quality += quality;
                        }
                    }
                }
                else
                {
                    var item = new DetailBill();
                    item.Product   = product;
                    item.ProductID = productID;
                    item.quality   = quality;
                    list.Add(item);
                }
                Session[CartSession] = list;
            }
            else
            {
                var item = new DetailBill();
                item.Product   = product;
                item.ProductID = productID;
                item.quality   = quality;
                var list = new List <DetailBill>();
                list.Add(item);
                Session[CartSession] = list;
            }
            return(Redirect("Index"));
        }
Example #20
0
        public ActionResult Index(int?Category, int?Brand, string OrderBy, decimal?PriceMin, decimal?PriceMax, int?page, int?NumberPage)
        {
            List <Product> model = new ProductF().Products.ToList();

            ViewBag.category   = Category;
            ViewBag.brand      = Brand;
            ViewBag.orderby    = OrderBy;
            ViewBag.pricemin   = PriceMin;
            ViewBag.pricemax   = PriceMax;
            ViewBag.numberpage = NumberPage;
            if (Category != null)
            {
                model = model.Where(x => x.CaterogyID == Category).ToList();
                ProductCategory category = new ProductCategoryF().FindEntity(Category.GetValueOrDefault(0));
                ViewBag.parentID = category.ParentID;
            }
            if (Brand != null)
            {
                model = model.Where(x => x.BrandID == Brand).ToList();
            }
            if (PriceMin != null && PriceMax != null)
            {
                model = model.Where(x => x.Price >= PriceMin && x.Price <= PriceMax).ToList();
            }
            if (OrderBy == "Name")
            {
                model = model.OrderBy(x => x.Name).ToList();
            }
            else if (OrderBy == "Price")
            {
                model = model.OrderBy(x => x.Price).ToList();
            }
            else
            {
                model = model.OrderBy(x => x.ID).ToList();
            }

            return(View(model.ToPagedList(page ?? 1, NumberPage ?? 3)));
        }
Example #21
0
        public ActionResult Detail(long ID)
        {
            var model = new ProductF().FindEntity(ID);

            return(View(model));
        }
Example #22
0
        public ActionResult Delete(string id)
        {
            Product product = new ProductF().FindProduct(id);

            return(View(product));
        }
        public ActionResult Productdetail(int id)
        {
            var model = new ProductF().GetProductDetail(id);

            return(View(model));
        }
        // GET: /Home/
        public ActionResult Index()
        {
            var model = new ProductF().Get();

            return(View(model));
        }