Пример #1
0
        public ActionResult addProduct(Product model, HttpPostedFileBase fuMain, HttpPostedFileBase fuThumbs)
        {
            using (QLBHEntities ctx = new QLBHEntities())
            {
                if (string.IsNullOrEmpty(model.TinyDes)) model.TinyDes = string.Empty;
                if (string.IsNullOrEmpty(model.FullDes)) model.FullDes = string.Empty;

                ctx.Products.Add(model);
                ctx.SaveChanges();

                var list = ctx.Categories.ToList();
                var list2 = ctx.TypeProducts.ToList();

                ViewBag.TypeProduct = list2;
                ViewBag.Categories = list;
            }
            if (fuMain != null && fuMain.ContentLength > 0 && fuThumbs != null && fuThumbs.ContentLength > 0)
            {
                //tao folder chua hinh [~/Imgs/sp/{ID}]
                string spDirPath = Server.MapPath("~/Imgs/sp");
                string targetDirPath = Path.Combine(spDirPath, model.ProID.ToString());
                Directory.CreateDirectory(targetDirPath);

                //copy hinh len
                string mainFileName = Path.Combine(targetDirPath, "main.jpg");
                fuMain.SaveAs(mainFileName);

                string thumbsFileName = Path.Combine(targetDirPath, "main_thumbs.jpg");
                fuThumbs.SaveAs(thumbsFileName);

            }
            ViewBag.Added = true;
            return View();
        }
Пример #2
0
        //
        // GET: /Product/byType/{id, page}
        public ActionResult byType(int? id, int page = 1)
        {
            if (id.HasValue == false)
            {
                return RedirectToAction("Index", "Home");
            }

            int pageSz = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);

            using (QLBHEntities ctx = new QLBHEntities())
            {
                var query = ctx.Products.Where(p => p.TypeID == id);
                int count = query.Count();
                int nPages = count / pageSz + (count % pageSz > 0 ? 1 : 0);

                List<Product> list = query.OrderBy(p => p.ProID).Skip((page - 1) * pageSz).Take(pageSz).ToList();

                ViewBag.TypeName = list.First().TypeProduct.TypeName;
                ViewBag.CurPage = page;
                ViewBag.PageCount = nPages;
                ViewBag.TypeId = id;

                return View(list);
            }
        }
Пример #3
0
        public ActionResult changePWD_UsProfile(string PWD, string NewPWD)
        {
            int id = CurrentContext.GetCurUser().f_ID;
            string enc_pwd = StringUtils.MD5(PWD);
            string enc_newpwd = StringUtils.MD5(NewPWD);

            using (QLBHEntities ctx = new QLBHEntities())
            {
                int n = ctx.Users.Where(u => u.f_ID == id && u.f_Password == enc_pwd).Count();

                if (n == 0)
                {
                    notify = "fail";
                    RedirectToAction("UsProfile", "Account");
                }
                else
                {
                    User us = ctx.Users.Where(u => u.f_ID == id).First();

                    us.f_Password = enc_newpwd;
                    ctx.SaveChanges();

                    notify = "success";
                }
                return RedirectToAction("UsProfile", "Account");
            }
        }
        //
        // GET: /TypeProductAdmin/
        public ActionResult Index()
        {
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.TypeProducts.ToList();

                return View(list);
            }
        }
Пример #5
0
        //
        // GET: /TypeProduct/getAll
        public ActionResult getAll()
        {
            using(QLBHEntities ctx = new QLBHEntities())
            {
                List<TypeProduct> list = ctx.TypeProducts.ToList();

                return PartialView(list);
            }
        }
Пример #6
0
        //
        //GET: /Product/BestViewProduct
        public ActionResult BestViewProduct()
        {
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.Products.OrderByDescending(p => p.PageView).Take(5).ToList();

                return PartialView(list);
            }
        }
Пример #7
0
        //
        // GET: /Category/getAll
        public ActionResult getAll()
        {
            using (QLBHEntities ctx = new QLBHEntities())
            {
                List<Category> list = ctx.Categories.ToList();

                //ViewBag.CategoryList = list;
                return PartialView(list);
            }
        }
        public ActionResult addType(string typeName)
        {
            TypeProduct type = new TypeProduct { TypeName = typeName };
            using (QLBHEntities ctx = new QLBHEntities())
            {
                ctx.TypeProducts.Add(type);
                ctx.SaveChanges();

                return RedirectToAction("Index", "TypeProductAdmin");
            }
        }
