private AjaxReponseModel <dynamic> SaveBookingRoom()
        {
            var         response  = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);
            var         data      = new StreamReader(Request.InputStream).ReadToEnd();
            var         dym       = JsonConvert.DeserializeObject <BookingRoomModel>(data);
            tblNhanVien userLogin = Session["UserLogin"] as tblNhanVien;

            try
            {
                using (var db = new qlksEntities())
                {
                    tblPhieuDatPhong datPhong = new tblPhieuDatPhong()
                    {
                        MaKH     = dym.MaKH,
                        MaPhong  = dym.MaPhong,
                        MaNV     = userLogin.MaNV,
                        NgayBD   = dym.NgayBD,
                        NgayKT   = dym.NgayKT,
                        TongTien = dym.TongTien,
                        DonGia   = dym.DonGia
                    };

                    db.tblPhieuDatPhongs.Add(datPhong);
                    var numberSave = db.SaveChanges();

                    if (numberSave > 0)
                    {
                        var room = db.tblPhongs.FirstOrDefault(f => f.MaPhong == dym.MaPhong);
                        if (room != null)
                        {
                            room.TrangThai = true;
                        }

                        List <tblDichVuPhong> listDVP = new List <tblDichVuPhong>();
                        foreach (var item in dym.DichVuPhong)
                        {
                            tblDichVuPhong dichVuPhong = new tblDichVuPhong()
                            {
                                MaPhieuDP = datPhong.MaPhieuDP,
                                MaDV      = item.MaDV,
                                SoLuong   = item.SoLuong,
                                DonGia    = item.DonGia,
                                ThanhTien = item.ThanhTien
                            };
                            listDVP.Add(dichVuPhong);
                        }

                        db.tblDichVuPhongs.AddRange(listDVP);

                        List <tblSanPhamPhong> listSPP = new List <tblSanPhamPhong>();
                        foreach (var item in dym.SanPhamPhong)
                        {
                            tblSanPhamPhong dichVuPhong = new tblSanPhamPhong()
                            {
                                MaPhieuDP = datPhong.MaPhieuDP,
                                MaSP      = item.MaSP,
                                SoLuong   = item.SoLuong,
                                DonGia    = item.DonGia,
                                ThanhTien = item.ThanhTien
                            };
                            listSPP.Add(dichVuPhong);
                        }

                        db.tblSanPhamPhongs.AddRange(listSPP);

                        db.SaveChanges();

                        response.Message = "Đặt phòng thành công.";
                    }
                    else
                    {
                        response.Status  = AjaxReponseStatusEnum.Fail;
                        response.Message = "Đặt phòng thất bại.";
                    }
                };
            }
            catch (Exception e)
            {
                response.Status  = AjaxReponseStatusEnum.Fail;
                response.Message = "Đặt phòng thất bại (Exception).";
            }

            return(response);
        }
        private AjaxReponseModel <dynamic> UpdateBookingRoom()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);
            var data     = new StreamReader(Request.InputStream).ReadToEnd();
            var dym      = JsonConvert.DeserializeObject <BookingRoomModel>(data);

            try
            {
                using (var db = new qlksEntities())
                {
                    var room = db.tblPhongs.FirstOrDefault(f => f.MaPhong == dym.MaPhong);
                    if (room != null)
                    {
                        room.TrangThai = true;
                    }

                    foreach (var item in dym.DichVuPhong)
                    {
                        if (item.MaDVP != null && item.MaDVP != 0)
                        {
                            var dvp = db.tblDichVuPhongs.FirstOrDefault(f => f.MaPhieuDP == dym.MaPhieuDP && f.MaDVP == item.MaDVP);
                            dvp.SoLuong   = item.SoLuong;
                            dvp.ThanhTien = item.ThanhTien;
                        }
                        else
                        {
                            tblDichVuPhong dichVuPhong = new tblDichVuPhong()
                            {
                                MaPhieuDP = dym.MaPhieuDP,
                                MaDV      = item.MaDV,
                                SoLuong   = item.SoLuong,
                                DonGia    = item.DonGia,
                                ThanhTien = item.ThanhTien
                            };
                            db.tblDichVuPhongs.Add(dichVuPhong);
                        }
                    }

                    foreach (var item in dym.SanPhamPhong)
                    {
                        if (item.MaSPP != null && item.MaSPP != 0)
                        {
                            var dvp = db.tblSanPhamPhongs.FirstOrDefault(f => f.MaPhieuDP == dym.MaPhieuDP && f.MaSPP == item.MaSPP);
                            dvp.SoLuong   = item.SoLuong;
                            dvp.ThanhTien = item.ThanhTien;
                        }
                        else
                        {
                            tblSanPhamPhong dichVuPhong = new tblSanPhamPhong()
                            {
                                MaPhieuDP = dym.MaPhieuDP,
                                MaSP      = item.MaSP,
                                SoLuong   = item.SoLuong,
                                DonGia    = item.DonGia,
                                ThanhTien = item.ThanhTien
                            };
                            db.tblSanPhamPhongs.Add(dichVuPhong);
                        }
                    }

                    db.SaveChanges();

                    response.Message = "Cập nhật thành công.";
                };
            }
            catch (Exception e)
            {
                response.Status  = AjaxReponseStatusEnum.Fail;
                response.Message = "Cập nhật thất bại (Exception).";
            }

            return(response);
        }