forked from ddrilling/AsbCloudServer
refact
-query -method name
This commit is contained in:
parent
9819c2ac0d
commit
ff72a0cb88
@ -18,7 +18,7 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<PlannedTrajectoryDto>?> GetAsync(int idWell, CancellationToken token);
|
||||
Task<IEnumerable<PlannedTrajectoryDto>> GetOrDefaultAsync(int idWell, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить строки с координатами
|
||||
|
@ -38,25 +38,10 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<int> AddListAsync(int idWell, int idUser, IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
foreach (var dto in plannedTrajectoryRows)
|
||||
{
|
||||
var entity = dto.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
|
||||
entity.IdWell = idWell;
|
||||
entity.Id = default;
|
||||
entity.UpdateDate = DateTime.Today.ToUtcDateTimeOffset(timezone.Hours);
|
||||
entity.IdUser = idUser;
|
||||
db.PlannedTrajectorys.Add(entity);
|
||||
}
|
||||
return await db.SaveChangesAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token)
|
||||
{
|
||||
var query = db.PlannedTrajectorys.Where(e => ids.Contains(e.Id));
|
||||
var query = db.PlannedTrajectorys
|
||||
.Where(e => ids.Contains(e.Id));
|
||||
db.PlannedTrajectorys.RemoveRange(query);
|
||||
return await db.SaveChangesAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
@ -65,19 +50,23 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
||||
public async Task DeleteAllByIdWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var query = db.PlannedTrajectorys
|
||||
.AsNoTracking()
|
||||
.Where(e => e.IdWell == idWell);
|
||||
var ids = await query.Select(r => r.IdWell).ToListAsync(token);
|
||||
var ids = await query
|
||||
.Select(r => r.IdWell)
|
||||
.ToListAsync(token);
|
||||
var result = await DeleteRangeAsync(ids, token);
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<PlannedTrajectoryDto>?> GetAsync(int idWell, CancellationToken token)
|
||||
public async Task<IEnumerable<PlannedTrajectoryDto>> GetOrDefaultAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = wellService.GetOrDefault(idWell);
|
||||
if (well is null || well.Timezone is null)
|
||||
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
|
||||
var query = db.PlannedTrajectorys
|
||||
.Where(x => x.IdWell == idWell);
|
||||
.AsNoTracking()
|
||||
.Where(x => x.IdWell == idWell);
|
||||
var entities = await query
|
||||
.OrderBy(e => e.UpdateDate)
|
||||
.ToListAsync(token);
|
||||
|
Loading…
Reference in New Issue
Block a user