diff --git a/AsbCloudApp/Services/IPlannedTrajectoryService.cs b/AsbCloudApp/Services/IPlannedTrajectoryService.cs
index 0bfa43bc..f225635d 100644
--- a/AsbCloudApp/Services/IPlannedTrajectoryService.cs
+++ b/AsbCloudApp/Services/IPlannedTrajectoryService.cs
@@ -28,9 +28,20 @@ namespace AsbCloudApp.Services
///
///
///
- Task AddAsync(int idWell, int idUser,
+ Task AddRangeAsync(int idWell, int idUser,
IEnumerable plannedTrajectoryRows, CancellationToken token);
+ ///
+ /// Добавить одну строку с координатами
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task AddAsync(int idWell, int idUser,
+ PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token);
+
///
/// Обновить строку с координатами
///
diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs
index 3daec88f..1d5fcad3 100644
--- a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs
+++ b/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs
@@ -22,22 +22,26 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
this.db = db;
this.wellService = wellService;
}
- public async Task AddAsync(int idWell, int idUser,IEnumerable plannedTrajectoryRows, CancellationToken token)
+ public async Task AddRangeAsync(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);
- }
+ var entitys = plannedTrajectoryRows
+ .Select(e => Convert(e, timezone, idWell, idUser));
+ db.PlannedTrajectorys.AddRange(entitys);
return await db.SaveChangesAsync(token)
.ConfigureAwait(false);
}
+ public async Task AddAsync(int idWell, int idUser, PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token)
+ {
+ var timezone = wellService.GetTimezone(idWell);
+ var entity = Convert(plannedTrajectoryRow, timezone, idWell, idUser);
+ db.PlannedTrajectorys.Add(entity);
+ return await db.SaveChangesAsync(token)
+ .ConfigureAwait(false);
+ }
+
+
public async Task DeleteRangeAsync(IEnumerable ids, CancellationToken token)
{
var query = db.PlannedTrajectorys
@@ -92,7 +96,19 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
{
var dto = entity.Adapt();
return dto;
- }
+ }
+
+ private static AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, SimpleTimezoneDto timezone, int idWell, int idUser)
+ {
+ var entity = dto.Adapt();
+ entity.IdWell = idWell;
+ entity.Id = default;
+ entity.UpdateDate = DateTime.Today.ToUtcDateTimeOffset(timezone.Hours);
+ entity.IdUser = idUser;
+ return entity;
+ }
+
+
}
#nullable disable
}
diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs
index 288b4750..61250cda 100644
--- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs
+++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs
@@ -30,8 +30,6 @@ namespace AsbCloudWebApi.Controllers
this.plannedTrajectoryService = plannedTrajectoryService;
}
- // ---------FROM FILE-----------
-
///
/// Возвращает шаблон для заполнения строк плановой траектории
///
@@ -113,10 +111,6 @@ namespace AsbCloudWebApi.Controllers
}
}
-
- //-------------MANUAL---------------
- // !!! методы не реализованы в сервисе, в контроллере заглушка !!!
-
///
/// Получаем список всех строк координат плановой траектории (для клиента)
///
@@ -138,12 +132,12 @@ namespace AsbCloudWebApi.Controllers
idWell, token).ConfigureAwait(false))
return Forbid();
- var result = plannedTrajectoryService.GetAsync(idWell,token);
+ var result = plannedTrajectoryService.GetOrDefaultAsync(idWell,token);
return Ok(result);
}
///
- /// Добавить новые координаты для плановой траектории
+ /// Добавить одну новую строчку координат для плановой траектории
///
///
///
@@ -157,7 +151,34 @@ namespace AsbCloudWebApi.Controllers
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
- var result = row;
+ int? idUser = User.GetUserId();
+ if (!idUser.HasValue)
+ return Forbid();
+ var result = await plannedTrajectoryService.AddAsync(idWell, idUser.Value, row, token)
+ .ConfigureAwait(false);
+ return Ok(result);
+ }
+
+ ///
+ /// Добавить массив строчек координат для плановой траектории
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ [Permission]
+ [ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)]
+ public async Task AddRowAsync(int idWell, [FromBody] IEnumerable rows,
+ CancellationToken token = default)
+ {
+ if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
+ return Forbid();
+ int? idUser = User.GetUserId();
+ if (!idUser.HasValue)
+ return Forbid();
+ var result = await plannedTrajectoryService.AddRangeAsync(idWell, idUser.Value, rows, token)
+ .ConfigureAwait(false);
return Ok(result);
}