adduser.component.ts
4.31 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
import { Component, OnInit, AfterViewInit,ViewChild } from '@angular/core';
import { UserService } from '../UserEntity/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 { GlobalService } 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';
@Component({
templateUrl:'./adduser.component.html' // '../../../../../wwwroot/html/UpdateProfile/updateuserprofile.component.html'
})
export class AddUser implements OnInit {
user: User;
baseUrl: string = "User";
adduserFrm: FormGroup;
useFname: string;
error;
status: boolean;
alerts: string;
emailPattern = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
public UserTypeList: any;
public AccountNumberList: any;
public ProductEditionList: any;
modalTitle: string;
//@ViewChild("profileModal")
//profileModal: ModalComponent;
//errorMessage: any;
constructor(private userservice: UserService, private router: Router, private fb: FormBuilder, private http: Http,
private _confirmService: ConfirmService, private commonService: GlobalService
) { }
ngOnInit(): void {
this.user = new User();
this.alerts = '';
//this.userservice.GetUserById(this.UserId);
this.adduserFrm = this.fb.group({
id: [''],
UserName: ['', Validators.required],
Password: ['', Validators.required],
ConfirmPassword: ['', Validators.required],
FirstName: ['', Validators.required],
LastName: ['', Validators.required],
EmailId: ['', Validators.required],
AccountNumberId: ['', Validators.required],
UserTypeId: ['', Validators.required],
ProductEditionId: ['', Validators.required]
});
//this.GetAccountNumber();
this.GetUserTypeByLicenseId();
}
GetUserTypeByLicenseId() {
debugger;
var Accountnumber = this.adduserFrm.controls['AccountNumberId'].value;
if (Accountnumber == "") { Accountnumber=0}
this.userservice.GetUserTypeByLicenseType({
AccountNumberId: Accountnumber
}).subscribe(x => { this.UserTypeList = x; }, error => this.error = <any>error);
}
GetAccountNumber() {
this.userservice.GetAccountNumber()
.subscribe(x => { console.log(x); this.AccountNumberList=x }, error => this.error = <any>error);
}
GetProductEdition() {
this.userservice.GetProductEdition({
AccountNumberId: this.adduserFrm.controls['AccountNumberId'].value})
.subscribe(x => { console.log(x); this.ProductEditionList=x }, error => this.error = <any>error);
}
UpdateUserProfile(this) {
// debugger;
this.user = this.adduserFrm.value;
//if(this.user.)
//console.log(this.user);
var obj = this.user
if (this.adduserFrm.valid) {
return this.userservice.UpdateUserProfileById(obj)
.subscribe(
n => (this.AfterInsertData(n)),
error => this.error = <any>error);
}
}
AfterInsertData(data) {
//debugger;
if (data.Status == "False") {
return false;
} else {
this.status = true;
this._confirmService.activate("User Profile Updated Successfully.", "alertMsg");
}
}
bindUsers(data) {
//console.log(data);
//alert(JSON.stringify(data));
//this.user = data[0];
this.adduserFrm.controls['id'].setValue(this.user.Id)
this.adduserFrm.controls['FirstName'].setValue(this.user.FirstName)
this.adduserFrm.controls['LastName'].setValue(this.user.LastName)
this.adduserFrm.controls['EmailId'].setValue(this.user.EmailId)
this.adduserFrm.controls['UserName'].setValue(this.user.LoginId)
this.adduserFrm.controls['Password'].setValue(this.user.Password)
this.adduserFrm.controls['ConfirmPassword'].setValue(this.user.ConfirmPassword)
this.adduserFrm.controls['AccountNumberId'].setValue(this.user.AccountNumberId)
this.adduserFrm.controls['UserTypeId'].setValue(this.user.UserTypeId)
this.adduserFrm.controls['ProductEditionId'].setValue(this.user.ProductEditionId)
}
}