From 5ca55dfc0aab45251773dc86083d88f864cb4f17 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 8 Nov 2022 12:04:09 +0500 Subject: [PATCH] #7205798 fix --- .../Repository/UserRepository.cs | 21 +++------------- .../Repository/UserRoleRepository.cs | 24 +++---------------- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRepository.cs b/AsbCloudInfrastructure/Repository/UserRepository.cs index b38b923a..22477d44 100644 --- a/AsbCloudInfrastructure/Repository/UserRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRepository.cs @@ -5,7 +5,6 @@ using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudInfrastructure.EfCache; using Mapster; -using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -48,7 +47,7 @@ namespace AsbCloudInfrastructure.Repository await dbContext.SaveChangesAsync(token); DropCacheUsers(); - return updatedEntity?.Entity?.Id ?? 0; + return updatedEntity.Entity.Id; } public Task InsertRangeAsync(IEnumerable newItems, CancellationToken token = default) @@ -109,7 +108,7 @@ namespace AsbCloudInfrastructure.Repository var result = dbContext.Users.Upsert(entity); await dbContext.SaveChangesAsync(token); DropCacheUsers(); - return result?.Entity?.Id ?? 0; + return result.Entity.Id; } public async Task DeleteAsync(int id, CancellationToken token = default) @@ -122,21 +121,7 @@ namespace AsbCloudInfrastructure.Repository var result = dbContext.Users.Remove(entity); await dbContext.SaveChangesAsync(token); DropCacheUsers(); - return result?.Entity?.Id ?? 0; - } - - public async Task DeleteAsync(IEnumerable ids, CancellationToken token = default) - { - var dto = (await GetCacheUserAsync(token)).Where(r => ids.Contains(r.Id)); - if (dto is null) - return 0; - - var count = dto.Count(); - var entities = dto.Select(Convert); - dbContext.Users.RemoveRange(entities); - await dbContext.SaveChangesAsync(token); - DropCacheUsers(); - return count; + return result.Entity.Id; } public IEnumerable GetRolesByIdUser(int idUser, int nestedLevel = 0) diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 65666205..8fc9b10a 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -40,7 +40,7 @@ namespace AsbCloudInfrastructure.Repository await dbContext.SaveChangesAsync(token); DropCacheUserRole(); - return updatedEntity?.Entity?.Id ?? 0; + return updatedEntity.Entity.Id; } public Task InsertRangeAsync(IEnumerable newItems, CancellationToken token) @@ -53,9 +53,6 @@ namespace AsbCloudInfrastructure.Repository var entities = await GetCacheUserRoleAsync(token) .ConfigureAwait(false); - if (entities is null) - return Enumerable.Empty(); - return entities.Select(Convert); } @@ -100,7 +97,7 @@ namespace AsbCloudInfrastructure.Repository var result = dbContext.UserRoles.Upsert(entity); await dbContext.SaveChangesAsync(token); DropCacheUserRole(); - return result?.Entity?.Id ?? 0; + return result.Entity.Id; } public IEnumerable GetNestedById(int id, int recursionLevel = 7) @@ -135,22 +132,7 @@ namespace AsbCloudInfrastructure.Repository var removeEntity = dbContext.UserRoles.Remove(entity); await dbContext.SaveChangesAsync(token); DropCacheUserRole(); - return removeEntity?.Entity?.Id ?? 0; - } - else return 0; - } - - public async Task DeleteAsync(IEnumerable ids, CancellationToken token) - { - var entities = (await GetCacheUserRoleAsync(token)).Where(r => ids.Contains(r.Id)); - - if (entities is not null) - { - var count = entities.Count(); - dbContext.UserRoles.RemoveRange(entities); - await dbContext.SaveChangesAsync(token); - DropCacheUserRole(); - return count; + return removeEntity.Entity.Id; } else return 0; }