/// <summary> /// 授予角色 /// </summary> /// <param name="role"></param> public Role GiveRole(Role role) { //角色是否已存在 if (RoleUserInfoRepo.Read().Exists(ru => ru.RoleId == role.Id && ru.UserId == this.Id)) { return(role); } //检查互斥 List <Role> linkRoleList = this.DeepRoleList; foreach (Role linkRole in linkRoleList) { if (RoleMutex.CheckMutex(role, linkRole, RoleMutexType.Static)) { throw new Exception("授予的角色和当前用户或其所在的组织的角色存在静态互斥关系"); } } RoleUserInfo roleUserInfo = new RoleUserInfo(); roleUserInfo.RoleId = role.Id; roleUserInfo.UserId = this.Id; RoleUserInfoRepo.Add(roleUserInfo); return(role); }
public void Delete() { DataRepo<AppInfo> repo = new DataRepo<AppInfo>(); //添加 AppInfo appInfo = new AppInfo(); appInfo.Id = StringFactory.NewGuid(); appInfo.Key = "$deleteKey"; appInfo.Secret = "test"; appInfo.Name = "测试删除App"; repo.Add(appInfo); repo.Delete(appInfo); Assert.IsTrue(repo.Read().Where(a => a.Key == "$deleteKey").Count() < 1); }
public void Delete() { DataRepo <AppInfo> repo = new DataRepo <AppInfo>(); //添加 AppInfo appInfo = new AppInfo(); appInfo.Id = StringFactory.NewGuid(); appInfo.Key = "$deleteKey"; appInfo.Secret = "test"; appInfo.Name = "测试删除App"; repo.Add(appInfo); repo.Delete(appInfo); Assert.IsTrue(repo.Read().Where(a => a.Key == "$deleteKey").Count() < 1); }
public void SaveUser(string firstname, string lastname, int StravaID, int NumAct, int NumSeg) { var DataContext = new DataClasses1DataContext(); var userct = from u in DataContext.Users where u.StravaID == StravaID select u; if (userct.Count() > 0) { //update var sc = db.Users .Where(s => s.StravaID == StravaID) .First(); sc.Activities = NumAct; sc.Segments = NumSeg; sc.LastRefresh = Convert.ToDateTime(DateTime.Now).ToShortDateString(); db.SubmitChanges(); } else { //save new User unew = new Models.User(); unew.Firstname = firstname; unew.Lastname = lastname; unew.StravaID = StravaID; unew.Activities = NumAct; unew.Segments = NumSeg; unew.Credits = 15; unew.FirstLogin = DateTime.Now; datarepo.Add(unew); datarepo.Save(); } }
public void AddAndRead() { DataRepo<AppInfo> repo = new DataRepo<AppInfo>(); //添加 AppInfo info = new AppInfo(); info.Id = StringFactory.NewGuid(); info.Key = "test"; info.Secret = "test"; info.Name = "测试App"; repo.Add(info); //通过读取验证添加是否成功 List<AppInfo> infoList = repo.Read(); Assert.IsNotNull(infoList); Assert.IsTrue(infoList.Count > 0); repo.Delete(info); }
public void AddAndRead() { DataRepo <AppInfo> repo = new DataRepo <AppInfo>(); //添加 AppInfo info = new AppInfo(); info.Id = StringFactory.NewGuid(); info.Key = "test"; info.Secret = "test"; info.Name = "测试App"; repo.Add(info); //通过读取验证添加是否成功 List <AppInfo> infoList = repo.Read(); Assert.IsNotNull(infoList); Assert.IsTrue(infoList.Count > 0); repo.Delete(info); }
public Role GiveRole(Role role) { if (!PositionInfoRepo.Exists(this.MappingTo <PositionInfo>())) { throw new Exception("岗位不存在"); } if (!Role.RoleInfoRepo.Exists(role.MappingTo <RoleInfo>())) { throw new Exception("角色不存在"); } if (RolePositionInfoRepo.Read().Exists(ro => ro.RoleId == role.Id && ro.OrganizationId == this.OrganizationId && ro.PositionId == this.Id)) { return(role); } //检查互斥,除检查自身外,需检查所有上级组件层叠过来的角色(DeepRoleList 包括上级组件的角色) List <Role> linkRoleList = this.DeepRoleList; foreach (Role linkRole in linkRoleList) { if (RoleMutex.CheckMutex(role, linkRole, RoleMutexType.Static)) { throw new Exception("授予的角色和当前岗位或其所在组织的角色存在静态互斥关系"); } } RolePositionInfo rolePositionInfo = new RolePositionInfo(); rolePositionInfo.RoleId = role.Id; rolePositionInfo.OrganizationId = this.OrganizationId; rolePositionInfo.PositionId = this.Id; RolePositionInfoRepo.Add(rolePositionInfo); return(role); }