Пример #9
0
 public ActionResult admin_Dashboard()
 {
     using (QLBHEntities ctx = new QLBHEntities())
     {
         ViewBag.CountCat = ctx.Categories.Count().ToString();
         ViewBag.CountPro = ctx.Products.Count().ToString();
         ViewBag.CountOrder = ctx.Orders.Count().ToString();
         ViewBag.CountType = ctx.TypeProducts.Count().ToString();
     }
     return View();
 }
Пример #10
0
        public ActionResult addCat(string catName)
        {
            Category cat = new Category { CatName = catName };
            using (QLBHEntities ctx = new QLBHEntities())
            {
                ctx.Categories.Add(cat);
                ctx.SaveChanges();

                return RedirectToAction("getAll", "CategoryAdmin");
            }
        }
Пример #11
0
        //
        // GET: /Order/
        public ActionResult Index()
        {
            int total = 0;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.Orders.Include("User").ToList();
                total = list.Count();

                ViewBag.Total = total;
                return View(list);
            }
        }
Пример #12
0
        //
        //GET: /ProductAdmin/addProduct
        public ActionResult addProduct()
        {
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.Categories.ToList();
                var list2 = ctx.TypeProducts.ToList();

                ViewBag.TypeProduct = list2;
                ViewBag.Categories = list;
                return View();
            }
        }
Пример #13
0
        //
        // GET: /Home/findPro/{keyword, findby, page}
        public ActionResult findPro(string keyword, string findby, int page = 1)
        {
            if (string.IsNullOrEmpty(keyword))
            {
                return RedirectToAction("Index", "Home");
            }
            List<Product> list = null;
            int pageSz = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
            using (QLBHEntities ctx = new QLBHEntities())
            {
                List<Product> temp = null;
                var query = ctx.Products.Include("Category").Include("TypeProduct");

                switch (findby)
                    {
                        case "0":
                            temp = query.Where(p => p.Category.CatName.Contains(keyword) || p.TypeProduct.TypeName.Contains(keyword) || p.Origin.Contains(keyword) || p.ProName.Contains(keyword)).ToList();
                            break;
                        case "1":
                            temp = query.Where(p => p.Category.CatName.Contains(keyword)).ToList();
                            break;
                        case "2":
                            temp = query.Where(p => p.TypeProduct.TypeName.Contains(keyword)).ToList();
                            break;
                        case "3":
                            temp = query.Where(p => p.Origin.Contains(keyword)).ToList();
                            break;
                        case "4":
                            temp = query.Where(p => p.ProName.Contains(keyword) && p.Price < 10000000).ToList();
                            break;
                        case "5":
                            temp = query.Where(p => p.ProName.Contains(keyword) && p.Price > 10000000 && p.Price < 20000000).ToList();
                            break;
                        case "6":
                            temp = query.Where(p => p.ProName.Contains(keyword) && p.Price > 20000000 && p.Price < 30000000).ToList();
                            break;
                        case "7":
                            temp = query.Where(p => p.ProName.Contains(keyword) && p.Price > 30000000).ToList();
                            break;
                        default:
                            goto case "0";
                    }
                int count = temp.Count();
                int nPages = count / pageSz + (count % pageSz > 0 ? 1 : 0);
                list = temp.OrderBy(p => p.ProID).Skip((page - 1) * pageSz).Take(pageSz).ToList();
                    ViewBag.CurPage = page;
                    ViewBag.PageCount = nPages;
                    ViewBag.KeyWord = keyword;
                    ViewBag.FindBy = findby;
            }
            return View(list);
        }
Пример #14
0
 //
 //POSt: /Order/updateOrder
 public ActionResult updateOrder(int id, int sttOrder)
 {
     using (QLBHEntities ctx = new QLBHEntities())
     {
         var order = ctx.Orders.Where(c => c.OrderID == id).First();
         if (order != null)
         {
             order.Status = sttOrder;
             ctx.SaveChanges();
         }
     }
     return RedirectToAction("Index","Order");
 }
