user.service.ts
6.47 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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 + "User/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 + "User/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 + "User/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 + "User/UpdateUserId", obj)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
/// End ////
/// Users List Form///////
GetUserType() {
return this.http.get(this.commonService.resourceBaseUrl + "User/GetUserType/"+this.commonService.UserType)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
GetAccountType() {
return this.http.get(this.commonService.resourceBaseUrl + "User/GetAccountType/"+this.commonService.AccountType)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
GetUserList(obj: any) {
return this.http.get(this.commonService.resourceBaseUrl + "User/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));
}
UpdateUserEntity(obj: any) {
//let options = new RequestOptions({ headers: this.headers });
var jsonData = { 'id': obj.id, 'FirstName': obj.FirstName, 'LastName': obj.LastName, 'EmailId': obj.EmailId, 'UserName': obj.UserName, 'Password': obj.Password, 'Modifiedby': this.commonService.UserId, 'IsActive': obj.isActive};
console.log(obj);
var headers = new Headers({
'Content-Type': 'application/json'
});
return this.http.post(this.commonService.resourceBaseUrl + "User/UpdateUser",
JSON.stringify(jsonData), { headers: headers })
.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 + "User/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 + "User/GetAccountNumber").
map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
GetProductEdition(obj: any) {
return this.http.get(this.commonService.resourceBaseUrl + "User/GetProductEdition?LicenseId=" + obj.AccountNumberId)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
InsertUser(obj: any)
{
//let options = new RequestOptions({ headers: this.headers });
var jsonData = { 'id': this.commonService.UserId, 'FirstName': obj.FirstName, 'LastName': obj.LastName, 'EmailId': obj.EmailId, 'UserName': obj.UserName, 'Password': obj.Password, 'AccountNumberId': obj.AccountNumberId, 'UserTypeId': obj.UserTypeId, 'ProductEditionId':obj.ProductEditionId };
console.log(obj);
var headers = new Headers({
'Content-Type': 'application/json'
});
return this.http.post(this.commonService.resourceBaseUrl + "User/NewUser",
JSON.stringify(jsonData), { headers: headers })
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
/// End //////
//// UnBlocked User
GetBlockUserList(obj: any) {
return this.http.get(this.commonService.resourceBaseUrl + "User/BlockedUser?UserTypeId=" + obj.UserTypeId +
"&LicenseId=" + obj.LicenseId)
.map(this.extractData)
.catch((res: Response) => this.handleError(res));
}
UpdateUnBlockedUser(obj: any) {
//let options = new RequestOptions({ headers: this.headers });
var UserIds = obj;
console.log(UserIds);
var headers = new Headers({
'Content-Type': 'application/json'
});
return this.http.post(this.commonService.resourceBaseUrl + "User/UnblockedUser",
UserIds, { headers: headers })
.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';
error.status ? `${error._body}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}