/// <summary> /// Заповнюємо список ролей /// </summary> private void FillRoles() { SecurityUserRolesLogic userRoles = new SecurityUserRolesLogic(manager); SecurityRolesLogic roles = new SecurityRolesLogic(manager); List<SecurityRole> allRoles = roles.GetAll(); if (userId != null) { List<SecurityUserRole> userHasRoles = userRoles.GetAll(Convert.ToInt32(userId)); foreach (var role in allRoles) { Helpers.Item item = new Item(); item.ID = role.ID.ToString(); item.Name = role.Name; ((ListBox)RolesLB).DisplayMember = "Name"; ((ListBox)RolesLB).ValueMember = "ID"; SecurityUserRole userRole = userHasRoles.Where(a => a.RoleID == role.ID).Select(a => a).FirstOrDefault(); bool selected = false; if (userRole != null) { selected = true; } RolesLB.Items.Add(item, selected); } } }
private void SaveBt_Click(object sender, EventArgs e) { SecurityUserRolesLogic userRoles = new SecurityUserRolesLogic(manager); List <int> checkedRoles = new List <int>(); List <int> availableRoles = new List <int>(); foreach (Object item in RolesLB.CheckedItems) { checkedRoles.Add(Convert.ToInt32(((Helpers.Item)item).ID)); } foreach (Object item in RolesLB.Items) { availableRoles.Add(Convert.ToInt32(((Helpers.Item)item).ID)); } foreach (int roleId in availableRoles) { if (checkedRoles.Contains(roleId)) { userRoles.Create(Convert.ToInt32(userId), roleId); } else { userRoles.Delete(Convert.ToInt32(userId), roleId); } } manager.Save(); this.Close(); }
/// <summary> /// Заповнюємо список ролей /// </summary> private void FillRoles() { SecurityUserRolesLogic userRoles = new SecurityUserRolesLogic(manager); SecurityRolesLogic roles = new SecurityRolesLogic(manager); List <SecurityRole> allRoles = roles.GetAll(); if (userId != null) { List <SecurityUserRole> userHasRoles = userRoles.GetAll(Convert.ToInt32(userId)); foreach (var role in allRoles) { Helpers.Item item = new Item(); item.ID = role.ID.ToString(); item.Name = role.Name; ((ListBox)RolesLB).DisplayMember = "Name"; ((ListBox)RolesLB).ValueMember = "ID"; SecurityUserRole userRole = userHasRoles.Where(a => a.RoleID == role.ID).Select(a => a).FirstOrDefault(); bool selected = false; if (userRole != null) { selected = true; } RolesLB.Items.Add(item, selected); } } }
private void FillInfo() { if (DataGV.SelectedRows.Count > 0) { StaffEmployeePositionsLogic employeePositionsLogic = new StaffEmployeePositionsLogic(manager); StaffEmployeeLogic employeeLogic = new StaffEmployeeLogic(manager); SecurityUserRolesLogic userRoles = new SecurityUserRolesLogic(manager); int employeeId = Convert.ToInt32(DataGV.SelectedRows[0].Cells["ID"].Value); PositionsLB.DataSource = employeePositionsLogic.GetPositionsByEmployeeID(employeeId).ToList(); PositionsLB.DisplayMember = "Name"; PositionsLB.ValueMember = "ID"; PositionsLB.Update(); StaffEmployee employee = employeeLogic.Get(employeeId); if (employee.UserID != null) { int userId = Convert.ToInt32(employee.UserID); RolesLB.DataSource = userRoles.GetAll(userId).Select(a => a.SecurityRole).ToList(); RolesLB.DisplayMember = "Name"; RolesLB.ValueMember = "ID"; RolesLB.Update(); } } }
private void SaveBt_Click(object sender, EventArgs e) { SecurityUserRolesLogic userRoles = new SecurityUserRolesLogic(manager); List<int> checkedRoles = new List<int>(); List<int> availableRoles = new List<int>(); foreach (Object item in RolesLB.CheckedItems) { checkedRoles.Add(Convert.ToInt32(((Helpers.Item)item).ID)); } foreach (Object item in RolesLB.Items) { availableRoles.Add(Convert.ToInt32(((Helpers.Item)item).ID)); } foreach (int roleId in availableRoles) { if (checkedRoles.Contains(roleId)) { userRoles.Create(Convert.ToInt32(userId), roleId); } else { userRoles.Delete(Convert.ToInt32(userId), roleId); } } manager.Save(); this.Close(); }