рефакт

This commit is contained in:
eugeniy_ivanov 2023-02-14 12:20:29 +05:00
parent 6bf992f1f6
commit 2cc8abd767
2 changed files with 17 additions and 26 deletions

View File

@ -1,10 +1,8 @@
using AsbCloudDb.Model.Subsystems;
using AsbCloudDb.Model.WITS;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
@ -69,8 +67,7 @@ namespace AsbCloudDb.Model
Task<int> RefreshMaterializedViewAsync<TEntity>(CancellationToken token) where TEntity : class;
int SaveChanges();
int SaveChanges(bool acceptAllChangesOnSuccess);
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
DbSet<TEntity> Set<TEntity>(string name) where TEntity : class;
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
DbSet<TEntity> Set<TEntity>() where TEntity : class;
}
}

View File

@ -67,8 +67,7 @@ namespace AsbCloudInfrastructure.Repository
foreach(var dto in dtos)
{
dto.RoleNames = GetRolesNamesByIdUser(dto.Id);
};
};
return dtos;
}
@ -110,18 +109,16 @@ namespace AsbCloudInfrastructure.Repository
var entity = dbContext.Users.FirstOrDefault(u => u.Id == dto.Id);
if (entity is not null)
{
var user = Convert(dto);
entity.Id = user.Id;
entity.Company = user.Company;
entity.Name = user.Name;
entity.Email = user.Email;
entity.Phone = user.Phone;
entity.Surname = user.Surname;
entity.Patronymic = user.Patronymic;
entity.Position = user.Position;
entity.IdCompany = user.IdCompany;
entity.IdState = user.IdState;
{
entity.Id = dto.Id;
entity.Name = dto.Name;
entity.Email = dto.Email;
entity.Phone = dto.Phone;
entity.Surname = dto.Surname;
entity.Patronymic = dto.Patronymic;
entity.Position = dto.Position;
entity.IdCompany = dto.IdCompany;
entity.IdState = dto.IdState;
await dbContext.SaveChangesAsync(token);
}
DropCacheUsers();
@ -209,7 +206,11 @@ namespace AsbCloudInfrastructure.Repository
{
var relations = dbContext.RelationUserUserRoles.Where(r => r.IdUser == idUser);
dbContext.RelationUserUserRoles.RemoveRange(relations);
var entityRoles = roleDtos.Select(role => Convert(role));
var entityRoles = roleDtos.Select(role => new RelationUserUserRole
{
IdUser = idUser,
IdUserRole = role.Id
});
dbContext.RelationUserUserRoles.AddRange(entityRoles);
await dbContext.SaveChangesAsync(token);
DropCacheRelationUserUserRoleCacheTag();
@ -255,13 +256,6 @@ namespace AsbCloudInfrastructure.Repository
entity.PasswordHash = dbContext.Users.FirstOrDefault(u => u.Id == dto.Id)?.PasswordHash;
return entity;
}
protected RelationUserUserRole Convert(UserRoleDto dto)
{
var entity = dto.Adapt<RelationUserUserRole>();
return entity;
}
protected virtual UserExtendedDto Convert(User entity)
{
var dto = entity.Adapt<UserExtendedDto>();