//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 { INotes } from '../core/INotes'; import { INotesTypes } from '../core/INotesTypes'; import { IAssociateRecords } from '../core/IAssociateRecords '; import { IStaffs } from '../core/IStaffs'; @Injectable({ providedIn: 'root' }) export class NotesService { //The webapi controller urls private SaveNotesDetailsUrl = globals.serverBase + '/api/ContactDetails/SaveNotesDetails'; private GetAllNotesTypesUrl = globals.serverBase + '/api/ContactDetails/GetAllNotesTypes'; private GetAllNotesDetailsUrl = globals.serverBase + '/api/ContactDetails/GetAllNotesDetailsByContactId'; private ChangeOrderOfNotesUrl = globals.serverBase + '/api/ContactDetails/ChangeOrderOfNotes'; private GetAssociateRecordsUrl = globals.serverBase + '/api/ContactDetails/GetAssociateRecords'; private GetNoteAssociateRecordsUrl = globals.serverBase + '/api/ContactDetails/GetNoteAssociateRecords'; private GetAllFilterNotesDetailsUrl = globals.serverBase + '/api/ContactDetails/GetAllFilterNotesDetails'; private AppUrl = globals.serverBase + '/api/ContactDetails'; headers: any; constructor(private http: Http) { this.headers = new Headers(); this.headers.append('Content-Type', 'application/x-www-form-urlencoded'); } // Save Notes SaveNotesDetails(INotes: INotes, task: boolean, bussinessDates: number, associateRecords: string) { let myparams = new URLSearchParams(); myparams.append("businessDays", bussinessDates.toString()); myparams.append("associateRecords", associateRecords.toString()); myparams.append("task", task.toString()); let options = new RequestOptions({ params: myparams }); //let options = myparams.toString(); return this.http.post(this.SaveNotesDetailsUrl, INotes, options) .map((response: Response) => response.json()).catch(this.handleError); } // Get All Notes Types GetAllNotesTypes() { return this.http.get(this.GetAllNotesTypesUrl) .map((response: Response) => response.json()) .catch(this.handleError); } // Get All Notes GetAllNotesDetails(contactId: number) { let myparams = new URLSearchParams(); myparams.append("contactId", contactId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.GetAllNotesDetailsUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Change notes order ChangeOrderOfNotes(noteId: any, loginStaffId: number) { let myparams = new URLSearchParams(); myparams.append("noteId", noteId.toString()); myparams.append("loginStaffId", loginStaffId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.ChangeOrderOfNotesUrl, 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 Associate Recoreds by Id GetNoteAssociateRecords(noteId: any) { let myparams = new URLSearchParams(); myparams.append("noteId", noteId.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.GetNoteAssociateRecordsUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Filter Notes GetAllFilterNotesDetails(fromDate: string, toDate: string, loginStaffId: number, flag: number) { let myparams = new URLSearchParams(); if (loginStaffId == null && loginStaffId == undefined) { loginStaffId = 0; } myparams.append("fromDate", fromDate.toString()); myparams.append("toDate", toDate.toString()); myparams.append("staffId", loginStaffId.toString()); myparams.append("flag", flag.toString()); let options = new RequestOptions({ params: myparams }); return this.http.get(this.GetAllFilterNotesDetailsUrl, options) .map((response: Response) => response.json()) .catch(this.handleError); } // Get Owner List GetOwnerList() { return this.http.get(this.AppUrl + '/GetOwnerList') .map((response: Response) => response.json()) .catch(this.handleError); } // Filter email GetAllFilterEmailsDetails(dateFrom: string, dateTo: string, ownerId: number, flag: number, subjectTitle: string) { throw new Error("Method not implemented."); } //------------ 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); } }