private void AddNewUser() { Users user = new Users(); UserForm form = new UserForm(user, awards); if (form.ShowDialog(this) == DialogResult.OK) { //Users user = new Users(); user.Name = form.Name; user.Surname = form.Surname; user.Birthday = form.BD; user.Awards = form.userAwards; user.Id = userId++; users.Add(user); UserWithAward userWithAward = new UserWithAward(); userWithAward = UserWithAward.ModelMaker(user); _users.Add(userWithAward); //RABOTAY(userWithAward); refreshUsersGrid(); } }
public static UserWithAward ModelMaker(Users user) { var model = new UserWithAward(); model.Id = user.Id; model.Name = user.Name; model.Surname = user.Surname; model.Birthday = user.Birthday; model.Awards = string.Join(", ", user.Awards.Select(r => r.Title)); return(model); }
private void RemoveSelectedUser() { if (ctlUsers.SelectedCells.Count > 0) { UserWithAward user = (UserWithAward)ctlUsers.SelectedCells[0].OwningRow.DataBoundItem; List <Users> temp = new List <Users>(users); for (int i = 0; i < temp.Count; i++) { if (user.Id == temp[i].Id) { users.Remove(temp[i]); } } _users.Remove(user); } }
private void EditSelectedUser() { if (ctlUsers.SelectedCells.Count > 0) { UserWithAward user = (UserWithAward)ctlUsers.SelectedCells[0].OwningRow.DataBoundItem; Users editUser = null; int id = 0; foreach (var item in users) { if (item.Id == user.Id) { editUser = item; } else { id++; } } UserForm form = new UserForm(editUser, awards); if (form.ShowDialog(this) == DialogResult.OK) { editUser.Name = form.Name; editUser.Surname = form.Surname; editUser.Birthday = form.BD; editUser.Awards = form.userAwards; users[id] = editUser; user = UserWithAward.ModelMaker(editUser); //id = 0; BindingList <UserWithAward> temp = new BindingList <UserWithAward>(_users); for (int i = 0; i < temp.Count; i++) { if (temp[i].Id == user.Id) { _users[i] = user; } } } } }
private void dropAwardFromUsers(Awards award) { List <Users> temp = new List <Users>(users); BindingList <UserWithAward> tempView = new BindingList <UserWithAward>(_users); for (int i = 0; i < temp.Count; i++) { users[i].Awards.Remove(award); for (int k = 0; k < tempView.Count; k++) { if (temp[i].Id == tempView[k].Id) { _users[k] = UserWithAward.ModelMaker(users[i]); } refreshUsersGrid(); } } }