private void bRoleEdit_Click(object sender, EventArgs e) { FormCreateRole crRole = new FormCreateRole(); RoleRepository roleRep = new RoleRepository(); Roles role = bindingSourceUserinRoles.Current as Roles; List <BusinessUserInRoles> busUsinRol = new List <BusinessUserInRoles>(); crRole.Rolename = role.RoleName; crRole.UEForm = this; this.Visible = false; if (crRole.ShowDialog() == DialogResult.OK) { busUsinRol = DeleteUserinRoles(role); // Удаляем связи роли с пользователями roleRep.Delete(role); role = new Roles(); role.RoleName = crRole.tbRoleName.Text; roleRep.Create(role); MessageBox.Show("Role Edit"); GetRoles(); if (busUsinRol.Count > 0) { BusinessUserInRoles obj = new BusinessUserInRoles(); BusinessUserInRolesRepository brep = new BusinessUserInRolesRepository(); obj.RoleId = role.RoleId; for (int i = 0; i < busUsinRol.Count; i++) { obj.UserId = busUsinRol[i].UserId; obj.HireDate = busUsinRol[i].HireDate; brep.Create(obj); } } } }
private void bRoleCreate_Click(object sender, EventArgs e) { FormCreateRole crRole = new FormCreateRole(); crRole.UEForm = this; this.Visible = false; if (crRole.ShowDialog() == DialogResult.OK) { BusStationEntities context = new BusStationEntities(); Roles role = new Roles(); role.RoleName = crRole.tbRoleName.Text; context.Roles.Add(role); context.SaveChanges(); MessageBox.Show("Role Add"); GetRoles(); } }