room-detail.service.ts 3.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { roomDetail, SearchroomDetailModel } from '../models/roomDetail.model';

@Injectable({ providedIn: 'root' })
export class roomDetailService {

    constructor(private http: HttpClient) { }
    url: string;
    listroomDetail: roomDetail[] = [
        {
            Id: 1,
            room: {
                rId: 1,
                rName: "ห้องเดียว",
                rPic: "assets/img/room.jpg",
                roomLimit: 25,
                rDesc: "จำนวนคน 25 คน",
            },
            userName: 'เกม',
            sDate: '10/12/2560',
            eDate: '10/11/2561',
            sTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eStatus: 'รอการอนุมัติ',
            Remark: 'test',
        },
        {
            Id: 2,
            room: {
                rId: 2,
                rName: "ห้องคู่",
                rPic: "assets/img/room.jpg",
                roomLimit: 50,
                rDesc: "จำนวนคน 50 คน",
            },
            userName: 'เกม',
            sDate: '10/12/2560',
            eDate: '10/11/2561',
            sTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eStatus: 'รอการอนุมัติ',
            Remark: 'test',
        },

    ]

    addroomDetail(model: roomDetail) {
        console.log(this.listroomDetail);
        this.listroomDetail.push(model);

    }

    getListroomDetail() {
        return this.listroomDetail;
    }

    // getListroomDetail() {
    //   this.http.get(this.url).subscribe((response: any) => {
    //     console.log(response);
    //     this.listroomDetail = response.content;
    //   }, error => {
    //     console.log(error)
    //     // alert("ไม่สามารถดึงข้อมูลห้องประชุมได้ เนื่องจาก :\n" + error.message)
    //   })
    // }

    searchListroomDetail(searchModel: SearchroomDetailModel) {
        this.http.get(this.url + '&startDate=' + searchModel.sDate.split("-")[2] + '-' + searchModel.sDate.split("-")[1] + '-' + searchModel.sDate.split("-")[0] + '&endDate=' + searchModel.eDate.split("-")[2] + '-' + searchModel.eDate.split("-")[1] + '-' + searchModel.eDate.split("-")[0] + '&startTime=' + searchModel.sTime + ':00' + '&endTime=' + searchModel.eTime + ':00').subscribe((response: any) => {
            console.log(response);
            this.listroomDetail = response;
        }, error => {
            console.log(error)
            alert("ไม่สามารถค้นหาอุปกรณ์ที่ว่างได้ เนื่องจาก :\n" + error.message)
        })
    }

    // addEquirment(EquirmentModel: Equirment) {
    //   this.http.post(this.url, EquirmentModel).subscribe(response => {
    //     console.log(response);

    //   })


    // }
    deleteroomDetail(roomDetailModel: roomDetail) {
        this.http.delete(this.url + "/" + roomDetailModel.Id).subscribe(response => {
            console.log(response);
            this.getListroomDetail()
            alert("ลบข้อมูลอุปกรณ์สำเร็จ")
        })
    }

    updateroomDetail(roomDetailModel: roomDetail) {
        this.http.put(this.url + "/" + roomDetailModel.Id, roomDetailModel).subscribe(response => {
            console.log(response);
            alert("อัพเดทข้อมูลอุปกรณ์สำเร็จ")
        })
    }

    roomDetailModel(rId: string) {

    }

}