user.service.ts
4.29 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
116
117
118
import { Injectable, Inject } from '@angular/core';
//import { HttpClient, HttpParams, HttpRequest} from "@angular/common/http";
import { Http, Response, Headers, RequestOptions, HttpModule } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import { User } from '../UserEntity/datamodel';
import 'rxjs/add/operator/do';
import { Observable } from 'rxjs/Observable';
import { GlobalService } from '../../Shared/global';
@Injectable()
export class UserService {
constructor(private http: Http, private commonService: GlobalService ) { }
//////////Get User Detail///////////////
GetUserById() {
debugger;
return this.http.get(this.commonService.resourceBaseUrl + "/GetUserProfile/"+this.commonService.UserId)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));;
}
//////////Update User Detail///////////////
UpdateUserProfileById(obj: User) {
//let options = new RequestOptions({ headers: this.headers });
return this.http.post(this.commonService.resourceBaseUrl + "/UpdateProfile", obj)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
//////////// End /////////////////////
//////////Update User Password///////////
ChangeUserPassword(obj: any) {
//let options = new RequestOptions({ headers: this.headers });
var jsonData = { 'id': obj.userId, 'newPassword': obj.newPassword };
console.log(obj);
var headers = new Headers({
'Content-Type': 'application/json'
});
return this.http.post(this.commonService.resourceBaseUrl + "/ChangeUserPassword",
JSON.stringify(jsonData), { headers: headers })
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
//////////// End /////////////////////
//////////Update User Userid///////////////
UpdateUserId(obj: User) {
//let options = new RequestOptions({ headers: this.headers });
return this.http.post(this.commonService.resourceBaseUrl + "/UpdateUserId", obj)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
/// End ////
/// Users List Form///////
GetUserType() {
return this.http.get(this.commonService.resourceBaseUrl + "/GetUserType/"+this.commonService.UserType)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
GetAccountType() {
return this.http.get(this.commonService.resourceBaseUrl + "/GetAccountType/"+this.commonService.AccountType)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
GetUserList(obj: any) {
return this.http.get(this.commonService.resourceBaseUrl + "/Users?firstname=" + obj.FirstName +
"&lastname=" + obj.LastName +
"&emailid=" + obj.EmailId +
"&accountnumber=" + obj.AccountNumber +
"&usertypeid=" + obj.UserTypeId +
"&accounttypeid=" + obj.AccountTypeId)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
/// End Users /////
/// Add User Entity///
GetUserTypeByLicenseType(obj: any) {
debugger;
return this.http.get(this.commonService.resourceBaseUrl + "/GetUserTypebyLicenseId?UserTypeId=" + this.commonService.UserType + "&LicenseId=" + obj.AccountNumberId)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
GetAccountNumber() {
return this.http.get(this.commonService.resourceBaseUrl + "/GetAccountNumber").
map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
GetProductEdition(obj: any) {
return this.http.get(this.commonService.resourceBaseUrl + "/GetProductEdition?LicenseId=" + obj.AccountNumberId)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
/// End //////
extractData(res: Response) {
debugger;
let body = res.json();
return body;
}
handleError(error: any) {
debugger;
// In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}