public async Task<bool> Delete(DataLayer.Entities.User.RefreshTokens refreshToken) { using (DataLayer.EFDbContext.AuthorizationContext authContext = new EFDbContext.AuthorizationContext()) { authContext.RefreshTokens.Remove(refreshToken); return await authContext.SaveChangesAsync() > 0; } }
public async Task<bool> Delete(string refreshTokenId) { using (DataLayer.EFDbContext.AuthorizationContext authContext = new EFDbContext.AuthorizationContext()) { var refreshToken = await authContext.RefreshTokens.FindAsync(refreshTokenId); if (refreshToken != null) { authContext.RefreshTokens.Remove(refreshToken); return await authContext.SaveChangesAsync() > 0; } } return false; }
public async Task<bool> Insert(DataLayer.Entities.User.RefreshTokens refreshToken) { bool returnValue; using (DataLayer.EFDbContext.AuthorizationContext authContext = new EFDbContext.AuthorizationContext()) { DataLayer.Entities.User.RefreshTokens existingToken = authContext.RefreshTokens.Where(rt => rt.subject == refreshToken.subject && rt.clientId == refreshToken.clientId).SingleOrDefault(); if (existingToken != null) { bool result = await Delete(existingToken.refreshTokenId); } authContext.RefreshTokens.Add(refreshToken); returnValue = await authContext.SaveChangesAsync() > 0; } return returnValue; }
public async Task<IdentityRole> Insert(string roleName) { IdentityRole newRole = new IdentityRole(); newRole.Name = roleName; using (DataLayer.EFDbContext.AuthorizationContext authContext = new EFDbContext.AuthorizationContext()) { authContext.Roles.Add(newRole); await authContext.SaveChangesAsync(); } if (!string.IsNullOrEmpty(newRole.Id)) { return newRole; } return null; }
public async Task<List<string>> DeleteClaimsRoles(string roleId, int claimId) { List<string> errors = new List<string>(); int deletedCount = 0; try { using (DataLayer.EFDbContext.AuthorizationContext authContext = new EFDbContext.AuthorizationContext()) { DataLayer.Entities.User.ClaimsRoles claimsRole = await authContext.ClaimsRoles.FirstAsync(cr => cr.claimId == claimId && cr.roleId == roleId); if (claimsRole != null) { authContext.ClaimsRoles.Remove(claimsRole); deletedCount = await authContext.SaveChangesAsync(); if (deletedCount <= 0) { errors.Add("Error deleting ClaimRole object, ClaimID: " + claimId.ToString() + ", RoleID: " + roleId.ToString()); } } } } catch (DbEntityValidationException ex) { errors.Add(ex.ToString()); } return errors; }
public async Task<List<string>> InsertClaimRoles(string roleId, int claimId) { var errors = new List<string>(); DataLayer.Entities.User.ClaimsRoles claimRole = new DataLayer.Entities.User.ClaimsRoles { roleId = roleId, claimId = claimId }; try { using (DataLayer.EFDbContext.AuthorizationContext authContext = new EFDbContext.AuthorizationContext()) { authContext.ClaimsRoles.Add(claimRole); await authContext.SaveChangesAsync(); } } catch (DbEntityValidationException ex) { errors.Add(ex.ToString()); } return errors; }