-query
-method name
This commit is contained in:
eugeniy_ivanov 2022-12-27 14:03:44 +05:00
parent 9819c2ac0d
commit ff72a0cb88
2 changed files with 10 additions and 21 deletions

View File

@ -18,7 +18,7 @@ namespace AsbCloudApp.Services
/// <param name="idWell"></param> /// <param name="idWell"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<PlannedTrajectoryDto>?> GetAsync(int idWell, CancellationToken token); Task<IEnumerable<PlannedTrajectoryDto>> GetOrDefaultAsync(int idWell, CancellationToken token);
/// <summary> /// <summary>
/// Добавить строки с координатами /// Добавить строки с координатами

View File

@ -38,25 +38,10 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
.ConfigureAwait(false); .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) 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); db.PlannedTrajectorys.RemoveRange(query);
return await db.SaveChangesAsync(token) return await db.SaveChangesAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
@ -65,18 +50,22 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
public async Task DeleteAllByIdWellAsync(int idWell, CancellationToken token) public async Task DeleteAllByIdWellAsync(int idWell, CancellationToken token)
{ {
var query = db.PlannedTrajectorys var query = db.PlannedTrajectorys
.AsNoTracking()
.Where(e => e.IdWell == idWell); .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); 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); var well = wellService.GetOrDefault(idWell);
if (well is null || well.Timezone is null) if (well is null || well.Timezone is null)
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
var query = db.PlannedTrajectorys var query = db.PlannedTrajectorys
.AsNoTracking()
.Where(x => x.IdWell == idWell); .Where(x => x.IdWell == idWell);
var entities = await query var entities = await query
.OrderBy(e => e.UpdateDate) .OrderBy(e => e.UpdateDate)