forked from ddrilling/AsbCloudServer
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
|
using AsbCloudApp.Data;
|
|||
|
using AsbCloudApp.Services;
|
|||
|
using AsbCloudDb.Model;
|
|||
|
using AutoMapper;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace AsbCloudInfrastructure.Services
|
|||
|
{
|
|||
|
public class WellService : IWellService
|
|||
|
{
|
|||
|
private readonly IAsbCloudDbContext db;
|
|||
|
private readonly MapperConfiguration mapperConfiguration;
|
|||
|
|
|||
|
public WellService(IAsbCloudDbContext db, MapperConfiguration mapperConfiguration)
|
|||
|
{
|
|||
|
this.db = db;
|
|||
|
this.mapperConfiguration = mapperConfiguration;
|
|||
|
}
|
|||
|
|
|||
|
public IEnumerable<WellDto> GetWellsByCustomer(int idCustomer)
|
|||
|
{
|
|||
|
var wells = db.GetWellsByCustomer(idCustomer).ToList();
|
|||
|
return wells.Select(w => From(w));
|
|||
|
}
|
|||
|
|
|||
|
private WellDto From(Well well)
|
|||
|
{
|
|||
|
var wellDto = new WellDto
|
|||
|
{
|
|||
|
Id = well.Id,
|
|||
|
Caption = well.Caption,
|
|||
|
Cluster = well.Cluster.Caption,
|
|||
|
Deposit = well.Cluster.Deposit.Caption,
|
|||
|
};
|
|||
|
|
|||
|
var dataJson = well.Telemetry?.LastDataSaub;
|
|||
|
|
|||
|
if (string.IsNullOrEmpty(dataJson))
|
|||
|
return wellDto;
|
|||
|
|
|||
|
var data = System.Text.Json.JsonSerializer.Deserialize<DataSaubBase>(dataJson);
|
|||
|
wellDto.LastData = mapperConfiguration.CreateMapper().Map<DataSaubBaseDto>(data);
|
|||
|
|
|||
|
return wellDto;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|