//Importing the libraries import { Injectable } from '@angular/core'; import { Http, Headers, Response, RequestOptions, URLSearchParams } from '@angular/http'; import { Observable } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; import 'rxjs/add/observable/throw'; //Importing core classes import * as globals from '../core/common'; import { ITaskDetails } from '../core/ITaskDetails'; import { ITaskTypes } from '../core/ITaskTypes'; import { IAssociateRecords } from '../core/IAssociateRecords '; @Injectable({ providedIn: 'root' }) export class TasksService { //API calls private GetAllTasksDetailsByContactIdUrl = globals.serverBase + '/api/ContactDetails/GetAllTasksDetailsByContactId'; private ChangeOrderOfTasksUrl = globals.serverBase + '/api/ContactDetails/ChangeOrderOfTasks'; private GetAllTasksTypesUrl = globals.serverBase + '/api/ContactDetails/GetAllTasksTypes'; private SaveTasksDetailsUrl = globals.serverBase + '/api/ContactDetails/SaveTasksDetails'; private GetAssociateRecordsUrl = globals.serverBase + '/api/ContactDetails/GetAssociateRecords'; private GetTasksAssociateRecordsurl = globals.serverBase + '/api/ContactDetails/GetTasksAssociateRecords'; private CompleteTasksRecordsUrl = globals.serverBase + '/api/ContactDetails/CompleteTasksRecords'; private GetAllFilterTasksDetailsUrl = globals.serverBase + '/api/ContactDetails/GetAllFilterTasksDetails'; //The webapi controller urls private AppUrl = globals.serverBase + '/api/ContactDetails'; headers: any; constructor(private http: Http) { } // Get contact details GetAllTasksDetailsByContactId(contactId: number) { let myparams = new URLSearchParams(); myparams.append("contactId", contactId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.GetAllTasksDetailsByContactIdUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Change task order ChangeOrderOfTasks(taskId: any, loginStaffId: number) { let myparams = new URLSearchParams(); myparams.append("taskId", taskId.toString()); myparams.append("loginStaffId", loginStaffId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.ChangeOrderOfTasksUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Get all tasks types GetAllTasksTypes() { return this.http.get(this.GetAllTasksTypesUrl) .map((response: Response) => response.json()) .catch(this.handleError); } // Save Task SaveTasksDetails(tasksObject: ITaskDetails, associateRecords: string) { // debugger let myparams = new URLSearchParams(); myparams.append("associateRecords", associateRecords.toString()); let options = new RequestOptions({ params: myparams }); return this.http.post(this.SaveTasksDetailsUrl, tasksObject, options) .map((response: Response) => response.json()).catch(this.handleError); } // Get Associate Records GetAssociateRecords(contactId: number) { let myparams = new URLSearchParams(); myparams.append("contactId", contactId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.GetAssociateRecordsUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Get Tasks AssociateRecords GetTasksAssociateRecords(TaskDetailsId: any) { let myparams = new URLSearchParams(); myparams.append("TaskDetailsId", TaskDetailsId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.GetTasksAssociateRecordsurl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Complete Task CompleteTasksRecords(taskId: any) { let myparams = new URLSearchParams(); myparams.append("taskId", taskId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.CompleteTasksRecordsUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Filter Tasks GetAllFilterTasksDetails(dateFrom: string, dateTo: string, ownerId: number, flag: number) { let myparams = new URLSearchParams(); if (ownerId == null && ownerId == undefined) { ownerId = 0; } myparams.append("fromDate", dateFrom.toString()); myparams.append("toDate", dateTo.toString()); myparams.append("staffId", ownerId.toString()); myparams.append("flag", flag.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.GetAllFilterTasksDetailsUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } //------------- Common methods ----------------// //The function of handling the error private handleError(error: Response) { //console.log("Error in contact service"); //console.log(error); return Observable.throw('Server error'); } errorHandler(error: Response) { //console.log(error); } }