Esempio n. 1
0
        private AjaxReponseModel <dynamic> DeleteCustomer()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Customer>(data);
                int maKH = dym.MaKH;
                using (var db = new qlksEntities())
                {
                    tblKhachHang     kh  = db.tblKhachHangs.SingleOrDefault(w => w.MaKH == maKH);
                    tblPhieuDatPhong pdp = db.tblPhieuDatPhongs.SingleOrDefault(w => w.MaKH == maKH);
                    if (pdp != null && pdp.MaPhieuDP > 0)
                    {
                        response.Message = "PDP_EXIST";
                    }
                    else
                    {
                        db.tblKhachHangs.Remove(kh);
                        db.SaveChanges();
                        response.Message = "SUCCESS";
                    }
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }
Esempio n. 2
0
        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;
                        }

                        if (dym.SanPhamPhong != null && dym.SanPhamPhong.Length != 0)
                        {
                            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);
        }