Exemplo n.º 1
0
        //
        // GET: /Product/ByCat
        public ActionResult ByCat(int?id, int page = 1)
        {
            if (id.HasValue == false)
            {
                return(RedirectToAction("Index", "Home"));
            }
            using (var ctx = new QLBHEntities())
            {
                int n = ctx.Products
                        .Where(p => p.CatID == id)
                        .Count();
                int recordsPerPage = 6;
                int nPages         = n / recordsPerPage;
                int m = n % recordsPerPage;
                if (m > 0)
                {
                    nPages++;
                }
                ViewBag.Pages   = nPages;
                ViewBag.CurPage = page;
                var list = ctx.Products
                           .Where(p => p.CatID == id)
                           .OrderBy(p => p.ProID)
                           .Skip((page - 1) * recordsPerPage)
                           .Take(recordsPerPage)
                           .ToList();

                //var list = ctx.Products
                //    .Where(p => id == p.CatID)
                //    .ToList();
                return(View(list));
            }
        }
Exemplo n.º 2
0
        public ActionResult Product(int page = 1)
        {
            using (var ctx = new QLBHEntities())
            {
                int n = ctx.Products.Count();
                int recordsPerPage = 6;
                int nPages         = n / recordsPerPage;
                int m = n % recordsPerPage;
                if (m > 0)
                {
                    nPages++;
                }
                ViewBag.Pages   = nPages;
                ViewBag.CurPage = page;
                var list = ctx.Products
                           .OrderBy(p => p.ProID)
                           .Skip((page - 1) * recordsPerPage)
                           .Take(recordsPerPage)
                           .ToList();

                //var list = ctx.Products
                //    .Where(p => id == p.CatID)
                //    .ToList();
                return(View(list));
            }
        }
Exemplo n.º 3
0
 public void ListOrder(int userid, int[] a)
 {
     using (var ctx = new QLBHEntities())
     {
         var lOrder = ctx.Orders.Where(i => i.UserID == userid).ToList();
     }
 }
Exemplo n.º 4
0
        // GET: /Category/
        public ActionResult ListCategory()
        {
            QLBHEntities    ctx  = new QLBHEntities();
            List <Category> list = ctx.Categories.ToList();

            return(View(list));
        }
Exemplo n.º 5
0
        // GET: Home
        public ActionResult Index()
        {
            TopHomeIndex   obj   = new TopHomeIndex();
            List <Product> list1 = new List <Product>();
            List <Product> list2 = new List <Product>();

            using (var ctx = new QLBHEntities())
            {
                list1 = ctx.Products
                        .OrderByDescending(p => p.Price)
                        .Take(5)
                        .ToList();
                obj.LstTop51 = list1;
                //lstwash

                list2 = ctx.Products
                        .OrderByDescending(p => p.Quantity)
                        .Take(5)
                        .ToList();
                obj.LstTop52 = list2;
            }


            return(View(obj));
        }
Exemplo n.º 6
0
        public ActionResult Checkemail(string email)
        {
            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");

            if (string.IsNullOrEmpty(email))
            {
                return(Json(false));
            }
            else if (!regex.IsMatch(email))
            {
                return(Json(false));
            }
            else
            {
                bool rsl = false;
                using (var db = new QLBHEntities())
                {
                    var user = db.Users.Where(item => item.f_Email == email).FirstOrDefault();
                    if (user == null)
                    {
                        rsl = true;
                    }
                }
                return(Json(rsl));
            }
        }
        public ActionResult Register(RegisterVM model)
        {
            if (!ModelState.IsValid)
            {
                // TODO: Captcha validation failed, show error message

                ViewBag.ErrorMsg = "Sai mã xác nhận, vui lòng nhập lại!";
            }
            else
            {
                // TODO: Captcha validation passed, proceed with protected action

                User u = new User
                {
                    f_Username   = model.Username,
                    f_Email      = model.Email,
                    f_Name       = model.Name,
                    f_Password   = StringUtils.Md5(model.RawPWD),
                    f_Permission = 0,
                    f_DOB        = DateTime.ParseExact(model.DOB, "d/m/yyyy", null),
                    //f_Money = Decimal.Parse(model.Money, NumberStyles.Currency)
                    f_Money = Convert.ToDecimal(model.Money.ToString().TrimStart('¥'))
                };

                using (QLBHEntities ctx = new QLBHEntities())
                {
                    ctx.Users.Add(u);
                    ctx.SaveChanges();
                }
            }
            return(View());
        }
