예제 #1
0
        public ActionResult Register(RegisterVM model)
        {
            if (!ModelState.IsValid)
            {
                // TODO: Captcha validation failed, show error message

                ViewBag.ErrorMsg = "Sai mã Captcha";
            }
            else
            {
                // TODO: Captcha validation passed, proceed with protected action

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

                using (var ctx = new QLDGEntities())
                {
                    ctx.Users.Add(u);
                    ctx.SaveChanges();
                }
                ViewBag.SuccessMsg = "Bạn đã đăng kí thành công";
            }

            return(View());
        }
예제 #2
0
        public ActionResult Detail(int?id)
        {
            if (id.HasValue == false)
            {
                return(RedirectToAction("Index", "Home"));
            }

            using (var ctx = new QLDGEntities())
            {
                // lấy thông tin cho view title

                int CatID = ctx.Products
                            .Where(p => p.ProID == id)
                            .FirstOrDefault().CatID;

                string curCat = ctx.Categories
                                .Where(c => c.CatID == CatID)
                                .FirstOrDefault().CatName;

                ViewBag.Cat = curCat;

                // lấy thông tin sản phẩm

                var model = ctx.Products
                            .Where(p => p.ProID == id)
                            .FirstOrDefault();

                return(View(model));
            }
        }
예제 #3
0
        // GET: Category/List
        public ActionResult List()
        {
            using (var ctx = new QLDGEntities())
            {
                var list = ctx.Categories.ToList();

                return(PartialView("ListPartial", list));
            }
        }
 public ActionResult Add(Category model)
 {
     using (var ctx = new QLDGEntities())
     {
         ctx.Categories.Add(model);
         ctx.SaveChanges();
     }
     return(View());
 }
        // GET: Admin
        public ActionResult Index()
        {
            using (var ctx = new QLDGEntities())
            {
                var list = ctx.Categories.ToList();

                return(View(list));
            }
        }
