forked from ddrilling/AsbCloudServer
CS2-50: Controllers and some services are made async
This commit is contained in:
parent
e4800bf281
commit
4c4048865c
@ -1,20 +1,21 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IAnalyticsService
|
||||
{
|
||||
PaginationContainer<TelemetryOperationDto> GetOperationsByWell(int idWell,
|
||||
Task<PaginationContainer<TelemetryOperationDto>> GetOperationsByWellAsync(int idWell,
|
||||
IEnumerable<int> categoryids = default, DateTime begin = default,
|
||||
DateTime end = default, int skip = 0, int take = 32);
|
||||
IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int idWell);
|
||||
IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int idWell,
|
||||
Task<IEnumerable<WellDepthToDayDto>> GetWellDepthToDayAsync(int idWell);
|
||||
Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
||||
int intervalHoursTimestamp, int workBeginTimestamp);
|
||||
IEnumerable<TelemetryOperationDurationDto> GetOperationsSummary(int idWell,
|
||||
Task<IEnumerable<TelemetryOperationDurationDto>> GetOperationsSummaryAsync(int idWell,
|
||||
DateTime begin = default, DateTime end = default);
|
||||
IEnumerable<TelemetryOperationInfoDto> GetOperationsToInterval(int idWell,
|
||||
Task<IEnumerable<TelemetryOperationInfoDto>> GetOperationsToIntervalAsync(int idWell,
|
||||
int intervalHoursTimestamp, int workBeginTimestamp);
|
||||
void SaveAnalytics(DataSaubBaseDto dataSaub);
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IClusterService
|
||||
{
|
||||
IEnumerable<DepositDto> GetDeposits(int idCompany);
|
||||
IEnumerable<ClusterDto> GetClusters(int idCompany, int depositId);
|
||||
IEnumerable<ClusterDto> GetClusters(int idCompany);
|
||||
IEnumerable<WellDto> GetWells(int idCompany, int clusterId);
|
||||
ClusterStatDto GetStat(int idCompany, int clusterId);
|
||||
Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany);
|
||||
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany, int depositId);
|
||||
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany);
|
||||
Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany, int clusterId);
|
||||
Task<ClusterStatDto> GetStatAsync(int idCompany, int clusterId);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IWellService
|
||||
{
|
||||
IEnumerable<WellDto> GetWellsByCompany(int idCompany);
|
||||
IEnumerable<WellDto> GetTransmittingWells(int idCompany);
|
||||
bool IsCompanyInvolvedInWell(int idCompany, int idWell);
|
||||
IEnumerable<WellOperationDto> GetOperations(int idWell);
|
||||
Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany);
|
||||
Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany);
|
||||
Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell);
|
||||
Task<IEnumerable<WellOperationDto>> GetOperationsAsync(int idWell);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.Common;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@ -490,7 +491,7 @@ namespace AsbCloudDb.Model
|
||||
return (datesRange.From, datesRange.To);
|
||||
}
|
||||
|
||||
public IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId,
|
||||
public async Task<IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)>> GetDepthToIntervalAsync(int telemetryId,
|
||||
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset)
|
||||
{
|
||||
//TODO: Сменить на LINQ группирование
|
||||
@ -502,19 +503,25 @@ namespace AsbCloudDb.Model
|
||||
GROUP BY floor((extract(epoch from t.date) - {workStartTimestamp} + {timezoneOffset}) / {intervalHoursTimestamp});";
|
||||
|
||||
Database.OpenConnection();
|
||||
using var reader = command.ExecuteReader();
|
||||
if (reader.HasRows)
|
||||
using var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetResult(DbDataReader rd)
|
||||
{
|
||||
while (reader.Read())
|
||||
if (rd.HasRows)
|
||||
{
|
||||
yield return
|
||||
(
|
||||
(double?)reader.GetValue(0),
|
||||
(double?)reader.GetValue(1),
|
||||
(DateTime)reader.GetValue(2)
|
||||
);
|
||||
while (reader.Read())
|
||||
{
|
||||
yield return
|
||||
(
|
||||
(double?)reader.GetValue(0),
|
||||
(double?)reader.GetValue(1),
|
||||
(DateTime)reader.GetValue(2)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GetResult(reader);
|
||||
}
|
||||
|
||||
public async Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default)
|
||||
|
@ -41,7 +41,7 @@ namespace AsbCloudDb.Model
|
||||
IQueryable<Well> GetWellsForCompany(int idCompany);
|
||||
IQueryable<User> GetUsersByLogin(string login);
|
||||
(DateTime From, DateTime To) GetDatesRange<T>(int idTelemetry) where T : class, IIdTelemetryDate;
|
||||
IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId,
|
||||
Task<IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)>> GetDepthToIntervalAsync(int telemetryId,
|
||||
int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset);
|
||||
Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default) where TEntity : class;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
@ -30,7 +31,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
||||
}
|
||||
|
||||
public IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int idWell)
|
||||
public async Task<IEnumerable<WellDepthToDayDto>> GetWellDepthToDayAsync(int idWell)
|
||||
{
|
||||
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
|
||||
@ -52,15 +53,15 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (m > 1)
|
||||
depthToTimeData = depthToTimeData.Where(d => d.Id % m == 0);
|
||||
|
||||
return depthToTimeData.Select(d => new WellDepthToDayDto
|
||||
return await depthToTimeData.Select(d => new WellDepthToDayDto
|
||||
{
|
||||
WellDepth = d.WellDepth ?? 0.0,
|
||||
BitDepth = d.BitDepth ?? 0.0,
|
||||
Date = d.Date
|
||||
}).AsNoTracking().ToList();
|
||||
}).AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
public IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int idWell,
|
||||
public async Task<IEnumerable<WellDepthToIntervalDto>> GetWellDepthToIntervalAsync(int idWell,
|
||||
int intervalSeconds, int workBeginSeconds)
|
||||
{
|
||||
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
||||
@ -72,7 +73,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
||||
|
||||
var drillingPeriodsInfo = db.GetDepthToInterval((int)telemetryId, intervalSeconds,
|
||||
var drillingPeriodsInfo = await db.GetDepthToIntervalAsync((int)telemetryId, intervalSeconds,
|
||||
workBeginSeconds, timezoneOffset);
|
||||
|
||||
var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto
|
||||
@ -84,7 +85,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return wellDepthToIntervalData;
|
||||
}
|
||||
|
||||
public PaginationContainer<TelemetryOperationDto> GetOperationsByWell(int idWell,
|
||||
public async Task<PaginationContainer<TelemetryOperationDto>> GetOperationsByWellAsync(int idWell,
|
||||
IEnumerable<int> categoryIds = default, DateTime begin = default,
|
||||
DateTime end = default, int skip = 0, int take = 32)
|
||||
{
|
||||
@ -125,7 +126,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (skip > 0)
|
||||
operations = operations.Skip(skip);
|
||||
|
||||
var operationsList = operations.Take(take).AsNoTracking().ToList();
|
||||
var operationsList = await operations.Take(take).AsNoTracking().ToListAsync();
|
||||
|
||||
if (operationsList.Count == 0)
|
||||
return result;
|
||||
@ -148,7 +149,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<TelemetryOperationDurationDto> GetOperationsSummary(int idWell,
|
||||
public async Task<IEnumerable<TelemetryOperationDurationDto>> GetOperationsSummaryAsync(int idWell,
|
||||
DateTime begin = default, DateTime end = default)
|
||||
{
|
||||
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
@ -159,22 +160,22 @@ namespace AsbCloudInfrastructure.Services
|
||||
var unixBegin = (begin - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
|
||||
var operations = (from a in db.TelemetryAnalysis
|
||||
where a.IdTelemetry == telemetryId &&
|
||||
a.UnixDate > unixBegin && a.UnixDate < unixEnd
|
||||
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
||||
group a by new { a.IdOperation, o.Name } into g
|
||||
select new TelemetryOperationDurationDto
|
||||
{
|
||||
OperationName = g.Key.Name,
|
||||
Duration = g.Where(g => g.DurationSec > 0)
|
||||
.Sum(a => a.DurationSec)
|
||||
}).AsNoTracking().ToList();
|
||||
var operations = await (from a in db.TelemetryAnalysis
|
||||
where a.IdTelemetry == telemetryId &&
|
||||
a.UnixDate > unixBegin && a.UnixDate < unixEnd
|
||||
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
||||
group a by new { a.IdOperation, o.Name } into g
|
||||
select new TelemetryOperationDurationDto
|
||||
{
|
||||
OperationName = g.Key.Name,
|
||||
Duration = g.Where(g => g.DurationSec > 0)
|
||||
.Sum(a => a.DurationSec)
|
||||
}).AsNoTracking().ToListAsync();
|
||||
|
||||
return operations;
|
||||
}
|
||||
|
||||
public IEnumerable<TelemetryOperationInfoDto> GetOperationsToInterval(int idWell,
|
||||
public async Task<IEnumerable<TelemetryOperationInfoDto>> GetOperationsToIntervalAsync(int idWell,
|
||||
int intervalSeconds, int workBeginSeconds)
|
||||
{
|
||||
intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds;
|
||||
@ -186,21 +187,21 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId);
|
||||
|
||||
var operations = (from a in db.TelemetryAnalysis
|
||||
where a.IdTelemetry == telemetryId
|
||||
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
||||
group a by new
|
||||
{
|
||||
Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds),
|
||||
OperationId = a.IdOperation,
|
||||
o.Name
|
||||
} into g
|
||||
select new
|
||||
{
|
||||
IntervalStart = g.Min(d => d.UnixDate),
|
||||
OperationName = g.Key.Name,
|
||||
OperationsDuration = g.Sum(an => an.DurationSec)
|
||||
}).AsNoTracking().ToList();
|
||||
var operations = await (from a in db.TelemetryAnalysis
|
||||
where a.IdTelemetry == telemetryId
|
||||
join o in db.TelemetryOperations on a.IdOperation equals o.Id
|
||||
group a by new
|
||||
{
|
||||
Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds),
|
||||
OperationId = a.IdOperation,
|
||||
o.Name
|
||||
} into g
|
||||
select new
|
||||
{
|
||||
IntervalStart = g.Min(d => d.UnixDate),
|
||||
OperationName = g.Key.Name,
|
||||
OperationsDuration = g.Sum(an => an.DurationSec)
|
||||
}).AsNoTracking().ToListAsync();
|
||||
|
||||
var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
|
||||
.Select(o => new TelemetryOperationInfoDto
|
||||
|
@ -4,6 +4,7 @@ using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
@ -16,15 +17,15 @@ namespace AsbCloudInfrastructure.Services
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public IEnumerable<DepositDto> GetDeposits(int idCompany)
|
||||
public async Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany)
|
||||
{
|
||||
var wellEntities = (from well in db.Wells
|
||||
var wellEntities = await (from well in db.Wells
|
||||
.Include(w => w.RelationCompaniesWells)
|
||||
.Include(w => w.WellType)
|
||||
.Include(w => w.Cluster)
|
||||
.ThenInclude(c => c.Deposit)
|
||||
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
|
||||
select well).AsNoTracking().ToList();
|
||||
select well).AsNoTracking().ToListAsync();
|
||||
|
||||
var gDepositEntities = wellEntities
|
||||
.GroupBy(w => w.Cluster)
|
||||
@ -60,13 +61,13 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public IEnumerable<ClusterDto> GetClusters(int idCompany)
|
||||
public async Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany)
|
||||
{
|
||||
var entities = db.GetWellsForCompany(idCompany)
|
||||
var entities = await db.GetWellsForCompany(idCompany)
|
||||
.Select(e => e.Cluster)
|
||||
.Distinct()
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
|
||||
var dtos = entities.Select(e => new ClusterDto
|
||||
{
|
||||
@ -79,14 +80,14 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public IEnumerable<ClusterDto> GetClusters(int idCompany, int depositId)
|
||||
public async Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany, int depositId)
|
||||
{
|
||||
var entities = db.GetWellsForCompany(idCompany)
|
||||
var entities = await db.GetWellsForCompany(idCompany)
|
||||
.Select(e => e.Cluster)
|
||||
.Where(e => e.IdDeposit == depositId)
|
||||
.Distinct()
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
|
||||
var dtos = entities.Select(e => new ClusterDto
|
||||
{
|
||||
@ -99,12 +100,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public IEnumerable<WellDto> GetWells(int idCompany, int idCluster)
|
||||
public async Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany, int idCluster)
|
||||
{
|
||||
var entities = db.GetWellsForCompany(idCompany)
|
||||
var entities = await db.GetWellsForCompany(idCompany)
|
||||
.Where(e => e.IdCluster == idCluster)
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
|
||||
var dtos = entities.Select(e => new WellDto
|
||||
{
|
||||
@ -119,13 +120,13 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public ClusterStatDto GetStat(int idCompany, int idCluster)
|
||||
public async Task<ClusterStatDto> GetStatAsync(int idCompany, int idCluster)
|
||||
{
|
||||
var wellEntities = from w in db.Wells
|
||||
where w.IdCluster == idCluster && w.RelationCompaniesWells.Any(c => c.IdCompany == idCompany)
|
||||
select w;
|
||||
|
||||
var wellStatDtos = wellEntities.Select(e => new WellStatDto
|
||||
var wellStatDtos = await wellEntities.Select(e => new WellStatDto
|
||||
{
|
||||
Id = e.Id,
|
||||
Caption = e.Caption,
|
||||
@ -167,7 +168,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
CompanyType = c.Company.CompanyType.Caption,
|
||||
}),
|
||||
WellType = e.WellType.Caption,
|
||||
}).AsNoTracking().ToList();
|
||||
}).AsNoTracking().ToListAsync();
|
||||
|
||||
if (!wellStatDtos.Any())
|
||||
return null;
|
||||
|
@ -6,6 +6,8 @@ using Mapster;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
@ -23,36 +25,35 @@ namespace AsbCloudInfrastructure.Services
|
||||
cacheRelationCompaniesWells = cacheDb.GetCachedTable<RelationCompanyWell>((AsbCloudDbContext)db);
|
||||
}
|
||||
|
||||
public IEnumerable<WellDto> GetTransmittingWells(int idCompany)
|
||||
public async Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany)
|
||||
{
|
||||
var wells = new List<Well>();
|
||||
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
||||
if (activeTelemetriesUids.Any())
|
||||
{
|
||||
wells = db.GetWellsForCompany(idCompany)
|
||||
wells = await db.GetWellsForCompany(idCompany)
|
||||
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
}
|
||||
return wells.Select(w => From(w));
|
||||
}
|
||||
|
||||
public IEnumerable<WellDto> GetWellsByCompany(int idCompany)
|
||||
public async Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany)
|
||||
{
|
||||
var wells = db.GetWellsForCompany(idCompany).ToList();
|
||||
var wells = await db.GetWellsForCompany(idCompany).ToListAsync();
|
||||
return wells.Select(w => From(w));
|
||||
}
|
||||
|
||||
public bool IsCompanyInvolvedInWell(int idCompany, int idWell)
|
||||
=> cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
||||
public async Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell)
|
||||
=> await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell &&
|
||||
r.IdCompany == idCompany, new CancellationToken());
|
||||
|
||||
public IEnumerable<WellOperationDto> GetOperations(int idWell)
|
||||
public async Task<IEnumerable<WellOperationDto>> GetOperationsAsync(int idWell)
|
||||
{
|
||||
var entities = db
|
||||
.WellOperations
|
||||
.Where(o => o.IdWell == idWell)
|
||||
var entities = await db.WellOperations.Where(o => o.IdWell == idWell)
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
|
||||
var dtos = entities.Adapt<WellOperationDto>();
|
||||
|
||||
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -35,15 +36,15 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/operationsByWell")]
|
||||
[ProducesResponseType(typeof(PaginationContainer<TelemetryOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetOperationsByWell(int idWell, int skip = 0, int take = 32,
|
||||
public async Task<IActionResult> GetOperationsByWellAsync(int idWell, int skip = 0, int take = 32,
|
||||
[FromQuery] IEnumerable<int> categoryIds = default, DateTime begin = default, DateTime end = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var analytics = analyticsService.GetOperationsByWell(idWell, categoryIds, begin, end, skip, take);
|
||||
var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take);
|
||||
|
||||
if (analytics is null || analytics.Count == 0)
|
||||
return NoContent();
|
||||
@ -59,14 +60,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/wellDepthToDay")]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetWellDepthToDay(int idWell)
|
||||
public async Task<IActionResult> GetWellDepthToDayAsync(int idWell)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var wellDepthToDayData = analyticsService.GetWellDepthToDay(idWell);
|
||||
var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell);
|
||||
|
||||
if (wellDepthToDayData is null || !wellDepthToDayData.Any())
|
||||
return NoContent();
|
||||
@ -84,15 +85,15 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/wellDepthToInterval")]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetWellDepthToInterval(int idWell,
|
||||
public async Task<IActionResult> GetWellDepthToIntervalAsync(int idWell,
|
||||
int intervalSeconds, int workBeginSeconds)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(idWell,
|
||||
var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell,
|
||||
intervalSeconds, workBeginSeconds);
|
||||
|
||||
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
|
||||
@ -111,14 +112,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/operationsSummary")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetOperationsSummary(int idWell, DateTime begin = default, DateTime end = default)
|
||||
public async Task<IActionResult> GetOperationsSummaryAsync(int idWell, DateTime begin = default, DateTime end = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var analytics = analyticsService.GetOperationsSummary(idWell, begin, end);
|
||||
var analytics = await analyticsService .GetOperationsSummaryAsync(idWell, begin, end);
|
||||
|
||||
if (analytics is null || !analytics.Any())
|
||||
return NoContent();
|
||||
@ -136,15 +137,15 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/operationsToInterval")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetOperationsToInterval(int idWell,
|
||||
public async Task<IActionResult> GetOperationsToIntervalAsync(int idWell,
|
||||
int intervalSeconds, int workBeginSeconds)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var analytics = analyticsService.GetOperationsToInterval(idWell, intervalSeconds, workBeginSeconds);
|
||||
var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell, intervalSeconds, workBeginSeconds);
|
||||
|
||||
if (analytics is null || !analytics.Any())
|
||||
return NoContent();
|
||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -27,14 +28,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet()]
|
||||
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetClusters()
|
||||
public async Task<IActionResult> GetClustersAsync()
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
var result = clusterService.GetClusters((int)idCompany);
|
||||
var result = await clusterService.GetClustersAsync((int)idCompany);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -45,14 +46,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idCluster}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetWells(int idCluster)
|
||||
public async Task<IActionResult> GetWellsAsync(int idCluster)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
var result = clusterService.GetWells((int)idCompany, idCluster);
|
||||
var result = await clusterService.GetWellsAsync((int)idCompany, idCluster);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -63,14 +64,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idCluster}/Stat")]
|
||||
[ProducesResponseType(typeof(ClusterStatDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetStat(int idCluster)
|
||||
public async Task<IActionResult> GetStatAsync(int idCluster)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
var result = clusterService.GetStat((int)idCompany, idCluster);
|
||||
var result = await clusterService.GetStatAsync((int)idCompany, idCluster);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -52,14 +53,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/dataDatesRange")]
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetDataDatesRange(int idWell)
|
||||
public async Task<IActionResult> GetDataDatesRangeAsync(int idWell)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -27,14 +28,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetDeposits()
|
||||
public async Task<IActionResult> GetDepositsAsync()
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
var result = clusterService.GetDeposits((int)idCompany);
|
||||
var result = await clusterService.GetDepositsAsync((int)idCompany);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -45,14 +46,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet("{depositId}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetClusters(int depositId)
|
||||
public async Task<IActionResult> GetClustersAsync(int depositId)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
var result = clusterService.GetClusters((int)idCompany, depositId);
|
||||
var result = await clusterService.GetClustersAsync((int)idCompany, depositId);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -34,7 +35,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpPost]
|
||||
[Route("{idWell}/files")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult SaveFiles(int idWell, int idCategory, int idUser,
|
||||
public async Task<IActionResult> SaveFilesAsync(int idWell, int idCategory, int idUser,
|
||||
[FromForm] IFormFileCollection files)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
@ -42,7 +43,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var fileInfoCollection = files.Select(f =>
|
||||
@ -81,13 +82,13 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}")]
|
||||
[ProducesResponseType(typeof(PaginationContainer<FilePropertiesDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetFilesInfo([FromRoute] int idWell,
|
||||
public async Task<IActionResult> GetFilesInfoAsync([FromRoute] int idWell,
|
||||
int skip = 0, int take = 32, int idCategory = default,
|
||||
DateTime begin = default, DateTime end = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var filesInfo = fileService.GetFilesInfo(idWell, idCategory,
|
||||
@ -108,7 +109,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/{fileId}")]
|
||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetFile([FromRoute] int idWell, int fileId)
|
||||
public async Task<IActionResult> GetFileAsync([FromRoute] int idWell, int fileId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -117,7 +118,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var fileInfo = fileService.GetFileInfo(fileId);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -18,11 +19,11 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Get([FromRoute] int idWell, [FromQuery] int idCategory)
|
||||
public async Task<IActionResult> GetAsync([FromRoute] int idWell, [FromQuery] int idCategory)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var result = lastDataService.Get(idWell, idCategory);
|
||||
@ -30,11 +31,11 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Put([FromRoute] int idWell, [FromQuery] int idCategory, T data)
|
||||
public async Task<IActionResult> PutAsync([FromRoute] int idWell, [FromQuery] int idCategory, T data)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
lastDataService.Upsert(idWell, idCategory, data);
|
||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -51,14 +52,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/messagesDatesRange")]
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetMessagesDateRange(int idWell)
|
||||
public async Task<IActionResult> GetMessagesDateRangeAsync(int idWell)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
@ -64,7 +64,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpPost]
|
||||
[Route("{idWell}/report")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult CreateReport(int idWell, int idUser, int stepSeconds, int format,
|
||||
public async Task<IActionResult> CreateReportAsync(int idWell, int idUser, int stepSeconds, int format,
|
||||
DateTime begin = default, DateTime end = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
@ -72,7 +72,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var id = reportService.CreateReport(idWell, idUser,
|
||||
@ -90,7 +90,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/{reportName}")]
|
||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetReport([FromRoute] int idWell, string reportName)
|
||||
public async Task<IActionResult> GetReportAsync([FromRoute] int idWell, string reportName)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -99,7 +99,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
// TODO: словарь content typoв
|
||||
var relativePath = Path.Combine(fileService.RootPath, $"{idWell}",
|
||||
@ -148,14 +148,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/reportSize")]
|
||||
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetReportSize(int idWell, int stepSeconds, int format, DateTime begin = default, DateTime end = default)
|
||||
public async Task<IActionResult> GetReportSizeAsync(int idWell, int stepSeconds, int format, DateTime begin = default, DateTime end = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
int reportSize = reportService.GetReportPagesCount(idWell, begin, end, stepSeconds, format);
|
||||
@ -171,14 +171,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("{idWell}/reportsDatesRange")]
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetReportsDateRange(int idWell)
|
||||
public async Task<IActionResult> GetReportsDateRangeAsync(int idWell)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(idWell);
|
||||
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
@ -21,7 +22,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetWells()
|
||||
public async Task<IActionResult> GetWellsAsync()
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
||||
@ -30,7 +31,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
var wells = wellService.GetWellsByCompany((int)idCompany);
|
||||
var wells = await wellService.GetWellsByCompanyAsync((int)idCompany);
|
||||
|
||||
if (wells is null || !wells.Any())
|
||||
return NoContent();
|
||||
@ -40,31 +41,31 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
[HttpGet("{idWell}/operations")]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetOperations(int idWell)
|
||||
public async Task<IActionResult> GetOperationsAsync(int idWell)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return NoContent();
|
||||
|
||||
if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var dto = wellService.GetOperations(idWell);
|
||||
var dto = await wellService.GetOperationsAsync(idWell);
|
||||
|
||||
return Ok(dto);
|
||||
}
|
||||
|
||||
[HttpGet("transmittingWells")]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetTransmittingWells()
|
||||
public async Task<IActionResult> GetTransmittingWellsAsync()
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return NoContent();
|
||||
|
||||
var transmittingWells = wellService.GetTransmittingWells((int)idCompany);
|
||||
var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany);
|
||||
|
||||
if (transmittingWells is null || !transmittingWells.Any())
|
||||
return NoContent();
|
||||
|
@ -25,7 +25,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default)
|
||||
{
|
||||
if(!CanUserAccessToWell(idWell))
|
||||
if(!await CanUserAccessToWellAsync(idWell))
|
||||
return Forbid();
|
||||
|
||||
var result = await sectionsService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
|
||||
@ -36,7 +36,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[Route("{idSection}")]
|
||||
public async Task<IActionResult> GetAsync(int idSection, int idWell, CancellationToken token = default)
|
||||
{
|
||||
if (!CanUserAccessToWell(idWell))
|
||||
if (!await CanUserAccessToWellAsync(idWell))
|
||||
return Forbid();
|
||||
|
||||
var result = await sectionsService.GetAsync(idSection, token).ConfigureAwait(false);
|
||||
@ -44,9 +44,9 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Insert(int idWell, [FromBody] IEnumerable<WellSectionDto> values, CancellationToken token = default)
|
||||
public async Task<IActionResult> InsertAsync(int idWell, [FromBody] IEnumerable<WellSectionDto> values, CancellationToken token = default)
|
||||
{
|
||||
if (!CanUserAccessToWell(idWell))
|
||||
if (!await CanUserAccessToWellAsync(idWell))
|
||||
return Forbid();
|
||||
|
||||
var result = await sectionsService.InsertRangeAsync(values, idWell, token).ConfigureAwait(false);
|
||||
@ -54,9 +54,9 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> Put(int id, int idWell, [FromBody] WellSectionDto value, CancellationToken token = default)
|
||||
public async Task<IActionResult> PutAsync(int id, int idWell, [FromBody] WellSectionDto value, CancellationToken token = default)
|
||||
{
|
||||
if (!CanUserAccessToWell(idWell))
|
||||
if (!await CanUserAccessToWellAsync(idWell))
|
||||
return Forbid();
|
||||
|
||||
var result = await sectionsService.UpdateAsync(value, id, idWell, token).ConfigureAwait(false);
|
||||
@ -64,19 +64,19 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> Delete(int id, int idWell, CancellationToken token = default)
|
||||
public async Task<IActionResult> DeleteAsync(int id, int idWell, CancellationToken token = default)
|
||||
{
|
||||
if (!CanUserAccessToWell(idWell))
|
||||
if (!await CanUserAccessToWellAsync(idWell))
|
||||
return Forbid();
|
||||
|
||||
var result = await sectionsService.DeleteAsync(new int[] { id }, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
private bool CanUserAccessToWell(int idWell)
|
||||
private async Task<bool> CanUserAccessToWellAsync(int idWell)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
return idCompany is not null && wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
|
||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user