Exemplo n.º 8
0
        public ActionResult Checkout()
        {
            using (var ctx = new QLBHEntities())
            {
                var ord = new Order
                {
                    OrderDate = DateTime.Now,
                    UserID    = CurrentContext.GetCurUser().f_ID,
                    Total     = 0
                };
                var c = CurrentContext.GetCart();
                foreach (var item in c.Items.Where(i => i.idUser == CurrentContext.GetCurUser().f_ID))
                {
                    var detail = new OrderDetail
                    {
                        ProID = item.Product.ProID,
                        //Quantity = item.Quantity,
                        Price  = item.Product.Price,
                        Amount = item.Price
                    };

                    ord.OrderDetails.Add(detail);
                    ord.Total += detail.Amount;

                    //c.RemoveItem(item.Product.ProID);
                }

                ctx.Orders.Add(ord);
                ctx.SaveChanges();
            }

            CurrentContext.GetCart().Items.Clear();
            return(RedirectToAction("Index", "Cart"));
        }
        public ActionResult Login(LoginVM model)
        {
            string encPwd = StringUtils.Md5(model.RawPWD);

            using (QLBHEntities ctx = new QLBHEntities())
            {
                var user = ctx.Users
                           .Where(u => u.f_Username == model.Username && u.f_Password == encPwd)
                           .FirstOrDefault();

                if (user != null)
                {
                    Session["isLogin"] = 1;
                    Session["user"]    = user;
                    if (model.Remember)
                    {
                        Response.Cookies["userId"].Value   = user.f_ID.ToString();
                        Response.Cookies["userId"].Expires = DateTime.Now.AddDays(7);
                    }

                    ViewBag.iduser = user.f_ID;
                    //ViewBag.IDLogin = user.f_ID.ToString();
                    //ViewBag.TK = Convert.ToInt32(user.f_Money);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.ErrorMsg = "Đăng nhập thất bại.";
                    return(View());
                }
            }
        }
Exemplo n.º 10
0
        public ActionResult Add2(int proId, int quantity, int curPage)
        {
            using (var ctx = new QLBHEntities())
            {
                var pro = ctx.Products
                          .Where(p => p.ProID == proId)
                          .FirstOrDefault();

                //pro.Price = pro.Price + 50000;
                //ctx.SaveChanges();

                var item = new CartItem
                {
                    Quantity = quantity,
                    Price    = pro.Price + 100000,
                    idUser   = CurrentContext.GetCurUser().f_ID,
                    Product  = pro
                };

                CurrentContext.moneyUser(item, CurrentContext.GetCurUser().f_ID);

                if (CurrentContext.GetCart().IsPrice(proId, Convert.ToInt32(pro.Price + 50000)) == false || item.moneyUser < pro.Price + 50000)
                {
                    ViewBag.ErrorMsg = "Đã có người ra giá cao hơn giá của bạn. Mời bạn ra giá khác cao hơn.";
                }
                else
                {
                    CurrentContext.GetCart().AddItem(item);
                }

                return(RedirectToAction("ByCat", "Product", new { id = pro.CatID, page = curPage }));
            }
        }
Exemplo n.º 11
0
        public ActionResult getPercen(int y = 2016)
        {
            decimal        total;
            List <decimal> kq   = new List <decimal>();
            List <string>  lbl  = new List <string>();
            decimal        q    = 0;
            string         name = "";

            using (var db = new QLBHEntities())
            {
                var cat = db.Categories.ToList();
                total = db.Orders.Where(itm => itm.OrderDate.Year == y)
                        .Sum(itm => itm.OrderDetails.Sum(o => o.Amount));
                foreach (var item in cat)
                {
                    var tmp = db.OrderDetails.Where(id => id.Product.CatID == item.CatID &&
                                                    id.Order.OrderDate.Year == 2016)
                              .ToList();
                    lbl.Add(string.Format("{0} %", Math.Round((tmp.Sum(i => i.Amount) / total) * 100, 2)));
                    kq.Add(tmp.Sum(i => i.Amount) / total);
                    if (q < tmp.Sum(i => i.Amount))
                    {
                        q    = tmp.Sum(i => i.Amount);
                        name = item.CatName;
                    }
                }
            }
            return(Json(new { kq = kq, lbl = lbl, qa = q, na = name }));
        }
