This commit is contained in:
ai.astrakhantsev 2022-11-08 12:04:09 +05:00
parent 408429a0b5
commit 5ca55dfc0a
2 changed files with 6 additions and 39 deletions

View File

@ -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<int> InsertRangeAsync(IEnumerable<UserExtendedDto> 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<int> 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<int> DeleteAsync(IEnumerable<int> 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<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0)

View File

@ -40,7 +40,7 @@ namespace AsbCloudInfrastructure.Repository
await dbContext.SaveChangesAsync(token);
DropCacheUserRole();
return updatedEntity?.Entity?.Id ?? 0;
return updatedEntity.Entity.Id;
}
public Task<int> InsertRangeAsync(IEnumerable<UserRoleDto> newItems, CancellationToken token)
@ -53,9 +53,6 @@ namespace AsbCloudInfrastructure.Repository
var entities = await GetCacheUserRoleAsync(token)
.ConfigureAwait(false);
if (entities is null)
return Enumerable.Empty<UserRoleDto>();
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<UserRoleDto> 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<int> DeleteAsync(IEnumerable<int> 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;
}