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, public commonService: GlobalService ) { } //////////Get User Detail/////////////// GetUserById() { return this.http.get(this.commonService.resourceBaseUrl + "User/GetUserProfile/"+this.commonService.UserId) .map(this.extractData) .catch((res: Response) => this.handleError(res));; } GetUserDetailById(UserId: Number) { return this.http.get(this.commonService.resourceBaseUrl + "User/GetUserDetail/"+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 ///////////////////// //////////Manage UserLogin Status/////////// ManageUserLoginStatus(obj: any) { var jsonData = { 'userId': obj.userId, 'tagName': obj.tagName,'SessionId': obj.SessionId,'isSiteUser': obj.isSiteUser,'isAdmin': obj.isAdmin }; console.log(obj); var headers = new Headers({ 'Content-Type': 'application/json' }); return this.http.post(this.commonService.resourceBaseUrl + "User/ManageUserLoginStatus", 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, pageNo: number, pageLength: number) { 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 + "&userLoginStatus=" + obj.LoginStatus + "&pageNo=" + pageNo + "&pageLength=" + pageLength + "&iLoginUserType=" + this.commonService.UserType + "&loggedIn="+this.commonService.LoginId) .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,'DeactivationDate': obj.DeactivationDate}; 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)); } GetManageUserRights(obj: any) { return this.http.get(this.commonService.resourceBaseUrl + "User/ManageRight?UserId=" + obj.UserId + "&UserType=" + obj.UserType) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } UpdateManageUserRights(objUser: any, SelectedUserRights: any, UncheckedUserRights: any) { //let options = new RequestOptions({ headers: this.headers }); var jsonData = { 'UserId': objUser.id, 'UserType': objUser.UserTypeTitle, 'CheckedUserRights': SelectedUserRights, 'UnCheckedUserRights': UncheckedUserRights}; console.log(jsonData); var headers = new Headers({ 'Content-Type': 'application/json' }); return this.http.post(this.commonService.resourceBaseUrl + "User/InsertDeleteUserManageRights", JSON.stringify(jsonData), { headers: headers }) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetGeneralAdminMenu(obj: any) { return this.http.get(this.commonService.resourceBaseUrl + "User/ManageMenu?UserId=" + obj.UserId + "&UserType=" + obj.UserType) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } /// End Users ///// /// Add User Entity/// GetUserTypeByLicenseType(obj: any) { 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)); } GetLicenseAccounts(licenseType: Number) { return this.http.get(this.commonService.resourceBaseUrl + "License/LicenseAccounts?LicenseType=" + licenseType) .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/////// //// User Group//////// GetLicenseUserGroups(licensId: number, pageNo: number, pageLength: number) { return this.http.get(this.commonService.resourceBaseUrl + "UserGroup/LicenseUserGroups?LicenseId=" + licensId + "&pageNo=" + pageNo + "&pageLength=" + pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } GetLicenseUserGroupUsers(licensId: number, UserGroupId: number, allUsers: boolean, pageNo: number, pageLength: number) { return this.http.get(this.commonService.resourceBaseUrl + "UserGroup/LicenseUserGroupUsers?LicenseId=" + licensId + "&UserGroupId=" + UserGroupId + "&AllUsers=" + allUsers + "&pageNo=" + pageNo + "&pageLength=" + pageLength) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } InsertUpdateLicenseUserGroup(obj: any) { //let options = new RequestOptions({ headers: this.headers }); var jsonData = { 'id': obj.id, 'licenseId': obj.licenseId, 'creationDate': obj.creationDate, 'modifiedDate': obj.modifiedDate, 'title': obj.title, 'isActive': obj.isActive }; var headers = new Headers({ 'Content-Type': 'application/json' }); return this.http.post(this.commonService.resourceBaseUrl + "UserGroup/InsertUpdateLicenseUserGroup", JSON.stringify(jsonData), { headers: headers }) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } UpdateLicenseUserGroupUsers(userGroupId: number, userIds: string) { //let options = new RequestOptions({ headers: this.headers }); var jsonData = { 'userGroupId': userGroupId, 'userIds': userIds }; var headers = new Headers({ 'Content-Type': 'application/json' }); return this.http.post(this.commonService.resourceBaseUrl + "UserGroup/UpdateLicenseUserGroupUsers", JSON.stringify(jsonData), { headers: headers }) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } DeleteLicenseUserGroup(userGroupId: number) { return this.http.get(this.commonService.resourceBaseUrl + "UserGroup/DeleteLicenseUserGroup?UserGroupId=" + userGroupId) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } CheckDuplicateLicenseUserGroup(LicenseId: number, Title: string) { return this.http.get(this.commonService.resourceBaseUrl + "UserGroup/CheckDuplicateLicenseUserGroup?LicenseId=" + LicenseId + "&Title=" + Title). map(this.extractData) .catch((res: Response) => this.handleError(res)); } ///// End extractData(res: Response) { let body = res.json(); return body; } handleError(error: any) { // 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); } }