예제 #1
0
        public JsonResult SaveDataTypeRoom(TypeRoomViewModel roomType)
        {
            bool   status  = false;
            string message = string.Empty;

            tblLoaiPhong loaiPhong = new tblLoaiPhong();

            loaiPhong.loai_phong    = roomType.ID;
            loaiPhong.gia           = roomType.Price;
            loaiPhong.ti_le_phu_thu = roomType.Percent;
            loaiPhong.mo_ta         = roomType.TypeRoom;
            loaiPhong.anh           = roomType.Image;

            if (roomType.ID == 0)
            {
                //Thêm mới
                db.tblLoaiPhongs.Add(loaiPhong);
                try
                {
                    db.SaveChanges();
                    status = true;
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }
            else
            {
                //Đang cập nhật dữ liệu
                var entity = db.tblLoaiPhongs.Find(roomType.ID);
                entity.mo_ta         = roomType.TypeRoom;
                entity.gia           = roomType.Price;
                entity.ti_le_phu_thu = roomType.Percent;
                //entity.trang_thai = service.Status;
                entity.anh = roomType.Image;

                //entity.CreatedDate = DateTime.Now;
                try
                {
                    db.SaveChanges();
                    status = true;
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }

            return(Json(new
            {
                status = status,
                message = message
            }));
        }
        //Get All Rooo Type
        public IEnumerable <TypeRoomViewModel> GetAllType()
        {
            List <TypeRoomViewModel> TypeRoom = new List <TypeRoomViewModel>();

            foreach (var item in db.RoomTypes)
            {
                TypeRoomViewModel obj = new TypeRoomViewModel();
                obj.RoomType1 = item.RoomType1;
                obj.Type      = item.Type;
                TypeRoom.Add(obj);
            }
            return(TypeRoom);
        }
예제 #3
0
        public JsonResult GetDetailTypeRoom(int id)
        {
            try
            {
                db.Configuration.ProxyCreationEnabled = false;
                var typeRoom = db.tblLoaiPhongs.Find(id);
                TypeRoomViewModel typeRoomViewModel = new TypeRoomViewModel();
                typeRoomViewModel.ID       = typeRoom.loai_phong;
                typeRoomViewModel.Image    = typeRoom.anh;
                typeRoomViewModel.Percent  = typeRoom.ti_le_phu_thu;
                typeRoomViewModel.Price    = typeRoom.gia;
                typeRoomViewModel.TypeRoom = typeRoom.mo_ta;

                return(Json(new
                {
                    data = typeRoomViewModel,
                    status = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception error)
            {
                return(Json(new { status = false, message = error.ToString() }, JsonRequestBehavior.AllowGet));
            }
        }