internal bool UpgradeArchitectureToRemote(out Exception ex) { ex = null; int errCount = 0; try { Architecture a = this.CurrentArchitecture; List <KellRole.Action> atcs = a.Acts; List <Department> deps = a.Deps; List <Module> mods = a.Mods; List <Permission> perms = a.Pers; List <Role> roles = a.Roles; List <UserGroup> ugrps = a.Ugroups; List <User> users = a.Users; ActionLogic.GetInstance().UpgradeList(atcs); DepartmentLogic.GetInstance().UpgradeList(deps); ModuleLogic.GetInstance().UpgradeList(mods); PermissionLogic.GetInstance().UpgradeList(perms); RoleLogic.GetInstance().UpgradeList(roles); UserGroupLogic.GetInstance().UpgradeList(ugrps); UserLogic.GetInstance().UpgradeList(users); } catch (Exception e) { errCount++; ex = e; } return(errCount == 0); }
private void btn_Perm_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { Permission per = new Permission(); per.ID = data[comboBox1.SelectedIndex].ID; per.Name = textBox1.Text.Trim(); per.IsExcept = checkBox1.Checked; Module mod = comboBox9.SelectedItem as Module; if (mod != null) { per.TheModule = mod; KellRole.Action act = comboBox10.SelectedItem as KellRole.Action; per.TheAction = act; per.Remark = textBox2.Text; PermissionLogic pl = PermissionLogic.GetInstance(); if (pl.ExistsNameOther(per.Name, per.ID)) { if (MessageBox.Show("系统中已经存在该名称,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { if (pl.UpdatePermission(per)) { data[comboBox1.SelectedIndex].Name = per.Name; data[comboBox1.SelectedIndex].TheModule = per.TheModule; data[comboBox1.SelectedIndex].TheAction = per.TheAction; data[comboBox1.SelectedIndex].Remark = per.Remark; RefreshInfo(); MessageBox.Show("修改成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { if (pl.UpdatePermission(per)) { data[comboBox1.SelectedIndex].Name = per.Name; data[comboBox1.SelectedIndex].TheModule = per.TheModule; data[comboBox1.SelectedIndex].TheAction = per.TheAction; data[comboBox1.SelectedIndex].Remark = per.Remark; RefreshInfo(); MessageBox.Show("修改成功!"); } } } else { MessageBox.Show("请选定模块!"); } } else { MessageBox.Show("先选定要修改的项目!"); } }
public void AddPermission() { RoleLogic RLogic = new RoleLogic(); PermissionLogic PLogic = new PermissionLogic(); string selectedPermission = lbxPermissions.SelectedItem.ToString(); string selectedRole = cmbRoles.SelectedItem.ToString(); PLogic.AddPermission(selectedRole, selectedPermission); }
public void LoadPermissions() { PermissionLogic Logic = new PermissionLogic(); List <Permission> permissionlist = Logic.RetrieveAllPermissions(); foreach (Permission p in permissionlist) { lbxpermissions.Items.Add(p.PermissionName); } }
private void btnRemove_Click(object sender, EventArgs e) { //Get the rolename and the permissionname string RoleName = cmbRoles.SelectedItem.ToString(); string PermissionName = listBox1.SelectedItem.ToString(); //New instance of permissionlogic and rolelogic PermissionLogic PLogic = new PermissionLogic(); RoleLogic RLogic = new RoleLogic(); //New role and new permisson Role r = new Role(RoleName, 1); Permission p = new Permission(1, PermissionName); //Empt roleid and permissionid int RoleID = 0; int PermissionID = 0; //Get permissionid from the database var AllPermissions = PLogic.RetrieveAllPermissions(); foreach (var SinglePermission in AllPermissions) { if (SinglePermission.PermissionName == p.PermissionName) { PermissionID = SinglePermission.RetrievePermissionID(); } } //Get roleid from the database var AllRoles = RLogic.RetrieveAllRoles(); foreach (var SingleRole in AllRoles) { if (SingleRole.RetrieveRoleName() == r.RetrieveRoleName()) { RoleID = SingleRole.RetrieveRoleID(); } } PLogic.DeleteRolePermission(RoleID, PermissionID); listBox1.Items.Clear(); string rol = cmbRoles.SelectedItem.ToString(); List <string> permissions = PLogic.GetAllRolePermissions(rol); foreach (string per in permissions) { listBox1.Items.Add(per); } }
private void cmbRoles_SelectedIndexChanged(object sender, EventArgs e) { listBox1.Items.Clear(); PermissionLogic PLogic = new PermissionLogic(); string rol = cmbRoles.SelectedItem.ToString(); List <string> permissions = PLogic.GetAllRolePermissions(rol); foreach (string per in permissions) { listBox1.Items.Add(per); } }
private static Architecture GetRemoteArchitecture() { Architecture a = Architecture.Empty; a.Deps = DepartmentLogic.GetInstance().GetAllDepartments(); a.Ugroups = UserGroupLogic.GetInstance().GetAllUserGroups(); a.Users = UserLogic.GetInstance().GetAllUsers(); a.Mods = ModuleLogic.GetInstance().GetAllModules(); a.Acts = ActionLogic.GetInstance().GetAllActions(); a.Pers = PermissionLogic.GetInstance().GetAllPermissions(); a.Roles = RoleLogic.GetInstance().GetAllRoles(); return(a); }
private void button9_Click(object sender, EventArgs e) { Module mod = comboBox9.SelectedItem as Module; KellRole.Action act = comboBox10.SelectedItem as KellRole.Action; if (mod != null) { Permission per = new Permission(); per.Name = textBox1.Text.Trim(); per.IsExcept = checkBox1.Checked; per.TheModule = mod; per.TheAction = act; per.Remark = textBox2.Text; PermissionLogic pl = PermissionLogic.GetInstance(); if (pl.ExistsName(per.Name)) { if (MessageBox.Show("系统中已经存在该名称,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { int id = pl.AddPermission(per); if (id > 0) { per.ID = id; data.Add(per); RefreshInfo(); MessageBox.Show("添加成功!"); } } else { textBox1.Focus(); textBox1.SelectAll(); } } else { int id = pl.AddPermission(per); if (id > 0) { per.ID = id; data.Add(per); RefreshInfo(); MessageBox.Show("添加成功!"); } } } else { MessageBox.Show("请选定模块!"); } }
private void btnAddPermission_Click(object sender, EventArgs e) { AddPermission(); listBox1.Items.Clear(); PermissionLogic Logic = new PermissionLogic(); string rol = cmbRoles.SelectedItem.ToString(); List <string> permissions = Logic.GetAllRolePermissions(rol); foreach (string per in permissions) { listBox1.Items.Add(per); } }
public void DeletePermission() { PermissionLogic Logic = new PermissionLogic(); string permission = (string)lbxpermissions.SelectedItem; if (Logic.DeletePermission(permission) == true) { MessageBox.Show("Perimssion " + permission + " is succesvol verwijderd"); lbxpermissions.Items.Remove(permission); } else { MessageBox.Show("Er ging iets mis tijdens het verwijderen"); } }
/// <summary> /// Checks if the provided user id has the requested permission /// </summary> /// <param name="userId">The user id</param> /// <param name="permissionId">The requested permission id</param> /// <returns>True if the user has the requested permission.</returns> public virtual bool HasPermissions(int userId, int permissionId) { var cached = UserPermissionCache.Get(userId); if (cached != null && cached.Contains(permissionId)) { return(true); } var permissionList = PermissionLogic.SelectBy_UserIdNow(userId); var permIdList = (from p in permissionList select p.PermissionId ?? 0).ToList(); //Cache results for 10 minutes 10*60*1000 UserPermissionCache.Cache(userId, permIdList, 600000); return(permIdList.Contains(permissionId)); }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { if (MessageBox.Show("确定要删除该项目?", "删除提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { Permission per = data[comboBox1.SelectedIndex]; if (PermissionLogic.GetInstance().DeletePermission(per)) { data.RemoveAt(comboBox1.SelectedIndex); RefreshInfo(); } } } else { MessageBox.Show("先选定要删除的项目!"); } }
public IEnumerable <ProjectView> GetProjects(UserView user, ActiveState activeState) { //TODO CLLP, Handle if Active is null, return all projects int active = EnumHelper.EnumToInt(activeState); if (user != null) { using (SqlConnection conn = SqlHelper.GetOpenConnection()) { IEnumerable <ProjectView> projects = conn.Query <ProjectView, ProjectArea, Program, Organization, ProjectView>("GetProjects", (p, pa, prog, o) => { p.ProjectArea = pa; p.Program = prog; p.Organization = o; return(p); }, new { UserId = user.Id, ActiveState = active }, commandType: CommandType.StoredProcedure); var query = @"SELECT prv.* FROM [ProjectRoleView] prv WHERE prv.UserId = @UserId"; var projectRoles = conn.Query <ProjectRoleView>(query, new { UserId = user.Id }); //add the project permissions foreach (var project in projects) { var rolesForProject = projectRoles.Where(p => p.ProjectId.Equals(project.Id)); project.Permissions = PermissionLogic.GetPermissions(rolesForProject, project, user, false); //var permission = project.Permissions.Where(p => p.Section.Equals(PermissionSection.Project)).FirstOrDefault(); } return(projects.FilterProjectList()); //return projects.Where(p => p.ShowInListDueToWritePermissionAndVersion.Equals(true)); } } else { //throw new Exception("User is null, can not get projects"); log.Error("User is null, can not get projects"); return(null); } }
public void LoadAllPermission() { lbxPermissions.Items.Clear(); cmbRoles.Items.Clear(); PermissionLogic PLogic = new PermissionLogic(); RoleLogic RLogic = new RoleLogic(); List <Permission> permissions = PLogic.RetrieveAllPermissions(); foreach (var permission in permissions) { lbxPermissions.Items.Add(permission.PermissionName); } List <Role> Roles = RLogic.RetrieveAllRoles(); foreach (Role role in Roles) { cmbRoles.Items.Add(role.RetrieveRoleName()); } }
public Project GetProject(int id) { using (SqlConnection conn = SqlHelper.GetOpenConnection()) { using (var multi = conn.QueryMultiple("GetProject", new { ProjectId = id }, commandType: CommandType.StoredProcedure)) { //var project = multi.Read<Project>().FirstOrDefault(); var project = multi.Read <Project, Organization, UserView, Program, Project>((p, o, uv, program) => { p.Organization = o; p.User = uv; p.Program = program; return(p); }).FirstOrDefault(); var projectActivities = multi.Read <ProjectActivity>(); var projectFollowUps = multi.Read <ProjectFollowUp>(); var projectGoals = multi.Read <ProjectGoal>(); var projectMembers = multi.Read <ProjectMemberView>(); var projectRoles = multi.Read <ProjectRoleView>(); var projectRisks = multi.Read <ProjectRisk>(); if (project == null) { return(null); } if (projectActivities.Any()) { project.ProjectActivities = projectActivities.ToList(); } if (projectFollowUps.Any()) { project.ProjectFollowUps = projectFollowUps.ToList(); } if (projectGoals.Any()) { project.ProjectGoals = projectGoals.ToList(); } var projectMemberViews = projectMembers as List <ProjectMemberView> ?? projectMembers.ToList(); if (projectMemberViews.Any()) { project.ProjectMembers = projectMemberViews; } // add member roles var projectRoleView = projectRoles as List <ProjectRoleView> ?? projectRoles.ToList(); foreach (var member in project.ProjectMembers) { ProjectMemberView memberCopy = member; foreach (var roleView in projectRoleView.Where(roleView => memberCopy.UserId == roleView.UserId)) { member.ProjectRoles.Add(roleView); } } if (projectRisks.Any()) { project.ProjectRisks = projectRisks.ToList(); } var query = @"SELECT prv.* FROM [ProjectRoleView] prv WHERE prv.ProjectId = @ProjectId AND prv.UserId = @UserId"; var user = IdentityContext.Current.User; IEnumerable <ProjectRoleView> currentUserRoles = conn.Query <ProjectRoleView>(query, new { ProjectId = id, UserId = user.Id }); //add the project permissions if (project != null) { IProjectRepository projectRepository = CoreFactory.ProjectRepository; IEnumerable <ProjectRole> avaliableRoles = projectRepository.GetAvaliableRoles(user.Id, project.Id); project.Permissions = PermissionLogic.GetPermissions(currentUserRoles, project, user, avaliableRoles.Any()); } //set the current project to identity context IdentityContext.CurrentProjectId = project.Id; return(project); } } }