示例#1
0
 public ActionResult cartt(int id)
 {
     using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
     {
         //tìm món ăn và hoá đơn đã có trong billinfo chưa
         var x = dbb.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault();
         if (x == null)
         {
             //nếu không tìm thấy thì ta tạo mới billinfo chứa món ăn và idbill của bàn ăn đó
             dbb.add_billinfo(int.Parse(Session["idbill"].ToString()), id, 1);
         }
         else
         {
             //nếu tìm thấy ta tăng số lượng món ăn lên 1
             x.count++;
             dbb.SaveChanges();
         }
     }
     //thêm xong ta sẽ show lên giỏ hàng
     using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
     {
         //lấy tất cả billinfo
         cartfood.allbillinfos = dbb.billinfoes.ToList();
         cartfood.allfoods     = new List <food>();
         foreach (billinfo item in cartfood.allbillinfos)
         {
             //lấy ra món ăn tương ứng với sô lượng của chúng
             var x = dbb.foods.ToList().Where(s => s.id == item.idfood).FirstOrDefault();
             cartfood.allfoods.Add(x);
         }
     }
     return(PartialView("/Views/Shared/_cartproduct.cshtml", cartfood));
 }
示例#2
0
        public ActionResult Index(int id, int?status)
        {
            ViewBag.temp = status;
            //nhận được id bàn
            ViewBag.idtable = id;
            Session.Timeout = 360;
            //tìm trong bill xem bàn đã có hoá đơn chưa theo id bàn và status của bill
            var x = db.bills.ToList().Where(s => s.idtable == id && string.Compare(s.status, "0", true) == 0).FirstOrDefault();

            if (x == null)
            {
                //nếu bàn chưa có bill thì tạo tạm thời 1 bill để lưu thông tin món ăn
                DateTime Timecheckin  = DateTime.Now;
                DateTime?Timecheckout = null;
                db.add_bill(Timecheckin, Timecheckout, "0", int.Parse(Session["idaccount"].ToString()), id);
                var y = db.bills.ToList().Where(s => s.idtable == id & string.Compare(s.status, "0", true) == 0).FirstOrDefault();
                Session["idbill"] = y.id; //lấy giá trị idbill để dùng cho việc xem billinfo của 1 bàn nào đó
            }
            else
            {
                /*ngược lại nếu bàn đó trống mà trước đó ta có chọn món mà ko xác nhận thì ở bước này sẽ xoá billinfo của bàn đó.
                 * cái này cũng dùng cho trường hợp sau khi xác nhận thanh toán sẽ xoá hết thông tin billinfo của bàn đó */
                Session["idbill"] = x.id;
                var y = db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "Trống", true) == 0).FirstOrDefault();
                if (y != null)
                {
                    db.delete_billinfo(x.id);
                    x.datecheckin = DateTime.Now;
                    db.SaveChanges();
                }
                else
                {
                    using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
                    {
                        List <listIncart> listproduct = new List <listIncart>();
                        cartfood.allbillinfos = dbb.billinfoes.ToList();
                        foreach (billinfo item in cartfood.allbillinfos)
                        {
                            if (item.idbill == int.Parse(Session["idbill"].ToString()))
                            {
                                listproduct.Add(new listIncart(item.idfood, item.idbill, item.count));
                            }
                        }
                        Session["listproduct"] = listproduct;
                    }
                }
            }

            data.allfoods = db.foods.ToList();
            return(View(db.categories.ToList()));
        }
示例#3
0
 public ActionResult cartt(int id)
 {
     using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
     {
         //tìm món ăn và hoá đơn đã có trong billinfo chưa
         var x = dbb.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault();
         if (x == null)
         {
             //nếu không tìm thấy thì ta tạo mới billinfo chứa món ăn và idbill của bàn ăn đó
             dbb.add_billinfo(int.Parse(Session["idbill"].ToString()), id, 1);
         }
         else
         {
             //nếu tìm thấy ta tăng số lượng món ăn lên 1
             x.count++;
             dbb.SaveChanges();
         }
     }
     return(cart());
 }
