Exemple #1
0
        private AjaxReponseModel <dynamic> UpdateProduct()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Product>(data);
                int maSP = dym.MaSP;
                using (var db = new qlksEntities())
                {
                    tblSanPham sp = db.tblSanPhams.SingleOrDefault(w => w.MaSP == maSP);
                    sp.TenSP  = String.IsNullOrEmpty(dym.TenSP.ToString()) ? String.Empty : dym.TenSP.ToString().Trim();
                    sp.DonGia = dym.DonGia;

                    db.SaveChanges();
                    response.Message = "SUCCESS";
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }
Exemple #2
0
        private AjaxReponseModel <dynamic> UpdateCustomer()
        {
            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);
                    kh.TenKH    = String.IsNullOrEmpty(dym.TenKH.ToString()) ? String.Empty : dym.TenKH.ToString().Trim();
                    kh.SDT      = String.IsNullOrEmpty(dym.SDT.ToString()) ? String.Empty : dym.SDT.ToString().Trim();
                    kh.Email    = String.IsNullOrEmpty(dym.Email.ToString()) ? String.Empty : dym.Email.ToString().Trim();
                    kh.DiaChi   = String.IsNullOrEmpty(dym.DiaChi.ToString()) ? String.Empty : dym.DiaChi.ToString().Trim();
                    kh.NgaySinh = dym.NgaySinh;
                    kh.GioiTinh = dym.GioiTinh;
                    kh.CMND     = dym.CMND;

                    db.SaveChanges();
                    response.Message = "SUCCESS";
                };

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

                    if (dym.SanPhamPhong != null && dym.SanPhamPhong.Length != 0)
                    {
                        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);
        }
Exemple #4
0
        private AjaxReponseModel <dynamic> PaymentBookingRoom()
        {
            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 pdp = db.tblPhieuDatPhongs.FirstOrDefault(f => f.MaPhieuDP == dym.MaPhieuDP);
                    if (pdp != null)
                    {
                        pdp.TrangThai = true;

                        var p = db.tblPhongs.FirstOrDefault(f => f.MaPhong == pdp.MaPhong);
                        if (p != null)
                        {
                            p.TrangThai = false;
                        }

                        db.SaveChanges();

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

            return(response);
        }
Exemple #5
0
        private AjaxReponseModel <dynamic> DeleteProduct()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Product>(data);
                int maSP = dym.MaSP;
                using (var db = new qlksEntities())
                {
                    tblSanPham      sp  = db.tblSanPhams.SingleOrDefault(w => w.MaSP == maSP);
                    tblSanPhamPhong pdp = db.tblSanPhamPhongs.SingleOrDefault(w => w.MaSP == maSP);
                    if (pdp != null && pdp.MaPhieuDP > 0)
                    {
                        response.Message = "PDP_EXIST";
                    }
                    else
                    {
                        db.tblSanPhams.Remove(sp);
                        db.SaveChanges();
                        response.Message = "SUCCESS";
                    }
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }
Exemple #6
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);
        }