update-user.service.ts
4.19 KB
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
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions, URLSearchParams } from '@angular/http';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { UserProfile } from '../model/data-model';
//import { AppSettings, User } from '../model/data-model';
@Injectable()
export class UpdateUserService {
//appSettingsLoaded: boolean;
//appSettings: AppSettings;
//currentUser: User;
//loggedIn: boolean;
userId: number;
firstName: string;
lastName: string;
emailId: string;
userInfo: UserProfile;
private headers: Headers;
constructor(private http: Http, private router: Router) {
//if (this.currentUser == null) {
// var user = localStorage.getItem("currentUser");
// if (user != null) {
// this.currentUser = JSON.parse(user);
// this.loggedIn = true;
// }
//}
this.userId = 0;
this.firstName = "";
this.lastName = "";
this.emailId = "";
}
private extractData(res: Response) {
let body = res.json();
return body || {};
}
private handleError(error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}
public UpdateUserProfile(applicationName: string, strFirstName: string, strLastName: string, strEmailID: string): Observable<any> {
console.log('inside application service');
let usrID: number;
usrID = 1;
let headers = new Headers({ 'Content-Type': 'application/json' });
//let headers = new Headers();
//headers.append('Content-type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let body = JSON.stringify({ userId: usrID, emailId: strEmailID, firstName: strFirstName, lastName: strLastName });
console.log(body);
return this.http.post('http://localhost:85/AIAHTML5.Server/api/updateprofile', body, options)
.map(this.extractData)
.catch(this.handleError);
}
public UpdateUserProfile2(applicationName: string, strFirstName: string, strLastName: string, strEmailID: string): Observable<any> {
console.log('inside update-user service -2');
let usrID: number;
usrID = 1;
//let headers = new Headers({ 'Content-Type': 'application/json' });
let headers = new Headers();
headers.append('Content-type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let body = 'userId=' + usrID + '&emailId=' + strEmailID + '&firstName=' + strFirstName + '&lastName=' + strLastName;
console.log(body);
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('userId', usrID.toString());
urlSearchParams.append('firstName', strFirstName);
urlSearchParams.append('lastName', strLastName);
urlSearchParams.append('emailId', strEmailID);
let body2 = urlSearchParams.toString()
return this.http.post('http://localhost:85/AIAHTML5.Server/api/updateprofile', body, options)
.map((response: Response) => {
console.log(response);
var body = response.json();
console.log(body);
})
.catch(this.logError);
}
private extractData2(res: Response) {
let body = res.json();
console.log('ServiceResult: ' + body);
return body || {};
}
logError(error: Response | any) {
console.log('ServiceError: ' + err);
}
}