示例#4
0
        public ActionResult reduction(int id)
        {
            //nếu count =1 thì không làm gì, ngược lại thì giảm đi 1
            var y = db.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault();

            if (y.count == 1)
            {
                return(RedirectToAction("index", "order"));
            }
            else
            {
                using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
                {
                    var x = dbb.billinfoes.ToList().Where(s => s.idfood == id && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault();
                    x.count = x.count - 1;
                    dbb.SaveChanges();
                }
            }
            return(cart());
        }
示例#5
0
        public ActionResult bill(int?id, int?temp)
        {
            if (id != null && db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "trống", true) == 0).FirstOrDefault() == null)
            {
                ViewBag.temp = temp;
                db.empty_table(id);
                var x = db.bills.ToList().Where(s => s.idtable == id && string.Compare(s.status, "0", true) == 0).FirstOrDefault();
                x.status       = "1";
                x.idaccount    = int.Parse(Session["idaccount"].ToString());
                x.datecheckout = DateTime.Now;
                //tính tổng tiền của bàn
                double tongtien = 0;
                using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
                {
                    cartfood.allbillinfos = dbb.billinfoes.ToList();
                    foreach (billinfo item in cartfood.allbillinfos)
                    {
                        if (item.idbill == int.Parse(Session["idbill"].ToString()))
                        {
                            var y = dbb.foods.ToList().Where(s => s.id == item.idfood).FirstOrDefault();
                            tongtien += (item.count * y.price);
                        }
                    }
                }
                x.Tongtien = tongtien;
                db.SaveChanges();
            }
            else if (id != null && db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "trống", true) == 0).FirstOrDefault() != null)
            {
                ViewBag.temp = temp;
                db.empty_table(id);
                var x = db.bills.ToList().Where(s => s.idtable == id && string.Compare(s.status, "0", true) == 0).FirstOrDefault();
                x.status       = "1";
                x.idaccount    = int.Parse(Session["idaccount"].ToString());
                x.datecheckout = DateTime.Now;
                //tính tổng tiền của bàn
                double tongtien = 0;
                using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
                {
                    cartfood.allbillinfos = dbb.billinfoes.ToList();
                    foreach (billinfo item in cartfood.allbillinfos)
                    {
                        if (item.idbill == int.Parse(Session["idbill"].ToString()))
                        {
                            var y = dbb.foods.ToList().Where(s => s.id == item.idfood).FirstOrDefault();
                            tongtien += (item.count * y.price);
                        }
                    }
                }
                if (tongtien == 0)
                {
                    return(RedirectToAction("index", "order", new { id = id, status = 4 }));
                }
                else
                {
                    x.Tongtien = tongtien;
                    db.SaveChanges();
                }
            }
            //nếu thanh toán khi chưa chọn xác nhận

            using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
            {
                //List<bill> x = dbb.bills.SqlQuery("select * from bill where ");
                //dbb.delete_billinfo(x.id);
                data.alltablefoods = dbb.tablefoods.SqlQuery("select * from tablefood").ToList();
            }
            return(View("index", data));
        }
示例#6
0
 public ActionResult Index(int?id, int?temp)
 {
     //taọ 1 toastr thông báo khi chưa chọn món mà bấm xác nhận
     using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
     {
         if (Session["idbill"] != null)
         {
             var x = dbb.billinfoes.ToList().Where(s => s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault();
             if (id != null && x == null)
             {
                 //nếu không tìm thấy billinfo của bill thì thông báo chưa chọn món.
                 //3 là trạng thái gửi sang page order
                 return(RedirectToAction("index", "order", new { id = id, status = 3 }));
             }
         }
     }
     //trường hợp chọn thêm món mà chưa xác nhận sẽ không được tính
     if (id == null && temp == null && Session["idbill"] != null)
     {
         ViewBag.temp = 3; //toastr thông báo món ăn ko thay đổi
         List <listIncart> listproduct = new List <listIncart>();
         listproduct = (List <listIncart>)Session["listproduct"];
         //listproduct là danh sách trước khi chịn thêm món
         //listproduct1 là danh sách sau khi chịn thêm món
         using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
         {
             List <listIncart> listproductbefore = new List <listIncart>();
             classdata         cardfood1         = new classdata();
             cardfood1.allbillinfos = dbb.billinfoes.ToList();
             foreach (billinfo item in cardfood1.allbillinfos)
             {
                 if (item.idbill == int.Parse(Session["idbill"].ToString()))
                 {
                     listproductbefore.Add(new listIncart(item.idfood, item.idbill, item.count));
                 }
             }
             foreach (var item in listproductbefore)
             {
                 foreach (var item1 in listproduct)
                 {
                     if (item1.ID == item.ID && item1.COUNT != item.COUNT)
                     {
                         var z = dbb.billinfoes.ToList().Where(s => s.idfood == item.ID && s.idbill == int.Parse(Session["idbill"].ToString())).FirstOrDefault();
                         z.count = item1.COUNT;
                         dbb.SaveChanges();
                     }
                 }
             }
         }
     }
     else if (id != null && temp != null)
     {
         //xác nhận đổi món của bàn thành công
         ViewBag.temp = 0;
     }
     //nếu id != null và bàn trống tức là có bàn yêu cầu xác nhận đặt món
     if (id != null && db.tablefoods.ToList().Where(s => s.id == id && string.Compare(s.status, "trống", true) == 0).FirstOrDefault() != null)
     {
         ViewBag.temp = temp;
         db.customer_table(id);
     }
     using (QuanLyCafeEntities dbb = new QuanLyCafeEntities())
     {
         data.alltablefoods = dbb.tablefoods.SqlQuery("select * from tablefood").ToList();
     }
     return(View(data));
 }