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
        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");
            }
        }
        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");
            }
        }
        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");
            }
        }
示例#5
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");
 }
示例#6
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");
 }
        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);
            }
        }
        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);
            }
        }
示例#9
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 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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        public ActionResult editProduct(Product model, HttpPostedFileBase fuMain, HttpPostedFileBase fuThumbs)
        {
            Product pro = new Product();
            using (QLBHEntities ctx = new QLBHEntities())
            {
                pro = ctx.Products.Where(p => p.ProID == model.ProID).First();
                if (string.IsNullOrEmpty(model.TinyDes)) model.TinyDes = string.Empty;
                if (string.IsNullOrEmpty(model.FullDes)) model.FullDes = string.Empty;

                pro.CatID = model.CatID;
                pro.TypeID = model.TypeID;
                pro.ProName = model.ProName;
                pro.Quantity = model.Quantity;
                pro.Price = model.Price;
                pro.Origin = model.Origin;
                pro.TinyDes = model.TinyDes;
                pro.FullDes = model.FullDes;

                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(pro);
        }
示例#14
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Error = "Captcha không đúng.";
                return View(model);
            }
            using (QLBHEntities ctx = new QLBHEntities())
            {
                int n = ctx.Users.Where(u => u.f_Username == model.UID).Count();

                if (n > 0)
                {
                    ViewBag.Error = model.UID + " đã tồn tại.";
                    return View(model);
                }

                User us = new User
                {
                    f_Username = model.UID,
                    f_Password = StringUtils.MD5(model.PWD),
                    f_Name = model.FullName,
                    f_Email = model.Email,

                    f_DOB = DateTime.ParseExact(model.DOB, "d/M/yyyy", null),
                    f_Permission = 0
                };

                ctx.Users.Add(us);
                ctx.SaveChanges();
            }
            Url.Action("login", "account");
            ViewBag.Status = true;

            return View();
        }
示例#15
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");
        }