Exemplo n.º 12
0
        public static bool IsLogged()
        {
            var flag = HttpContext.Current.Session["isLogin"];

            if (flag == null || (int)flag == 0)
            {
                if (HttpContext.Current.Request.Cookies["userId"] != null)
                {
                    int userIdCookie = Convert.ToInt32(HttpContext.Current.Request.Cookies["userId"].Value);

                    using (QLBHEntities ctx = new QLBHEntities())
                    {
                        var user = ctx.Users
                                   .Where(u => u.f_ID == userIdCookie)
                                   .FirstOrDefault();

                        HttpContext.Current.Session["isLogin"] = 1;
                        HttpContext.Current.Session["user"]    = user;
                        HttpContext.Current.Response.Cookies["userId"].Expires =
                            DateTime.Now.AddDays(-1);
                    }
                    return(true);
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 13
0
        public ActionResult Add(Product vm, HttpPostedFileBase fuMain, HttpPostedFileBase fuThumbs1, HttpPostedFileBase fuThumbs2)
        {
            if (vm.FullDes == null)
            {
                vm.FullDes = string.Empty;
            }
            if (vm.TinyDes == null)
            {
                vm.TinyDes = string.Empty;
            }
            using (var ctx = new QLBHEntities())
            {
                ctx.Products.Add(vm);
                ctx.SaveChanges();

                if (fuMain != null && fuMain.ContentLength > 0 && fuThumbs1 != null && fuThumbs1.ContentLength > 0 && fuThumbs2 != null && fuThumbs2.ContentLength > 0)
                {
                    string sDirPath      = Server.MapPath("~/Imgs/sp");
                    string targetDirPath = Path.Combine(sDirPath, vm.ProID.ToString());
                    Directory.CreateDirectory(targetDirPath);
                    string mainFileName = Path.Combine(targetDirPath, "main_thumbs.jpg");
                    fuMain.SaveAs(mainFileName);
                    string thumbs1FileName = Path.Combine(targetDirPath, "main_thumbs1.jpg");
                    fuThumbs1.SaveAs(thumbs1FileName);
                    string thumbs2FileName = Path.Combine(targetDirPath, "main_thumbs2.jpg");
                    fuThumbs2.SaveAs(thumbs2FileName);
                }

                var list = ctx.Categories.ToList();
                ViewBag.Categories = list;
            }

            return(View());
        }
Exemplo n.º 14
0
        public ActionResult Register(RegisterVM model)
        {
            if (!ModelState.IsValid)
            {
                // TODO: Captcha validation failed, show error message

                ViewBag.ErrorMsg = "Incorrect CAPTCHA code!";
            }
            else
            {
                // TODO: Captcha validation passed, proceed with protected action

                User u = new User
                {
                    f_Username   = model.Username,
                    f_Email      = model.Email,
                    f_Name       = model.Name,
                    f_Password   = StringUtils.Md5(model.RawPWD),
                    f_Permission = 0,
                    f_DOB        = DateTime.ParseExact(model.DOB, "d/m/yyyy", null)
                };

                using (QLBHEntities ctx = new QLBHEntities())
                {
                    ctx.Users.Add(u);
                    ctx.SaveChanges();
                }
            }
            return(View());
        }
        public ActionResult EditPassword(string pwUser, int?id)
        {
            if (id.HasValue == false)
            {
                return(RedirectToAction("Profile", "Account"));
            }

            if (pwUser != "" && pwUser != null)
            {
                using (var ctx = new QLBHEntities())
                {
                    //tim den thong tin user
                    var user = ctx.Users
                               .Where(i => i.f_ID == id)
                               .FirstOrDefault();

                    // user ton tai, loi
                    if (user != null)
                    {
                        user.f_Password = StringUtils.Md5(pwUser);

                        ctx.Entry(user).State =
                            System.Data.Entity.EntityState.Modified;

                        ctx.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("Profile", "Account", new { id = CurrentContext.GetCurUser().f_ID }));
        }
Exemplo n.º 16
0
        public ActionResult getDataChart(int y = 2016)
        {
            List <ReportPro> p       = new List <ReportPro>();
            int        s             = 0;
            string     tt            = "";
            List <int> quantityofRes = new List <int>();
            List <int> QuanOder      = new List <int>();

            using (var db = new QLBHEntities())
            {
                var c = db.Categories.OrderBy(it => it.CatID).ToList();
                foreach (var item in c)
                {
                    ReportPro t = new ReportPro()
                    {
                        CatName = item.CatName
                    };
                    var pro = db.OrderDetails.Include("Product")
                              .Where(it => it.Order.OrderDate.Year == y && it.Product.CatID == item.CatID)
                              .OrderBy(it => it.Order.OrderDate.Month)
                              .ToList();
                    var st = 0;
                    foreach (var it in new List <int>()
                    {
                        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
                    })
                    {
                        t.Month.Add(it);
                        var tm = pro.Where(itm => itm.Order.OrderDate.Month == it).Count();
                        st += tm;
                        t.QuanTity.Add(tm);
                    }
                    //s = st > s ? st : s;
                    if (st > s)
                    {
                        s  = st;
                        tt = item.CatName;
                    }
                    p.Add(t);
                }

                foreach (var item in new List <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
                })
                {
                    var qr = db.Users.Where(u => u.f_Day_Rerister.Value.Month == item).Count();
                    quantityofRes.Add(qr);
                    var qqo = db.Orders.Where(od => od.OrderDate.Day == item).Count();
                    QuanOder.Add(qqo);
                }
            }

            return(Json(new { lbl = p.Select(i => i.CatName).ToList(), sre =
                                  p.Select(i => i.QuanTity).ToList(), ma = s, pn = tt,
                              us_q = new List <List <int> > {
                                  quantityofRes, QuanOder
                              } }));
        }
Exemplo n.º 17
0
 public ActionResult ListCat()
 {
     using (var ctx = new QLBHEntities())
     {
         var list = ctx.Categories.ToList();
         return(View(list));
     }
 }
Exemplo n.º 18
0
 // Get:CreateProduct
 public ActionResult CreateProduct()
 {
     using (var db = new QLBHEntities())
     {
         ViewBag.Cat = db.Categories.ToList();
     }
     return(View());
 }
Exemplo n.º 19
0
 //
 // GET: /Category/
 public ActionResult List()
 {
     using (var ctx = new QLBHEntities())
     {
         var list = ctx.Categories.ToList();
         return(PartialView("ListPartial", list));
     }
 }
Exemplo n.º 20
0
 // GET: Header/Register
 public ActionResult Register()
 {
     using (var db = new QLBHEntities())
     {
         ViewBag.Countries = db.Countries.ToList();
     }
     return(View());
 }
Exemplo n.º 21
0
 //
 // GET: /Manage/
 public ActionResult ListUser()
 {
     using (var ctx = new QLBHEntities())
     {
         var list = ctx.Users.ToList();
         return(View(list));
     }
 }
Exemplo n.º 22
0
 //
 // GET//Top 5 san pham gia cao nhat
 public ActionResult Index()
 {
     using (var ctx = new QLBHEntities())
     {
         var list = ctx.Products.OrderByDescending(l => l.Price).ToList();
         Deline();
         return(View("Index", list));
     }
 }
Exemplo n.º 23
0
 //
 // GET: /MProduct/Add
 public ActionResult Add()
 {
     using (var ctx = new QLBHEntities())
     {
         var list = ctx.Categories.ToList();
         ViewBag.Categories = list;
     }
     return(View());
 }
Exemplo n.º 24
0
        public int soLuongSP(int catID)
        {
            using (var ctx = new QLBHEntities())
            {
                var list = ctx.Products.Where(i => i.CatID == catID).ToList();

                return(list.Count);
            }
        }
Exemplo n.º 25
0
 public ActionResult AddCat(Category model)
 {
     using (var ctx = new QLBHEntities())
     {
         ctx.Categories.Add(model);
         ctx.SaveChanges();
     }
     return(View());
 }
Exemplo n.º 26
0
        // GET: EditCategory
        public ActionResult EditCategory()
        {
            List <Category> listCat = null;

            using (var DB = new QLBHEntities())
            {
                listCat = DB.Categories.ToList();
            }
            return(View(listCat));
        }
Exemplo n.º 27
0
 public ActionResult UpdateUser(User model)
 {
     using (var ctx = new QLBHEntities())
     {
         ctx.Entry(model).State =
             System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index", "Home"));
 }
Exemplo n.º 28
0
        //GET://ListWinProduct
        public ActionResult ListWinProduct()
        {
            using (var ctx = new QLBHEntities())
            {
                var list = ctx.OrderDetails
                           .ToList();

                return(View(list));
            }
        }
Exemplo n.º 29
0
 public ActionResult Update(Category model)
 {
     using (var ctx = new QLBHEntities())
     {
         ctx.Entry(model).State =
             System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
     return(RedirectToAction("ListCat", "Manage"));
 }