From ff72a0cb88cf8c38cf968896435a2e659f4ea1e9 Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Tue, 27 Dec 2022 14:03:44 +0500 Subject: [PATCH] refact -query -method name --- .../Services/IPlannedTrajectoryService.cs | 2 +- .../PlannedTrajectoryService.cs | 29 ++++++------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/AsbCloudApp/Services/IPlannedTrajectoryService.cs b/AsbCloudApp/Services/IPlannedTrajectoryService.cs index 3c4c1c6f..0bfa43bc 100644 --- a/AsbCloudApp/Services/IPlannedTrajectoryService.cs +++ b/AsbCloudApp/Services/IPlannedTrajectoryService.cs @@ -18,7 +18,7 @@ namespace AsbCloudApp.Services /// /// /// - Task?> GetAsync(int idWell, CancellationToken token); + Task> GetOrDefaultAsync(int idWell, CancellationToken token); /// /// Добавить строки с координатами diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs index 4c1be72e..3daec88f 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs @@ -38,25 +38,10 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory .ConfigureAwait(false); } - public async Task AddListAsync(int idWell, int idUser, IEnumerable plannedTrajectoryRows, CancellationToken token) - { - var timezone = wellService.GetTimezone(idWell); - foreach (var dto in plannedTrajectoryRows) - { - var entity = dto.Adapt(); - 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 DeleteRangeAsync(IEnumerable 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?> GetAsync(int idWell, CancellationToken token) + public async Task> 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);