// get nhan vien
        public ActionResult NhanVien(int?page)
        {
            NhaHangEntities NhaHang  = new NhaHangEntities();
            var             NhanVien = NhaHang.Database.SqlQuery <NhanVienModel>("exec sp_ListAllNhanVien").ToPagedList(page ?? 1, 1000);

            return(View(NhanVien));
        }
        // get ma giam gia
        public ActionResult MaGiamGia(int?page)
        {
            NhaHangEntities NhaHang_Ban    = new NhaHangEntities();
            MaGiamGiaModel  maGiamGiaModel = new MaGiamGiaModel();
            int             pageSize       = 1000;
            int             pageNumber     = page ?? 1;

            maGiamGiaModel.MaGiamGiaModels = (from MGG in NhaHang_Ban.MaGiamGias
                                              select MGG).OrderBy(mgg => mgg.Magiamgia1).ToPagedList(pageNumber, pageSize);
            return(View(maGiamGiaModel));
        }
        // get hoa don
        public ActionResult HoaDon(int?page)
        {
            NhaHangEntities NhaHang      = new NhaHangEntities();
            HoaDonModel     hoaDonModels = new HoaDonModel();
            int             pageSize     = 1000;
            int             pageNumber   = page ?? 1;

            hoaDonModels.HoaDonModels = (from HD in NhaHang.HoaDons
                                         select HD).OrderBy(hd => hd.Idhoadon).ToPagedList(pageNumber, pageSize);
            return(View(hoaDonModels));
        }
        // get ban
        public ActionResult Ban(int?page)
        {
            NhaHangEntities NhaHang_Ban = new NhaHangEntities();
            BanModel        banModel    = new BanModel();
            int             pageSize    = 1000;
            int             pageNumber  = page ?? 1;

            banModel.BanModels = (from B in NhaHang_Ban.Bans
                                  select B).OrderBy(b => b.Idban).ToPagedList(pageNumber, pageSize);
            return(View(banModel));
        }
        // update hoa don
        public bool UpdateHoaDon(int id)
        {
            var hoaDon = new SqlParameter();

            hoaDon.ParameterName = "@Idhoadon";
            hoaDon.SqlValue      = id;
            NhaHangEntities NhaHang = new NhaHangEntities();

            try
            {
                NhaHang.Database.ExecuteSqlCommand("exec DocThongTinHoaDon_Truoc @Idhoadon", hoaDon);
                return(true);
            }
            catch (SqlException err)
            {
                Console.Write(err);
                return(false);
            }
        }
        public ActionResult Index(int?page)
        {
            NhaHangEntities NhaHang    = new NhaHangEntities();
            MonAnQuery      ListMonAn  = new MonAnQuery();
            HomeModel       homeModel  = new HomeModel();
            int             pageSize   = 1000;
            int             pageNumber = (page ?? 1);

            homeModel.MonAnQueries = (from MA in NhaHang.MonAns
                                      join LM in NhaHang.LoaiMons on MA.Idloaimon equals LM.Idloaimon
                                      select new MonAnQuery()
            {
                Idmon = MA.Idmon,
                TenMon = MA.Tenmon,
                Gia = MA.Gia,
                LoaiMon = LM.Tenloaimon,
            }).OrderBy(MonAn => MonAn.Gia).ToPagedList(pageNumber, pageSize);
            homeModel.LoaiMons = (from LM in NhaHang.LoaiMons select LM).ToList();
            return(View(homeModel));
        }
        // edit ma giam gia
        public bool EditMgg(string Mgg, int solan, int flag)
        {
            var mgg = new SqlParameter();

            mgg.ParameterName = "@Magiamgia";
            mgg.SqlDbType     = SqlDbType.VarChar;
            mgg.Size          = 10;
            mgg.SqlValue      = Mgg;
            var soLan = new SqlParameter();

            soLan.ParameterName = "@Soluong";
            soLan.SqlDbType     = SqlDbType.Int;
            soLan.SqlValue      = solan;
            NhaHangEntities NhaHang = new NhaHangEntities();

            if (flag == 1)
            {
                try
                {
                    NhaHang.Database.ExecuteSqlCommand("exec sp_CapNhatMaGiamGia_Truoc @Magiamgia, @Soluong", mgg, soLan);

                    return(true);
                }
                catch (SqlException err)
                {
                    Console.Write(err);
                    return(false);
                }
            }
            try
            {
                NhaHang.Database.ExecuteSqlCommand("exec sp_CapNhatMaGiamGia_Sau @Magiamgia, @Soluong", mgg, soLan);
                return(true);
            }
            catch (SqlException err)
            {
                Console.Write(err);
                return(false);
            }
        }
        // edit mon an
        public bool EditMonAn(int monan, int gia, int flag)
        {
            var monAn = new SqlParameter();

            monAn.ParameterName = "@Idmon";
            monAn.SqlDbType     = SqlDbType.VarChar;
            monAn.SqlValue      = monan;
            var Gia = new SqlParameter();

            Gia.ParameterName = "@Gia";
            Gia.SqlDbType     = SqlDbType.Int;
            Gia.SqlValue      = gia;
            NhaHangEntities NhaHang = new NhaHangEntities();

            if (flag == 1)
            {
                try
                {
                    NhaHang.Database.ExecuteSqlCommand("exec sp_CapNhatGiaMonAn_Truoc @Idmon, @Gia", monAn, Gia);

                    return(true);
                }
                catch (SqlException err)
                {
                    Console.Write(err);
                    return(false);
                }
            }
            try
            {
                NhaHang.Database.ExecuteSqlCommand("exec sp_CapNhatGiaMonAn_Sau @Idmon, @Gia", monAn, Gia);
                return(true);
            }
            catch (SqlException err)
            {
                Console.Write(err);
                return(false);
            }
        }
        // edit hoa don
        public bool EditHoaDon(int id, int ca)
        {
            var hoaDon = new SqlParameter();

            hoaDon.ParameterName = "@Idhoadon";
            hoaDon.SqlValue      = id;
            var Ca = new SqlParameter();

            Ca.ParameterName = "@Ca";
            Ca.SqlValue      = ca;
            NhaHangEntities NhaHang = new NhaHangEntities();

            try
            {
                NhaHang.Database.ExecuteSqlCommand("exec CapnhatHoaDon_Sau @Idhoadon, @Ca", hoaDon, Ca);
                return(true);
            }
            catch (SqlException err)
            {
                Console.Write(err);
                return(false);
            }
        }
        // edit ban
        public bool EditBan(int id, int soghe, int flag)
        {
            var idBan = new SqlParameter();

            idBan.ParameterName = "@idban";
            idBan.SqlDbType     = SqlDbType.Int;
            idBan.SqlValue      = id;
            var ghe = new SqlParameter();

            ghe.ParameterName = "@soghe";
            ghe.SqlDbType     = SqlDbType.Int;
            ghe.SqlValue      = soghe;
            NhaHangEntities NhaHang = new NhaHangEntities();

            if (flag == 1)
            {
                try
                {
                    NhaHang.Database.ExecuteSqlCommand("exec sp_EditTableWait @idban, @soghe", idBan, ghe);
                    return(true);
                }
                catch (SqlException err)
                {
                    return(false);
                }
            }
            try
            {
                NhaHang.Database.ExecuteSqlCommand("exec sp_EditTable @idban, @soghe", idBan, ghe);
                return(true);
            }
            catch (SqlException err)
            {
                return(false);
            }
        }