changeuserid.component.ts
4.05 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
import { Component, OnInit, AfterViewInit,ViewChild } from '@angular/core';
import { UserService } from './user.service';
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { User } from '../UserEntity/datamodel';
import { Http, Response } from '@angular/http';
//import { Global } from '../../Shared/global';
//import { DBOperation } from 'S';
import { Observable } from 'rxjs/Observable';
import { ConfirmService } from '../../Shared/Confirm/confirm.service';
import 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
import { LoadingService } from '../../shared/loading.service';
@Component({
templateUrl:'./changeuserid.component.html' // '../../../../../wwwroot/html/UpdateProfile/updateuserprofile.component.html'
})
export class ChangeUserID implements OnInit {
UserId: number=1;
user: User;
modalTitle: string;
modalBtnTitle: string;
baseUrl: string = "User";
ChangeUserIdFrm: FormGroup;
useFname: string;
error;
status: boolean;
alerts: string;
//@ViewChild("profileModal")
//profileModal: ModalComponent;
//errorMessage: any;
constructor(private _loadingService: LoadingService,private userservice: UserService, private router: Router, private fb: FormBuilder, private http: Http,
private _confirmService: ConfirmService
) { }
ngOnInit(): void {
this.user = new User();
this.alerts = '';
//this.userservice.GetUserById(this.UserId);
this.ChangeUserIdFrm = this.fb.group({
id: [''],
loginid: ['', Validators.required],
newloginid: ['', [Validators.required, Validators.minLength(8)]],
confirmloginid: ['', Validators.required]
// LastName: [''],
// Gender: ['', Validators.required],
// Email: ['']
});
this._loadingService.ShowLoading("global-loading");
this.GetUserById();
this._loadingService.HideLoading("global-loading");
}
redirect() {
this.router.navigate(['/']);
}
GetUserById() {
this.userservice.GetUserById()
.subscribe(x => { console.log(x); this.bindUsers(x) }, error => this.error = <any>error);
}
UpdateUserId(this) {
// debugger;
this.alerts = '';
if (this.user.LoginId == this.ChangeUserIdFrm.value.newloginid) {
this.alerts += '</br><span>New userid and old userid must be different</span>';
}
if (this.ChangeUserIdFrm.value.newloginid != this.ChangeUserIdFrm.value.confirmloginid) {
this.alerts += '</br><span>New userid and confirm userid must be same</span>';
}
if (this.alerts == '') {
this.user = this.ChangeUserIdFrm.value;
//if(this.user.)
console.log(this.user);
var obj = this.user
if (this.ChangeUserIdFrm.valid) {
return this.userservice.UpdateUserId(obj)
.subscribe(
n => (this.AfterInsertData(n)),
error => this.error = <any>error);
}
}
}
AfterInsertData(data) {
if (data == "success") {
this._confirmService.activate("Userid Updated Successfully.", "alertMsg");
} else {
this.alerts += '<span>' + data+'</span>';
return false;
}
//if (this.closeflag) {
// this.close.emit(null);
//}
//else {
//}
}
bindUsers(data) {
//console.log(data);
//alert(JSON.stringify(data));
this.user = data[0];
console.log(this.user);
this.ChangeUserIdFrm.controls['id'].setValue(this.user.Id)
this.ChangeUserIdFrm.controls['loginid'].setValue(this.user.LoginId)
this.ChangeUserIdFrm.controls['newloginid'].setValue(this.user.NewLoginId)
this.ChangeUserIdFrm.controls['confirmloginid'].setValue('')
}
ResetFormFields() {
this.ChangeUserIdFrm.reset()
this.ChangeUserIdFrm.controls['id'].setValue(this.user.Id)
this.ChangeUserIdFrm.controls['loginid'].setValue(this.user.LoginId)
this.ChangeUserIdFrm.controls['newloginid'].setValue('')
this.ChangeUserIdFrm.controls['confirmloginid'].setValue('')
this.alerts = '';
}
}