예제 #6
0
        //GET: Home/Top5Hot

        public ActionResult Top5Hot()
        {
            using (var ctx = new QLDGEntities())
            {
                var list = ctx.Products
                           .ToList();

                return(PartialView("Top5Hot", list));
            }
        }
 public ActionResult Update(Category newmodel, int idToUpdate)
 {
     using (var ctx = new QLDGEntities())
     {
         Category model = ctx.Categories.Where(c => c.CatID == idToUpdate)
                          .FirstOrDefault();
         model.CatName = newmodel.CatName;
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index", "Admin"));
 }
 // GET: AuctionHistory/List
 public ActionResult List(int?id)
 {
     using (var ctx = new QLDGEntities())
     {
         var list = ctx.AuctionHistories
                    .Where(a => a.ProID == id)
                    .ToList();
         var list2 = ctx.Products
                     .Where(a => a.ProID == id)
                     .ToList();
         return(PartialView("ListPartial", list));
     }
 }
예제 #9
0
        // GET: Product/ByCat
        public ActionResult ByCat(int?id, int page = 1)
        {
            if (id.HasValue == false)
            {
                return(RedirectToAction("Index", "Home"));
            }

            using (var ctx = new QLDGEntities())
            {
                // truyền tên danh mục đang xem vào viewtitle

                string curCatName = ctx.Categories
                                    .Where(c => c.CatID == id)
                                    .FirstOrDefault().CatName;

                ViewBag.CatName = curCatName;

                // chia page

                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;

                // lấy sản phẩm vào view

                var list = ctx.Products
                           .Where(p => p.CatID == id)
                           .Where(p => p.ProStatus == true)
                           .OrderBy(p => p.ProID)
                           .Skip((page - 1) * recordsPerpage)
                           .Take(recordsPerpage)
                           .ToList();


                return(View(list));
            }
        }
        public ActionResult Delete(int idToDelete)
        {
            using (var ctx = new QLDGEntities())
            {
                Category model = ctx.Categories
                                 .Where(c => c.CatID == idToDelete)
                                 .FirstOrDefault();

                ctx.Categories.Remove(model);
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index", "Admin"));
        }
예제 #11
0
        // GET: Home/Top5Highest
        public ActionResult Top5Highest()
        {
            using (var ctx = new QLDGEntities())
            {
                int records = 5;
                var list    = ctx.Products
                              .Where(p => p.ProStatus == true)
                              .OrderByDescending(p => p.PriceCur)
                              .Take(records)
                              .ToList();

                return(PartialView("Top5Highest", list));
            }
        }
예제 #12
0
        public ActionResult Login(LoginVM model)
        {
            using (var ctx = new QLDGEntities())
            {
                string encPWD = StringUtils.Md5(model.RawPW);

                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;

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.ErrorMsg = "Đăng nhập thất bại.";
                    return(View());
                }
            }
        }
예제 #13
0
        public ActionResult Detail(BuyVM newmodel)
        {
            using (var ctx = new QLDGEntities())
            {
                var abc = ctx.AuctionHistories
                          .Where(a => a.ProID == newmodel.ProID).FirstOrDefault();

                if (abc != null)
                {
                    decimal highest = ctx.AuctionHistories
                                      .Where(a => a.ProID == newmodel.ProID)
                                      .OrderByDescending(a => a.PriceBid)
                                      .FirstOrDefault().PriceBid;



                    if (newmodel.money < highest)
                    {
                        // LẤY THÔNG TIN TITLE

                        int CatID = ctx.Products
                                    .Where(p => p.ProID == newmodel.ProID)
                                    .FirstOrDefault().CatID;

                        string curCat = ctx.Categories
                                        .Where(c => c.CatID == CatID)
                                        .FirstOrDefault().CatName;

                        ViewBag.Cat = curCat;


                        // TỰ ĐỘNG ĐẤU GIÁ

                        // Đấu giá mới
                        // Lấy id người đang giữ giá cao nhất
                        int PreID = ctx.AuctionHistories
                                    .Where(a => a.ProID == newmodel.ProID)
                                    .OrderByDescending(a => a.PriceBid)
                                    .FirstOrDefault().UserID;

                        // Lấy giá đặt của người dùng giữ giá
                        decimal PrePriceBid = ctx.AuctionHistories
                                              .Where(a => a.ProID == newmodel.ProID)
                                              .OrderByDescending(a => a.PriceBid)
                                              .FirstOrDefault().PriceBid;

                        // Tgian đặt giá của người giữ giá cao nhất
                        DateTime time = ctx.AuctionHistories
                                        .Where(a => a.ProID == newmodel.ProID)
                                        .OrderByDescending(a => a.PriceBid)
                                        .FirstOrDefault().AuctionTime;

                        // lấy bước giá sản phẩm
                        decimal step = ctx.Products
                                       .Where(a => a.ProID == newmodel.ProID)
                                       .FirstOrDefault().Step;

                        // Lưu đấu giá
                        // người đấu giá mới thấp hơn cao nhất
                        AuctionHistory bid = new AuctionHistory
                        {
                            ProID         = newmodel.ProID,
                            UserID        = newmodel.UserID,
                            PriceBid      = newmodel.money,
                            PriceCur      = newmodel.money,
                            AuctionTime   = newmodel.time,
                            AuctionStatus = true
                        };

                        ctx.AuctionHistories.Add(bid);


                        // tự động đấu giá cho người giữ giá
                        AuctionHistory bid2 = new AuctionHistory
                        {
                            ProID         = newmodel.ProID,
                            UserID        = PreID,
                            PriceCur      = newmodel.money + step,
                            PriceBid      = PrePriceBid,
                            AuctionTime   = time,
                            AuctionStatus = true
                        };


                        ctx.AuctionHistories.Add(bid2);
                        ctx.SaveChanges();

                        // THAY ĐỔI THÔNG TIN SẢN PHẨM

                        Product model = ctx.Products
                                        .Where(p => p.ProID == newmodel.ProID)
                                        .FirstOrDefault();

                        model.PriceCur = newmodel.money + model.Step;
                        ctx.SaveChanges();

                        // lấy sản phẩm cho view

                        var latestmodel = ctx.Products
                                          .Where(p => p.ProID == newmodel.ProID)
                                          .FirstOrDefault();

                        ViewBag.ErrorMsg = "Bạn đã đặt giá THÀNH CÔNG, NHƯNG giá bạn đặt chưa phải là giá cao nhất";

                        return(View(latestmodel));
                    }


                    else if (newmodel.money == highest)
                    {
                        // Lấy id người đang giữ giá cao nhất
                        int PreID = ctx.AuctionHistories
                                    .Where(a => a.ProID == newmodel.ProID)
                                    .OrderByDescending(a => a.PriceBid)
                                    .FirstOrDefault().UserID;

                        // Tgian đặt giá của người giữ giá cao nhất
                        DateTime time = ctx.AuctionHistories
                                        .Where(a => a.ProID == newmodel.ProID)
                                        .OrderByDescending(a => a.PriceBid)
                                        .FirstOrDefault().AuctionTime;

                        // TỰ ĐỘNG ĐẤU GIÁ

                        AuctionHistory bid = new AuctionHistory
                        {
                            ProID         = newmodel.ProID,
                            UserID        = newmodel.UserID,
                            PriceBid      = newmodel.money,
                            PriceCur      = newmodel.money,
                            AuctionTime   = newmodel.time,
                            AuctionStatus = true
                        };

                        ctx.AuctionHistories.Add(bid);

                        AuctionHistory bid2 = new AuctionHistory
                        {
                            ProID         = newmodel.ProID,
                            UserID        = PreID,
                            PriceBid      = newmodel.money,
                            PriceCur      = newmodel.money,
                            AuctionTime   = time,
                            AuctionStatus = true
                        };
                        ctx.AuctionHistories.Add(bid2);
                        ctx.SaveChanges();


                        // THAY ĐỔI THÔNG TIN SẢN PHẨM

                        Product model = ctx.Products
                                        .Where(p => p.ProID == newmodel.ProID)
                                        .FirstOrDefault();

                        model.PriceCur = model.PriceHighest;
                        ctx.SaveChanges();

                        // Lấy thông tin title

                        int CatID = ctx.Products
                                    .Where(p => p.ProID == newmodel.ProID)
                                    .FirstOrDefault().CatID;

                        string curCat = ctx.Categories
                                        .Where(c => c.CatID == CatID)
                                        .FirstOrDefault().CatName;

                        ViewBag.Cat = curCat;

                        // Lấy sản phẩm cho view

                        var latestmodel = ctx.Products
                                          .Where(p => p.ProID == newmodel.ProID)
                                          .FirstOrDefault();

                        ViewBag.ErrorMsg = "Bạn đã đặt giá THÀNH CÔNG, NHƯNG giá bạn đặt chưa phải là giá cao nhất";

                        return(View(latestmodel));
                    }


                    else
                    {
                        // lấy bước giá sản phẩm
                        decimal step = ctx.Products
                                       .Where(a => a.ProID == newmodel.ProID)
                                       .FirstOrDefault().Step;
                        // lấy giá hiện tại của sản phẩm
                        decimal cur = ctx.Products
                                      .Where(a => a.ProID == newmodel.ProID)
                                      .FirstOrDefault().PriceCur;

                        // LƯU ĐẤU GIÁ VÀO CSDL

                        AuctionHistory bid = new AuctionHistory
                        {
                            ProID         = newmodel.ProID,
                            UserID        = newmodel.UserID,
                            PriceBid      = newmodel.money,
                            PriceCur      = cur + step,
                            AuctionTime   = newmodel.time,
                            AuctionStatus = true
                        };

                        ctx.AuctionHistories.Add(bid);
                        ctx.SaveChanges();

                        // THAY ĐỔI THÔNG TIN SẢN PHẨM

                        Product model = ctx.Products
                                        .Where(p => p.ProID == newmodel.ProID)
                                        .FirstOrDefault();
                        model.PriceHighest = newmodel.money;
                        model.PriceCur     = model.PriceCur + model.Step;
                        model.Buyer        = newmodel.UserID;

                        ctx.SaveChanges();

                        // Lấy thông tin title

                        int CatID = ctx.Products
                                    .Where(p => p.ProID == newmodel.ProID)
                                    .FirstOrDefault().CatID;

                        string curCat = ctx.Categories
                                        .Where(c => c.CatID == CatID)
                                        .FirstOrDefault().CatName;

                        ViewBag.Cat = curCat;

                        //Lấy sản phẩm cho view

                        var latestmodel = ctx.Products
                                          .Where(p => p.ProID == newmodel.ProID)
                                          .FirstOrDefault();

                        ViewBag.SuccessMsg = "Bạn đã đặt giá thành công";

                        return(View(latestmodel));
                    }
                }
                else
                {
                    // lấy bước giá sản phẩm
                    decimal step = ctx.Products
                                   .Where(a => a.ProID == newmodel.ProID)
                                   .FirstOrDefault().Step;
                    // lấy giá hiện tại của sản phẩm
                    decimal cur = ctx.Products
                                  .Where(a => a.ProID == newmodel.ProID)
                                  .FirstOrDefault().PriceCur;


                    // LƯU ĐẤU GIÁ VÀO CSDL

                    AuctionHistory bid = new AuctionHistory
                    {
                        ProID         = newmodel.ProID,
                        UserID        = newmodel.UserID,
                        PriceBid      = newmodel.money,
                        PriceCur      = cur + step,
                        AuctionTime   = newmodel.time,
                        AuctionStatus = true
                    };

                    ctx.AuctionHistories.Add(bid);
                    ctx.SaveChanges();


                    // THAY ĐỔI THÔNG TIN SẢN PHẨM

                    Product model = ctx.Products
                                    .Where(p => p.ProID == newmodel.ProID)
                                    .FirstOrDefault();
                    model.PriceHighest = newmodel.money;
                    model.PriceCur     = model.PriceCur + model.Step;
                    model.Buyer        = newmodel.UserID;

                    ctx.SaveChanges();

                    // Lấy thông tin title

                    int CatID = ctx.Products
                                .Where(p => p.ProID == newmodel.ProID)
                                .FirstOrDefault().CatID;

                    string curCat = ctx.Categories
                                    .Where(c => c.CatID == CatID)
                                    .FirstOrDefault().CatName;

                    ViewBag.Cat = curCat;

                    //Lấy sản phẩm cho view

                    var latestmodel = ctx.Products
                                      .Where(p => p.ProID == newmodel.ProID)
                                      .FirstOrDefault();

                    ViewBag.SuccessMsg = "Bạn đã đặt giá thành công";
                    return(View(latestmodel));
                }
            }
        }