Пример #15
0
 public ActionResult changeProfile_UsProfile(string FullName, string Email, string DOB)
 {
     int id = CurrentContext.GetCurUser().f_ID;
     using (QLBHEntities ctx = new QLBHEntities())
     {
         User us = ctx.Users.Where(u => u.f_ID == id).First();
         us.f_DOB = DateTime.ParseExact(DOB, "d/M/yyyy", null);
         us.f_Name = FullName;
         us.f_Email = Email;
         ctx.SaveChanges();
         notify = "success";
     }
     return RedirectToAction("UsProfile", "Account");
 }
Пример #16
0
        //
        // GET: /OrderDetail/
        public ActionResult Index(int id)
        {
            decimal total = 0;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.OrderDetails.Include("Product").Where(o => o.OrderID == id).ToList();
                foreach (OrderDetail o in list)
                {
                    total += o.Price * o.Quantity;
                }

                ViewBag.Total = total;
                return View(list);
            }
        }
Пример #17
0
        public ActionResult updateCat(int id, string name)
        {
            bool status = false;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                Category cat = ctx.Categories.Where(c => c.CatID == id).First();
                if (cat != null)
                {
                    cat.CatName = name;
                    ctx.SaveChanges();
                    status = true;
                }

                return Json(status);
            }
        }
Пример #18
0
        public ActionResult delPro(int id)
        {
            bool status = false;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                Product pro = ctx.Products.Where(p => p.ProID == id).First();
                if (pro != null)
                {
                    ctx.Products.Remove(pro);
                    ctx.SaveChanges();
                    status = true;
                }

                return Json(status);
            }
        }
Пример #19
0
        public ActionResult delOrder(int id)
        {
            bool status = false;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                Order order = ctx.Orders.Where(c => c.OrderID == id).First();
                if (order != null)
                {
                    ctx.Orders.Remove(order);
                    ctx.SaveChanges();
                    status = true;
                }

                return Json(status);
            }
        }
        public ActionResult updateType(int id, string name)
        {
            bool status = false;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var type = ctx.TypeProducts.Where(c => c.TypeID == id).First();
                if (type != null)
                {
                    type.TypeName = name;
                    ctx.SaveChanges();
                    status = true;
                }

                return Json(status);
            }
        }
Пример #21
0
        public ActionResult AddToCart(CartItem item)
        {
            int cartItemQuantity = CurrentContext.GetCart().getQuantityPro(item.ProID);
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var pro = ctx.Products.Where(p => p.ProID == item.ProID).First();

                if (pro.Quantity >= (item.Quantity + cartItemQuantity))
                {
                    CurrentContext.GetCart().Add(item);
                    return RedirectToAction("Detail", "Product", new { id = item.ProID });
                }
                else
                {
                    Session["Error"] = "Loi";
                    return RedirectToAction("Detail", "Product", new { id = item.ProID });
                }
            }
        }
        public ActionResult delType(int id)
        {
            bool status = false;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.Products.Where(p => p.TypeID == id).ToList();
                foreach (Product p in list)
                {
                    ctx.Products.Remove(p);
                }
                var type = ctx.TypeProducts.Where(c => c.TypeID == id).First();
                if (type != null)
                {
                    ctx.TypeProducts.Remove(type);
                    ctx.SaveChanges();
                    status = true;
                }

                return Json(status);
            }
        }
Пример #23
0
        public ActionResult delCat(int id)
        {
            bool status = false;
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.Products.Where(p => p.CatID == id).ToList();
                foreach (Product p in list)
                {
                    ctx.Products.Remove(p);
                }
                Category cat = ctx.Categories.Where(c => c.CatID == id).First();
                if (cat != null)
                {
                    ctx.Categories.Remove(cat);
                    ctx.SaveChanges();
                    status = true;
                }

                return Json(status);
            }
        }
Пример #24
0
        public ActionResult Add1ToCart(int id)
        {
            CartItem item = new CartItem();
            item.ProID = id;
            item.Quantity = 1;
            int cartItemQuantity = CurrentContext.GetCart().getQuantityPro(item.ProID);
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var pro = ctx.Products.Where(p => p.ProID == item.ProID).First();

                if (pro.Quantity >= (item.Quantity + cartItemQuantity))
                {
                    CurrentContext.GetCart().Add(item);
                }
                else
                {
                    Session["Error"] = "Loi";
                }
            }
            int numberItem = CurrentContext.GetCart().GetNumberOfItem();
            return Json(numberItem);
        }
