DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellService.cs

51 lines
1.5 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using System.Collections.Generic;
using System.Linq;
using System;
namespace AsbCloudInfrastructure.Services
{
public class WellService : IWellService
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryTracker telemetryTracker;
public WellService(IAsbCloudDbContext db, ITelemetryTracker telemetryTracker)
{
this.db = db;
this.telemetryTracker = telemetryTracker;
}
public IEnumerable<WellDto> GetTransmittingWells(int idCustomer)
{
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetRequests();
var wells = db.GetWellsByCustomer(idCustomer)
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
.ToList();
return wells.Select(w => From(w));
}
public IEnumerable<WellDto> GetWellsByCustomer(int idCustomer)
{
var wells = db.GetWellsByCustomer(idCustomer).ToList();
return wells.Select(w => From(w));
}
private static WellDto From(Well well)
{
var wellDto = new WellDto
{
Id = well.Id,
Caption = well.Caption,
Cluster = well.Cluster.Caption,
Deposit = well.Cluster.Deposit.Caption,
};
return wellDto;
}
}
}