public IEnumerable<DT.Client> GetAllClients() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>() select Convert.ToDto(c); return query.ToList(); } }
public IEnumerable<DT.Client> GetClients(IEnumerable<Guid> ids) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>() where ids.Contains(c.Id) select Convert.ToDto(c); return query.ToList(); } }
public bool ClientExists(Guid id) { if (id != Guid.Empty) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { return (context.Resources.Where(x => x.Id == id).Count() != 0); } } return false; }
public IEnumerable <Guid> GetUserGroupIdsOfGroup(Guid groupId) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupUserGroups where u.UserGroupUserGroupId == groupId select u.UserGroupId; return(query.ToList()); } }
public IEnumerable <DT.UserGroupMapping> GetUserGroupMapping() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupUserGroups select Convert.ToDto(u); return(query.ToList()); } }
public IEnumerable <DT.UserGroup> GetAllUserGroups() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType <DA.UserGroup>() select Convert.ToDto(u); return(query.ToList()); } }
public void DeleteClientLog(DT.ClientLog log) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { context.ClientLogs.DeleteOnSubmit(Convert.ToEntity(log)); context.SubmitChanges(); } }
public DT.ClientLog GetLastClientLog(Guid clientId) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from r in context.ClientLogs where r.ResourceId == clientId select r; return(Convert.ToDto(query.OrderBy(x => x.Timestamp).LastOrDefault())); } }
public IEnumerable <DT.Resource> GetResources() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from r in context.Resources select Convert.ToDto(r); return(query.ToList()); } }
public IEnumerable <DT.Client> GetAllClients() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.GetTable <DA.Resource>().OfType <DA.Client>() select Convert.ToDto(c); return(query.ToList()); } }
public IEnumerable <DT.ClientGroupMapping> GetClientGroupMapping() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.GetTable <DA.ResourceResourceGroup>() select Convert.ToDto(c); return(query.ToList()); } }
public void AddClient(DT.Client client) { string country = string.Empty; OperationContext opContext = OperationContext.Current; if (opContext != null) { MessageProperties properties = opContext.IncomingMessageProperties; RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; string ipAdr = endpoint.Address; country = GeoIPLookupService.Instance.GetCountryName(ipAdr); } using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { DA.Client entity = Convert.ToEntity(client); if (country != string.Empty) { var query = from c in context.GetTable <DA.Country>() where c.Name == country select c; if (query.Count() > 0) { entity.CountryId = query.First().Id; } } if (entity.OperatingSystem != null) { string osversion = entity.OperatingSystem.Name; var query = from os in context.GetTable <DA.OperatingSystem>() where os.Name == osversion select os; if (query.Count() > 0) { entity.OperatingSystem = query.First(); } } if (entity.ClientType != null) { string cType = entity.ClientType.Name; var query = from t in context.GetTable <DA.ClientType>() where t.Name == cType select t; if (query.Count() > 0) { entity.ClientType = query.First(); } } context.Resources.InsertOnSubmit(entity); context.SubmitChanges(); } }
private DT.User BuildUserDto(Guid userId) { DA.aspnet_User aspUser = null; DA.aspnet_Membership aspMembership = null; DA.User accessUser = null; using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { var userQuery = from u in context.aspnet_Users where u.UserId == userId select u; if (userQuery.Count() == 1) { aspUser = userQuery.First(); } var memQuery = from u in context.aspnet_Memberships where u.UserId == userId select u; if (memQuery.Count() == 1) { aspMembership = memQuery.First(); } } if (aspUser != null || aspMembership != null) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType <DA.User>() where u.Id == userId select u; if (query.Count() == 1) { accessUser = query.First(); } else { //if the user is not in the access db add it (this makes it easy to upgrade with an existing asp.net authentication db) DA.User user = new DA.User(); user.Id = userId; user.FullName = "Not set"; context.UserGroupBases.InsertOnSubmit(user); context.SubmitChanges(); accessUser = user; } } } if (aspUser == null || aspMembership == null || accessUser == null) { throw new Exception("User with id " + userId + " not found."); } else { return(Convert.ToDto(accessUser, aspUser, aspMembership)); } }
public IEnumerable <DT.UserGroup> GetUserGroups(IEnumerable <Guid> ids) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType <DA.UserGroup>() where ids.Contains(u.Id) select Convert.ToDto(u); return(query.ToList()); } }
public void AddUserGroupBaseToGroup(DT.UserGroupBase resource, DT.UserGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { DA.UserGroupUserGroup ugug = new DA.UserGroupUserGroup(); ugug.UserGroupId = resource.Id; ugug.UserGroupUserGroupId = group.Id; context.UserGroupUserGroups.InsertOnSubmit(ugug); context.SubmitChanges(); } }
public IEnumerable <DT.Client> GetClients(IEnumerable <Guid> ids) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.GetTable <DA.Resource>().OfType <DA.Client>() where ids.Contains(c.Id) select Convert.ToDto(c); return(query.ToList()); } }
public IEnumerable <DT.ClientLog> GetClientLogs(Guid clientId) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from r in context.ClientLogs where r.ResourceId == clientId select Convert.ToDto(r); return(query.ToList()); } }
public IEnumerable <DT.ClientLog> GetClientLogsSince(DateTime startDate) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from r in context.ClientLogs where r.Timestamp >= startDate select Convert.ToDto(r); return(query.ToList()); } }
public bool ClientExists(Guid id) { if (id != Guid.Empty) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { return(context.Resources.Where(x => x.Id == id).Count() != 0); } } return(false); }
public Guid AddUserGroup(DT.UserGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { //because id is not automatically set because of user, we have to do it here manually for group group.Id = Guid.NewGuid(); context.UserGroupBases.InsertOnSubmit(Convert.ToEntity(group)); context.SubmitChanges(); return(group.Id); } }
public IEnumerable <DT.ClientError> GetClientErrors() { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.ClientErrors select Convert.ToDto(c); return(query.ToList()); } }
public void RemoveResourceFromGroup(DT.Resource resource, DT.ClientGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = context.ResourceResourceGroups.Where(x => x.ResourceId == resource.Id && x.ResourceGroupId == group.Id); if (query.Count() > 0) { context.ResourceResourceGroups.DeleteOnSubmit(query.First()); context.SubmitChanges(); } } }
public DT.Client GetClient(Guid id) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>() where c.Id == id select c; if (query.Count() > 0) { return Convert.ToDto(query.FirstOrDefault()); } else { return null; } } }
public DT.User AddUser(DT.User user) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); DA.User accessUser; DA.aspnet_User aspUser; DA.aspnet_Membership aspMembership; bool userExistsInASP; Convert.ToEntity(user, out accessUser, out aspUser, out aspMembership, out userExistsInASP); if (userExistsInASP) { if (accessUser.Id == null || accessUser.Id == Guid.Empty) { accessUser.Id = aspMembership.UserId; } using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { context.UserGroupBases.InsertOnSubmit(accessUser); context.SubmitChanges(); } MembershipUser membershipUser = Membership.GetUser((object)accessUser.Id); if (membershipUser != null) { membershipUser.Email = aspMembership.Email; membershipUser.IsApproved = aspMembership.IsApproved; membershipUser.Comment = aspMembership.Comment; Membership.UpdateUser(membershipUser); } } else { MembershipUser membershipUser = Membership.CreateUser(aspUser.UserName, aspUser.UserName, aspMembership.Email); membershipUser.IsApproved = aspMembership.IsApproved; membershipUser.Comment = aspMembership.Comment; Membership.UpdateUser(membershipUser); Guid userId = (Guid)membershipUser.ProviderUserKey; accessUser.Id = userId; using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { context.UserGroupBases.InsertOnSubmit(accessUser); context.SubmitChanges(); } } using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { var newAspUser = context.aspnet_Users.Where(x => x.UserId == accessUser.Id).FirstOrDefault(); var newAspMembership = context.aspnet_Memberships.Where(x => x.UserId == accessUser.Id).FirstOrDefault(); return(Convert.ToDto(accessUser, newAspUser, newAspMembership)); } }
public void DeleteError(DT.ClientError error) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = context.ClientErrors.Where(x => x.Id == error.Id); if (query.Count() > 0) { context.ClientErrors.DeleteOnSubmit(query.First()); context.SubmitChanges(); } } }
public void AddResourceToGroup(DT.Resource resource, DT.ClientGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { DA.ResourceResourceGroup rrg = new DA.ResourceResourceGroup() { ResourceId = resource.Id, ResourceGroupId = group.Id }; context.ResourceResourceGroups.InsertOnSubmit(rrg); context.SubmitChanges(); } }
public IEnumerable <DT.UserGroup> GetGroupsOfCurrentUser() { Guid userId = UserManager.CurrentUserId; using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from g in context.UserGroupUserGroups from ug in context.UserGroupBases.OfType <DA.UserGroup>() where g.UserGroupId == userId && g.UserGroupUserGroupId == ug.Id select Convert.ToDto(ug); return(query.ToList()); } }
public void RemoveUserGroupBaseFromGroup(DT.UserGroupBase resource, DT.UserGroup userGroup) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupUserGroups where u.UserGroupId == resource.Id && u.UserGroupUserGroupId == userGroup.Id select u; if (query.Count() == 1) { context.UserGroupUserGroups.DeleteOnSubmit(query.First()); context.SubmitChanges(); } } }
public Guid AddClientGroup(DT.ClientGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { if (group.Id == Guid.Empty) { group.Id = Guid.NewGuid(); } var entity = Convert.ToEntity(group); context.Resources.InsertOnSubmit(entity); context.SubmitChanges(); return(entity.Id); } }
public IEnumerable <DT.UserGroup> GetUserGroupsOfUser(Guid userId) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var groupIds = from g in context.UserGroupUserGroups where g.UserGroupId == userId select g.UserGroupUserGroupId; var query = from g in context.UserGroupBases.OfType <DA.UserGroup>() where groupIds.Contains(g.Id) select Convert.ToDto(g); return(query.ToList()); } }
public void UpdateClientGroup(DT.ClientGroup clientGroup) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from g in context.Resources.OfType <DA.ClientGroup>() where g.Id == clientGroup.Id select g; if (query.Count() > 0) { var entity = query.First(); entity.Name = clientGroup.Name; entity.Description = clientGroup.Description; context.SubmitChanges(); } } }
public void DeleteClientGroup(DT.ClientGroup clientGroup) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { //load clientGroup because we could get a detached object var query = from c in context.GetTable <DA.Resource>().OfType <DA.ClientGroup>() where c.Id == clientGroup.Id select c; if (query.Count() > 0) { context.Resources.DeleteOnSubmit(query.First()); context.SubmitChanges(); } } }
public DT.Client GetClient(Guid id) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.GetTable <DA.Resource>().OfType <DA.Client>() where c.Id == id select c; if (query.Count() > 0) { return(Convert.ToDto(query.FirstOrDefault())); } else { return(null); } } }
public IEnumerable <DT.LightweightUser> GetLightweightUsers(IEnumerable <Guid> ids) { List <Guid> accessUserGuids = null; using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType <DA.User>() where ids.Contains(u.Id) select u.Id; accessUserGuids = query.ToList(); } if (accessUserGuids.Count() != ids.Count()) { throw new Exception("Couldn't find one or more users for the given user ids."); } return(accessUserGuids.Select(x => BuildLightweightUserDto(x))); }
public void UpdateUser(DT.User user) { if (user.Id != UserManager.CurrentUserId) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); } MembershipUser membershipUser = Membership.GetUser((object)user.Id); if (membershipUser != null) { membershipUser.Email = user.Email; membershipUser.IsApproved = user.IsApproved; membershipUser.Comment = user.Comment; Membership.UpdateUser(membershipUser); } using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.User>() where u.Id == user.Id select u; if (query.Count() > 0) { DA.User u = query.First(); u.FullName = user.FullName; context.SubmitChanges(); } } }
public IEnumerable<DT.UserGroup> GetUserGroupsOfUser(Guid userId) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var groupIds = from g in context.UserGroupUserGroups where g.UserGroupId == userId select g.UserGroupUserGroupId; var query = from g in context.UserGroupBases.OfType<DA.UserGroup>() where groupIds.Contains(g.Id) select Convert.ToDto(g); return query.ToList(); } }
public IEnumerable<DT.UserGroup> GetAllUserGroups() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.UserGroup>() select Convert.ToDto(u); return query.ToList(); } }
public Guid AddUserGroup(DT.UserGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { //because id is not automatically set because of user, we have to do it here manually for group group.Id = Guid.NewGuid(); context.UserGroupBases.InsertOnSubmit(Convert.ToEntity(group)); context.SubmitChanges(); return group.Id; } }
public IEnumerable<DT.UserGroup> GetUserGroups(IEnumerable<Guid> ids) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.UserGroup>() where ids.Contains(u.Id) select Convert.ToDto(u); return query.ToList(); } }
private DT.LightweightUser BuildLightweightUserDto(Guid userId) { DA.aspnet_User aspUser = null; DA.aspnet_Membership aspMembership = null; DA.User accessUser = null; List<DA.aspnet_Role> roles = new List<DA.aspnet_Role>(); List<DA.UserGroup> groups = new List<DA.UserGroup>(); using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { var userQuery = from u in context.aspnet_Users where u.UserId == userId select u; var memQuery = from u in context.aspnet_Memberships where u.UserId == userId select u; if (memQuery.Count() == 1) { aspMembership = memQuery.First(); } if (userQuery.Count() == 1) { aspUser = userQuery.First(); roles = (from ur in context.aspnet_UsersInRoles where ur.UserId == aspUser.UserId join r in context.aspnet_Roles on ur.RoleId equals r.RoleId select r).ToList(); } } if (aspUser != null || aspMembership != null) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.User>() where u.Id == userId select u; if (query.Count() == 1) { accessUser = query.First(); groups = (from ug in context.UserGroupUserGroups where ug.UserGroupId == accessUser.Id join g in context.UserGroupBases.OfType<DA.UserGroup>() on ug.UserGroupUserGroupId equals g.Id select g).ToList(); } else { //if the user is not in the access db add it (this makes it easy to upgrade with an existing asp.net authentication db) DA.User user = new DA.User(); user.Id = userId; user.FullName = "Not set"; context.UserGroupBases.InsertOnSubmit(user); context.SubmitChanges(); accessUser = user; } } } if (aspUser == null || accessUser == null || aspMembership == null) { throw new Exception("User with id " + userId + " not found."); } else { return Convert.ToDto(accessUser, aspUser, aspMembership, roles, groups); } }
public void AddClient(DT.Client client) { string country = string.Empty; OperationContext opContext = OperationContext.Current; if (opContext != null) { MessageProperties properties = opContext.IncomingMessageProperties; RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; string ipAdr = endpoint.Address; country = GeoIPLookupService.Instance.GetCountryName(ipAdr); } using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { DA.Client entity = Convert.ToEntity(client); if (country != string.Empty) { var query = from c in context.GetTable<DA.Country>() where c.Name == country select c; if (query.Count() > 0) { entity.CountryId = query.First().Id; } } if (entity.OperatingSystem != null) { string osversion = entity.OperatingSystem.Name; var query = from os in context.GetTable<DA.OperatingSystem>() where os.Name == osversion select os; if (query.Count() > 0) { entity.OperatingSystem = query.First(); } } if (entity.ClientType != null) { string cType = entity.ClientType.Name; var query = from t in context.GetTable<DA.ClientType>() where t.Name == cType select t; if (query.Count() > 0) { entity.ClientType = query.First(); } } context.Resources.InsertOnSubmit(entity); context.SubmitChanges(); } }
public IEnumerable<DT.UserGroupBase> GetLeightweightUsersAndGroups(IEnumerable<Guid> ids) { List<DA.UserGroupBase> dbUserGroupsBases = new List<DA.UserGroupBase>(); List<DT.UserGroupBase> result = new List<DT.UserGroupBase>(); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases where ids.Contains(u.Id) select u; dbUserGroupsBases = query.ToList(); } foreach (var ugb in dbUserGroupsBases) { if (ugb.GetType() == typeof(DA.User)) { var user = BuildLightweightUserDto(ugb.Id); result.Add(user); } else if (ugb.GetType() == typeof(DA.UserGroup)) { var group = Convert.ToDto(ugb as DA.UserGroup); result.Add(group); } } return result; }
public DT.User AddUser(DT.User user) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); DA.User accessUser; DA.aspnet_User aspUser; DA.aspnet_Membership aspMembership; bool userExistsInASP; Convert.ToEntity(user, out accessUser, out aspUser, out aspMembership, out userExistsInASP); if (userExistsInASP) { if (accessUser.Id == null || accessUser.Id == Guid.Empty) { accessUser.Id = aspMembership.UserId; } using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { context.UserGroupBases.InsertOnSubmit(accessUser); context.SubmitChanges(); } MembershipUser membershipUser = Membership.GetUser((object)accessUser.Id); if (membershipUser != null) { membershipUser.Email = aspMembership.Email; membershipUser.IsApproved = aspMembership.IsApproved; membershipUser.Comment = aspMembership.Comment; Membership.UpdateUser(membershipUser); } } else { MembershipUser membershipUser = Membership.CreateUser(aspUser.UserName, aspUser.UserName, aspMembership.Email); membershipUser.IsApproved = aspMembership.IsApproved; membershipUser.Comment = aspMembership.Comment; Membership.UpdateUser(membershipUser); Guid userId = (Guid)membershipUser.ProviderUserKey; accessUser.Id = userId; using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { context.UserGroupBases.InsertOnSubmit(accessUser); context.SubmitChanges(); } } using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { var newAspUser = context.aspnet_Users.Where(x => x.UserId == accessUser.Id).FirstOrDefault(); var newAspMembership = context.aspnet_Memberships.Where(x => x.UserId == accessUser.Id).FirstOrDefault(); return Convert.ToDto(accessUser, newAspUser, newAspMembership); } }
public void DeleteUserGroup(DT.UserGroup group) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); var g = group; //linq does not like vars called group if (g.Id != null && g.Id != Guid.Empty) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from ug in context.UserGroupBases.OfType<DA.UserGroup>() where ug.Id == g.Id select ug; if (query.Count() > 0) { context.UserGroupBases.DeleteOnSubmit(query.First()); context.SubmitChanges(); } else { throw new Exception("UserGroup with id " + g.Id + " does not exist."); } } } }
public void UpdateUserGroup(DT.UserGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { DA.UserGroup entity = context.UserGroupBases.OfType<DA.UserGroup>().FirstOrDefault(x => x.Id == group.Id); Convert.ToEntity(group, entity); context.SubmitChanges(); } }
public void AddUserGroupBaseToGroup(DT.UserGroupBase resource, DT.UserGroup group) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { DA.UserGroupUserGroup ugug = new DA.UserGroupUserGroup(); ugug.UserGroupId = resource.Id; ugug.UserGroupUserGroupId = group.Id; context.UserGroupUserGroups.InsertOnSubmit(ugug); context.SubmitChanges(); } }
public void DeleteError(DT.ClientError error) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = context.ClientErrors.Where(x => x.Id == error.Id); if (query.Count() > 0) { context.ClientErrors.DeleteOnSubmit(query.First()); context.SubmitChanges(); } } }
public IEnumerable<DT.ClientError> GetLastClientErrors(DateTime startDate) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from c in context.ClientErrors where c.Timestamp >= startDate select Convert.ToDto(c); return query.ToList(); } }
public void DeleteUser(DT.User user) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); if (user.Id != null && user.Id != Guid.Empty) { //delete asp.net user Membership.DeleteUser(user.UserName); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = context.UserGroupBases.OfType<DA.User>().Where(x => x.Id == user.Id); if (query.Count() > 0) { //delete affiliation first var queryMapping = context.UserGroupUserGroups.Where(x => x.UserGroupId == user.Id); if (queryMapping.Count() > 0) { context.UserGroupUserGroups.DeleteAllOnSubmit(queryMapping); } //delete user from access db context.UserGroupBases.DeleteOnSubmit(query.First()); context.SubmitChanges(); } } } }
public IEnumerable<DT.UserGroupMapping> GetUserGroupMapping() { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupUserGroups select Convert.ToDto(u); return query.ToList(); } }
public IEnumerable<DT.User> GetUsers(IEnumerable<Guid> ids) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); List<Guid> accessUserGuids = null; using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.User>() where ids.Contains(u.Id) select u.Id; accessUserGuids = query.ToList(); } if (accessUserGuids.Count() != ids.Count()) { throw new Exception("Couldn't find one or more users for the given user ids."); } return accessUserGuids.Select(x => BuildUserDto(x)); }
public void RemoveUserGroupBaseFromGroup(DT.UserGroupBase resource, DT.UserGroup userGroup) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupUserGroups where u.UserGroupId == resource.Id && u.UserGroupUserGroupId == userGroup.Id select u; if (query.Count() == 1) { context.UserGroupUserGroups.DeleteOnSubmit(query.First()); context.SubmitChanges(); } } }
public IEnumerable<DT.UserGroupBase> GetAllLeightweightUsersAndGroups() { List<DT.UserGroup> userGroups = new List<DT.UserGroup>(); List<DT.UserGroupBase> result = new List<DT.UserGroupBase>(); List<Guid> accessUserGuids = null; using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { var query = from u in context.aspnet_Users select u.UserId; accessUserGuids = query.ToList(); } var lightweightUsers = accessUserGuids.Select(x => BuildLightweightUserDto(x)); using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.UserGroup>() select Convert.ToDto(u); userGroups = query.ToList(); } result.AddRange(lightweightUsers); result.AddRange(userGroups); return result; }
private DT.User BuildUserDto(Guid userId) { DA.aspnet_User aspUser = null; DA.aspnet_Membership aspMembership = null; DA.User accessUser = null; using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { var userQuery = from u in context.aspnet_Users where u.UserId == userId select u; if (userQuery.Count() == 1) { aspUser = userQuery.First(); } var memQuery = from u in context.aspnet_Memberships where u.UserId == userId select u; if (memQuery.Count() == 1) { aspMembership = memQuery.First(); } } if (aspUser != null || aspMembership != null) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.User>() where u.Id == userId select u; if (query.Count() == 1) { accessUser = query.First(); } else { //if the user is not in the access db add it (this makes it easy to upgrade with an existing asp.net authentication db) DA.User user = new DA.User(); user.Id = userId; user.FullName = "Not set"; context.UserGroupBases.InsertOnSubmit(user); context.SubmitChanges(); accessUser = user; } } } if (aspUser == null || aspMembership == null || accessUser == null) { throw new Exception("User with id " + userId + " not found."); } else { return Convert.ToDto(accessUser, aspUser, aspMembership); } }
public IEnumerable<DT.LightweightUser> GetLightweightUsers(IEnumerable<Guid> ids) { List<Guid> accessUserGuids = null; using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupBases.OfType<DA.User>() where ids.Contains(u.Id) select u.Id; accessUserGuids = query.ToList(); } if (accessUserGuids.Count() != ids.Count()) { throw new Exception("Couldn't find one or more users for the given user ids."); } return accessUserGuids.Select(x => BuildLightweightUserDto(x)); }
public void AddRoleToGroup(DT.UserGroup userGroup, DT.Role role) { Guid[] userIds; string[] aspUsers; using (DA.AccessServiceDataContext accessContext = new DA.AccessServiceDataContext()) { userIds = (from u in accessContext.UserGroupUserGroups where u.UserGroupUserGroupId == userGroup.Id select u.UserGroupId).ToArray(); } using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) { aspUsers = (from u in aspContext.aspnet_Users where userIds.Contains(u.UserId) select u.UserName).ToArray(); } Roles.AddUsersToRole(aspUsers, role.Name); }
public void RemoveRoleFromGroup(DT.UserGroup userGroup, DT.Role role) { RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator); Guid[] userIds; string[] aspUsers; using (DA.AccessServiceDataContext accessContext = new DA.AccessServiceDataContext()) { userIds = (from u in accessContext.UserGroupUserGroups where u.UserGroupUserGroupId == userGroup.Id select u.UserGroupId).ToArray(); } using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) { aspUsers = (from u in aspContext.aspnet_Users where userIds.Contains(u.UserId) select u.UserName).ToArray(); } Roles.RemoveUsersFromRole(aspUsers.ToArray(), role.Name); }
public IEnumerable<Guid> GetUserGroupIdsOfGroup(Guid groupId) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from u in context.UserGroupUserGroups where u.UserGroupUserGroupId == groupId select u.UserGroupId; return query.ToList(); } }
public void ReportError(DT.ClientError error) { using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { context.ClientErrors.InsertOnSubmit(Convert.ToEntity(error)); context.SubmitChanges(); } }
public IEnumerable<DT.UserGroup> GetGroupsOfCurrentUser() { Guid userId = UserManager.CurrentUserId; using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { var query = from g in context.UserGroupUserGroups from ug in context.UserGroupBases.OfType<DA.UserGroup>() where g.UserGroupId == userId && g.UserGroupUserGroupId == ug.Id select Convert.ToDto(ug); return query.ToList(); } }