コード例 #1
0
        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;
            }
        }
コード例 #2
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;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
ファイル: Roles.cs プロジェクト: innercitypressure/ngKeyBase
        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;
        }
コード例 #5
0
ファイル: Claims.cs プロジェクト: innercitypressure/ngKeyBase
        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;
        }
コード例 #6
0
ファイル: Claims.cs プロジェクト: innercitypressure/ngKeyBase
        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;
        }