forked from ddrilling/AsbCloudServer
Merge branch 'dev' of http://46.146.209.148:8080/DDrilling/AsbCloudServer into dev
This commit is contained in:
commit
e3e6a06ef6
@ -85,8 +85,8 @@ namespace AsbCloudInfrastructure.Repository
|
||||
};
|
||||
dto.Pressure = new PlanFactDto
|
||||
{
|
||||
Fact = entity.FlowFact,
|
||||
Plan = entity.FlowPlan
|
||||
Fact = entity.PressureFact,
|
||||
Plan = entity.PressurePlan
|
||||
};
|
||||
dto.TopDriveSpeed = new PlanFactDto
|
||||
{
|
||||
@ -100,6 +100,27 @@ namespace AsbCloudInfrastructure.Repository
|
||||
};
|
||||
return dto;
|
||||
}
|
||||
|
||||
protected override ProcessMap Convert(ProcessMapDto dto)
|
||||
{
|
||||
var entity = dto.Adapt<ProcessMap>();
|
||||
entity.AxialLoadPlan = dto.AxialLoad.Plan;
|
||||
entity.AxialLoadFact = dto.AxialLoad.Fact;
|
||||
|
||||
entity.FlowPlan = dto.Flow.Plan;
|
||||
entity.FlowFact = dto.Flow.Fact;
|
||||
|
||||
entity.PressurePlan = dto.Pressure.Plan;
|
||||
entity.PressureFact = dto.Pressure.Fact;
|
||||
|
||||
entity.TopDriveSpeedPlan = dto.TopDriveSpeed.Plan;
|
||||
entity.TopDriveSpeedFact = dto.TopDriveSpeed.Fact;
|
||||
|
||||
entity.TopDriveTorquePlan = dto.TopDriveTorque.Plan;
|
||||
entity.TopDriveTorqueFact = dto.TopDriveTorque.Fact;
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -35,27 +35,28 @@ namespace AsbCloudInfrastructure.Repository
|
||||
this.userRoleRepository = userRoleRepository;
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(UserExtendedDto dto, CancellationToken token = default)
|
||||
public async Task<int> InsertAsync(UserExtendedDto dto, CancellationToken token)
|
||||
{
|
||||
dto.Id = default;
|
||||
var entity = Convert(dto);
|
||||
await AssertLoginIsBusyAsync(dto.Login, token);
|
||||
var userRoles = await userRoleRepository.GetByNamesAsync(dto.RoleNames, token).ConfigureAwait(false);
|
||||
var updatedEntity = await dbContext.Users.AddAsync(entity, token).ConfigureAwait(false);
|
||||
await dbContext.SaveChangesAsync(token);
|
||||
|
||||
if (userRoles?.Any() == true)
|
||||
await UpdateRolesCacheForUserAsync(updatedEntity.Entity.Id, userRoles, token);
|
||||
|
||||
await dbContext.SaveChangesAsync(token);
|
||||
DropCacheUsers();
|
||||
return updatedEntity.Entity.Id;
|
||||
}
|
||||
|
||||
public Task<int> InsertRangeAsync(IEnumerable<UserExtendedDto> newItems, CancellationToken token = default)
|
||||
public Task<int> InsertRangeAsync(IEnumerable<UserExtendedDto> newItems, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<UserExtendedDto>> GetAllAsync(CancellationToken token = default)
|
||||
public async Task<IEnumerable<UserExtendedDto>> GetAllAsync(CancellationToken token)
|
||||
{
|
||||
var dtos = (await GetCacheUserAsync(token)).ToList();
|
||||
if (dtos is null)
|
||||
@ -76,7 +77,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<UserExtendedDto?> GetOrDefaultAsync(int id, CancellationToken token = default)
|
||||
public async Task<UserExtendedDto?> GetOrDefaultAsync(int id, CancellationToken token)
|
||||
{
|
||||
var dto = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == id);
|
||||
if (dto is null)
|
||||
@ -86,7 +87,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<int> UpdateAsync(UserExtendedDto dto, CancellationToken token = default)
|
||||
public async Task<int> UpdateAsync(UserExtendedDto dto, CancellationToken token)
|
||||
{
|
||||
if (dto.Id <= 1)
|
||||
throw new ArgumentInvalidException($"Invalid id {dto.Id}. You can't edit this user.", nameof(dto));
|
||||
@ -109,7 +110,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return result.Entity.Id;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAsync(int id, CancellationToken token = default)
|
||||
public async Task<int> DeleteAsync(int id, CancellationToken token)
|
||||
{
|
||||
var dto = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == id);
|
||||
if (dto is null)
|
||||
@ -159,7 +160,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
.Select(r => r.Caption)
|
||||
.Distinct();
|
||||
|
||||
private async Task AssertLoginIsBusyAsync(string login, CancellationToken token = default)
|
||||
private async Task AssertLoginIsBusyAsync(string login, CancellationToken token)
|
||||
{
|
||||
var existingUserDto = (await GetCacheUserAsync(token))
|
||||
.FirstOrDefault(u => u.Login.ToLower() == login.ToLower());
|
||||
|
@ -110,7 +110,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
public override async Task<ActionResult<int>> UpdateAsync([FromBody] ProcessMapDto value, CancellationToken token)
|
||||
{
|
||||
value.IdUser = User.GetUserId() ?? -1;
|
||||
return await base.InsertAsync(value, token);
|
||||
return await base.UpdateAsync(value, token);
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
|
Loading…
Reference in New Issue
Block a user