public Update(User user, Users.List sender) { InitializeComponent(); this.txtFirstName.Text = user.FirstName; this.txtLastName.Text = user.LastName; this.txtUserName.Text = user.UserName; this._user = user; this._sender = sender; cboRole.ItemsSource = Enum.GetValues(typeof(Role)).Cast <Role>().ToList(); cboRole.SelectedValue = user.Role; }
private void btnsave_Click(object sender, RoutedEventArgs e) { if (Validate() == false) { return; } if (UsersBLL.GetDuplicateUserName(txtUserName.Text, this._user.Id) != null) { MessageBox.Show("Username is already used"); } else { ShamirasRestaurant.Domain.Models.User user = new ShamirasRestaurant.Domain.Models.User(); user.Id = Guid.NewGuid(); user.UserName = txtUserName.Text; user.LastName = txtLastName.Text; user.FirstName = txtFirstName.Text; Role role = new Role(); if (cboRole.SelectedValue.ToString() == Role.Admin.ToString()) { role = Role.Admin; } else if (cboRole.SelectedValue.ToString() == Role.Cashier.ToString()) { role = Role.Cashier; } else if (cboRole.SelectedValue.ToString() == Role.Chef.ToString()) { role = Role.Chef; } else if (cboRole.SelectedValue.ToString() == Role.InventoryController.ToString()) { role = Role.InventoryController; } else if (cboRole.SelectedValue.ToString() == Role.Waiter.ToString()) { role = Role.Waiter; } user.Role = role; user.Id = this._user.Id; UsersBLL.Update(user); MessageBox.Show("User successfully created."); this._sender.showList(); this.Close(); } }