Ejemplo n.º 1
0
        public ActionResult DeleteProduct(string id)
        {
            using (var db = new CartEntities())
            {
                var p = db.Categories.FirstOrDefault(e => e.catid.Equals(id));
                if (p != null)
                {
                    p.deleflag = true;
                    db.SaveChanges();
                }
            }

            return RedirectToAction("Index");
        }
Ejemplo n.º 2
0
        public ActionResult DatHangCF(FormCollection f)
        {
            if (Session["ShoppingCart"] != null)
            {
                //Lấy list sản phẩm trong giỏ hàng hiện tại
                List<OrderItem> lsProduct = Session["ShoppingCart"] as List<OrderItem>;
                var name = f["name"];
                var mail = f["mail"];
                var addr = f["addr"];
                var phone = f["phone"];
                var date = String.Format("{0:dd/MM/yyyy}", DateTime.Now);
                decimal total = 0;
                decimal.TryParse(f["total"], out total);
                Order p = new Order()
                {
                    orderdate = date,
                    email = mail,
                    subtotal = total,
                    salestax = 0,
                    shipping = 0,
                    name = name,
                    addr = addr,
                    phone = phone,
                    trangthai="Chưa xử lý"
                };

                using (var db = new CartEntities())
                {
                    db.Orders.Add(p);
                    db.SaveChanges();

                }
                foreach (OrderItem item in lsProduct)
                {
                    OrderItem oi = new OrderItem();
                    oi.ordernum = p.ordernum;

                    oi.productid = item.productid;
                    oi.name = item.name;
                    oi.price = item.price;
                    oi.image = item.image;
                    oi.quantity = item.quantity;
                    db.OrderItems.Add(oi);
                    db.SaveChanges();
                }
                Session["ShoppingCart"] = null;
                return RedirectToAction("Index","Home");
            }
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 3
0
        public ActionResult Search( int? page,String str)
        {
            ViewBag.TuKhoa = str;
            //slider
            using (var db = new CartEntities())
            {
                ViewBag.Slider = db.baners.OrderBy(e => Guid.NewGuid()).Take(4).ToList();
                ViewBag.TopProduct = db.Products.OrderBy(e => Guid.NewGuid()).Where(e => e.deleflag == false).Take(12).ToList();
            }

            List<Product> lstSanPham = db.Products.Where(p => p.name.Contains(str)).ToList();
            ViewBag.serchcount = lstSanPham.Count();
            // phan trang
            int pageNumber = (page ?? 1);
            int pageSize = 3;
            return View(lstSanPham.ToPagedList(pageNumber, pageSize));
        }
Ejemplo n.º 4
0
        public ActionResult SaveData(Category t)
        {
            if (t != null) {
                Category p = new Category()
                {
                    catid = t.catid,
                    name = t.name,
                    desc = t.desc,
                };
                using (var db = new CartEntities())
                {
                    db.Categories.Add(p);
                    db.SaveChanges();
                }
            }

            return RedirectToAction("Index");
        }
Ejemplo n.º 5
0
        public ActionResult UpdateProduct(FormCollection f)
        {
            var id = f["editcode"];
            var name = f["editname"];
            var desc = f["editdesc"];

            CartEntities db = new CartEntities();
            var p = db.Categories.FirstOrDefault(e => e.catid.Equals(id));
            p.name = name;
            p.desc = desc;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
Ejemplo n.º 6
0
        public ActionResult UpdateProduct(FormCollection f)
        {
            int kt = 0;
            var type = f["type"];
            var category = f["editcategories"];
            var id = f["editcode"];
            var name = f["editname"];

            decimal price = 0;
            decimal.TryParse(f["editprice"], out price);
            var sizes = f["editsize"];
            var fileName = "";
            var fl = f["editfile"];

            if (type == "Create")
            {

                if (db.Products.Find(id) == null)
                {
                    if (Request.Files["editfile"] != null && Request.Files["editfile"].ContentLength > 0)
                    {
                        fileName = Path.GetFileName(Request.Files["editfile"].FileName);
                        // store the file inside ~/App_Data/uploads folder
                        var path = Path.Combine(Server.MapPath("~/Resource/images/"), fileName);
                        Request.Files["editfile"].SaveAs(path);
                    }

                    Product p = new Product()
                    {
                        catid = category,
                        productid = id,
                        name = name,
                        price = price,
                        size = sizes,
                        thumbnail = fileName,
                        image = fileName,
                        shorttext = "",
                        longtext = "",
                        deleflag = false
                    };

                    using (var db = new CartEntities())
                    {
                        db.Products.Add(p);
                        db.SaveChanges();
                        kt = 1;
                    }
                }
                else ViewBag.mes = "Sản Phẩm đã tồn tại";

            }
            else if (type == "Update")
            {

                CartEntities db = new CartEntities();
                var p = db.Products.FirstOrDefault(e => e.productid.Equals(id));
                p.name = name;
                p.catid = category;
                p.size = sizes;
                p.price = price;

                if (Request.Files["editfile"] != null && Request.Files["editfile"].ContentLength > 0)
                {
                    fileName = Path.GetFileName(Request.Files["editfile"].FileName);
                    // store the file inside ~/App_Data/uploads folder
                    var path = Path.Combine(Server.MapPath("~/Resource/images/"), fileName);

                    p.image = fileName;
                    p.thumbnail = fileName;
                    db.SaveChanges();
                    Request.Files["editfile"].SaveAs(path);
                }
                else
                {
                    db.SaveChanges();
                    kt = 1;
                }
            }
            return RedirectToAction("Index");
        }
Ejemplo n.º 7
0
 public ActionResult Index()
 {
     using (var db = new CartEntities())
     {
         ViewBag.Slider = db.baners.OrderBy(e => Guid.NewGuid()).Take(4).ToList();
         ViewBag.TopProduct = db.Products.OrderBy(e => Guid.NewGuid()).Where(e => e.deleflag == false).Take(12).ToList();
     }
     return View();
 }