Пример #25
0
        public ActionResult CheckOut(decimal total)
        {
            Order ord = new Order
            {
                OrderDate = DateTime.Now,
                UserID = CurrentContext.GetCurUser().f_ID,
                Total = total,
                Status = 0
            };
            using (QLBHEntities ctx = new QLBHEntities())
            {
                foreach (CartItem item in CurrentContext.GetCart().Items)
                {
                    Product pro = ctx.Products.Where(p => p.ProID == item.ProID).FirstOrDefault();
                    if (pro != null)
                    {
                        OrderDetail d = new OrderDetail
                        {
                            ProID = item.ProID,
                            Quantity = item.Quantity,
                            Price = pro.Price,
                            Amount = item.Quantity * pro.Price
                        };
                        ord.OrderDetails.Add(d);

                        pro.Quantity = pro.Quantity - item.Quantity; //Giảm số lượng tồn

                        if (pro.SaleQuantity != null) // Thay đổi số lượng bán
                            pro.SaleQuantity += item.Quantity;
                        else pro.SaleQuantity = item.Quantity;
                    }
                }
                ctx.Orders.Add(ord);
                ctx.SaveChanges();
            }

            CurrentContext.GetCart().Items.Clear();
            return RedirectToAction("Index", "Home");
        }
Пример #26
0
        public static bool IsLogged()
        {
            if ((int)HttpContext.Current.Session["IsLogin"] == 1)
                return true;

            if (HttpContext.Current.Request.Cookies["Username"] != null)
            {
                HttpContext.Current.Session["IsLogin"] = 1;

                string username = HttpContext.Current.Request.Cookies["Username"].Value;
                using (QLBHEntities ctx = new QLBHEntities())
                {
                    User us = ctx.Users
                         .Where(u => u.f_Username == username).FirstOrDefault();

                    HttpContext.Current.Session["CurUser"] = us;
                }

                return true;
            }

            return false;
        }
Пример #27
0
        //
        // GET: /Product/Detail/id
        public ActionResult Detail(int? id)
        {
            if (id.HasValue == false)
            {
                return RedirectToAction("Index", "Home");
            }
            using (QLBHEntities ctx = new QLBHEntities())
            {
                Product pro = ctx.Products.Include("Category").Include("TypeProduct").Where(p => p.ProID == id).FirstOrDefault();

                ViewBag.CatId = pro.CatID;
                ViewBag.TypeId = pro.TypeID;
                return View(pro);
            }
        }
Пример #28
0
        //
        //GET: /Product/LikeTypeProduct
        public ActionResult LikeTypeProduct(int id)
        {
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var list = ctx.Products.Where(p => p.TypeID == id).Take(5).ToList();

                return PartialView(list);
            }
        }
Пример #29
0
        //
        //GET: /ProductAdmin/editProduct
        public ActionResult editProduct(int id)
        {
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var pro = ctx.Products.Where(p => p.ProID == id).FirstOrDefault();
                var list = ctx.Categories.ToList();
                var list2 = ctx.TypeProducts.ToList();

                ViewBag.TypeProduct = list2;
                ViewBag.Categories = list;
                return View(pro);
            }
        }
Пример #30
0
        //
        // GET: /ProductAdmin/getAll/{page}
        public ActionResult getAll(int page = 1)
        {
            int pageSz = Convert.ToInt32(ConfigurationManager.AppSettings["admin_PageSize"]);

            using (QLBHEntities ctx = new QLBHEntities())
            {
                var query = ctx.Products.Include("Category").Include("TypeProduct");
                int count = query.Count();
                int nPages = count / pageSz + (count % pageSz > 0 ? 1 : 0);

                List<Product> list = query.OrderBy(p => p.ProID).Skip((page - 1) * pageSz).Take(pageSz).ToList();

                ViewBag.CurPage = page;
                ViewBag.PageCount = nPages;

                return View(list);
            }
        }