Example #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            User_KH user_KH = db.User_KH.Find(id);

            db.User_KH.Remove(user_KH);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "id_KH,diem,avatar")] User_KH user_KH)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user_KH).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.id_KH = new SelectList(db.Accounts, "id_account", "fullName", user_KH.id_KH);
     return(View(user_KH));
 }
Example #3
0
        // GET: Admin/User_KH/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User_KH user_KH = db.User_KH.Find(id);

            if (user_KH == null)
            {
                return(HttpNotFound());
            }
            return(View(user_KH));
        }
Example #4
0
        // GET: Admin/User_KH/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User_KH user_KH = db.User_KH.Find(id);

            if (user_KH == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id_KH = new SelectList(db.Accounts, "id_account", "fullName", user_KH.id_KH);
            return(View(user_KH));
        }
Example #5
0
        public ActionResult DangNhap(FormCollection collection)
        {
            string      email    = collection.Get("email");
            string      password = collection.Get("password");
            MyDBContext context  = new MyDBContext();
            User_KH     user     = context.User_KH.
                                   Where(m => m.Account.index_quyen == 0).
                                   Where(m => m.Account.email == email && m.Account.passwords == password).
                                   FirstOrDefault();

            if (user != null)
            {
                Session.Add("userID", user.id_KH);
                Session.Add("FullName", user.Account.fullName);
                return(RedirectToAction("Home", "Site"));
            }
            else
            {
                ViewBag.Message = "SDT, email không tồn tại, hoặc mật khẩu của bạn không đúng";
                return(View("DangNhap"));
            }
        }
        public ActionResult Index(FormCollection collection)
        {
            List <Cart> listSP = new List <Cart>();

            if (Session["cart"] != null)
            {
                listSP = Session["cart"] as List <Cart>;
            }
            else
            {
                return(View());
            }


            if (Session["userID"] == null)
            {
                TempData["msg"] = "<script>alert('Bạn cần phải đăng nhập trước khi đặt hàng');</script>";
            }

            else
            {
                int     maKH = Convert.ToInt32((Session["userID"]));
                User_KH kH   = context.User_KH.FirstOrDefault(k => k.id_KH == maKH);

                DonHang donHang = new DonHang()
                {
                    User_KH   = kH,
                    ngayLap   = DateTime.Now,
                    tongTien  = 0,
                    tinhTrang = 0
                };

                context.DonHangs.Add(donHang);
                context.SaveChanges();
                DonHang temp = context.DonHangs.OrderByDescending(n => n.soDH).First() as DonHang;

                decimal tongTien = 0;
                foreach (var item in listSP)
                {
                    ChiTietDH ct = new ChiTietDH()
                    {
                        maGiay     = item.giay.maGiay,
                        size       = item.size,
                        soLuongMua = item.soLuong,
                        soDH       = temp.soDH
                    };

                    tongTien += (item.soLuong * item.giay.giaBan);
                    ChiTietGiay ctg = context.ChiTietGiays.FirstOrDefault(k => k.maGiay == ct.maGiay) as ChiTietGiay;
                    ctg.soLuongTon -= ct.soLuongMua;

                    temp.ChiTietDHs.Add(ct);
                    context.ChiTietDHs.Add(ct);
                    context.SaveChanges();
                }
                tongTien     += tongTien * 0.01M;
                temp.tongTien = tongTien;

                context.SaveChanges();

                TempData["success"] = "<script>alert('Quý khách đã đặt đơn hàng thành công');</script>";
                Session.Remove("cart");
            }

            ViewData["cart"] = listSP;
            return(View());
        }