import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import { AppConfig } from '../../app.config'; import { ResultMessage } from '../../../viewmodel/result'; import { ServiceCommon } from "../service.common"; import {RefundView} from "../../../viewmodel/myexam/RefundView"; import 'rxjs/add/operator/toPromise'; @Injectable() export class MyexamService { constructor(private http: Http) { } getMyexamListView(count: number): Promise { let url: string = AppConfig.getServiceUrl(); url += "MyexamServices/MyexamListView"; return this.http.post(url, JSON.stringify({ userID: localStorage.userID, pageIndex: 0, pageSize: count }), {headers: ServiceCommon.getHeader()}) .toPromise() .then(res => { return { isSuccess: true, message: "", data: res.json().rows } as ResultMessage; }) .catch(ServiceCommon.serviceErrorHandler); } canPay(examinationRegistrationID:string): Promise { let url: string = AppConfig.getServiceUrl(); url += "ExamineApply/CanPay"; return this.http.post(url, JSON.stringify({ examinationRegistrationID: examinationRegistrationID }), {headers: ServiceCommon.getHeader()}) .toPromise() .then(res => { let result = res.json(); return { isSuccess: result.IsSuccess, message: result.Message, data: null } as ResultMessage; }) .catch(ServiceCommon.serviceErrorHandler); } cancel(ExaminationRegistrationID:string): Promise{ let url: string = AppConfig.getServiceUrl(); url += "MyexamServices/Cancel"; return this.http.post(url, JSON.stringify({ExaminationRegistrationID:ExaminationRegistrationID}), {headers: ServiceCommon.getHeader()}) .toPromise() .then(res => { return res.json() as ResultMessage; }) .catch(ServiceCommon.serviceErrorHandler); } messageSubmit(ExaminationRegistrationID:string,refundView:RefundView): Promise{ let url: string = AppConfig.getServiceUrl(); url += "MyexamServices/CancelApply"; return this.http.post(url, JSON.stringify({ExaminationRegistrationID:ExaminationRegistrationID,RefundView:refundView}), {headers: ServiceCommon.getHeader()}) .toPromise() .then(res => { return res.json() as ResultMessage; }) .catch(ServiceCommon.serviceErrorHandler); } }