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); } }