forked from ddrilling/AsbCloudServer
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using AsbCloudDb.Model;
|
|||
|
using AsbCloudApp.Services;
|
|||
|
using Mapster;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
|||
|
namespace AsbCloudInfrastructure.Services
|
|||
|
{
|
|||
|
public class LastDataService<Tdto, TModel> : ILastDataService<Tdto>
|
|||
|
where TModel : class, IIdWellCategory
|
|||
|
{
|
|||
|
private readonly DbContext context;
|
|||
|
private readonly IAsbCloudDbContext db;
|
|||
|
|
|||
|
//private Dictioanary dict =
|
|||
|
|
|||
|
public LastDataService(IConfiguration configuration, IAsbCloudDbContext db)
|
|||
|
{
|
|||
|
this.db = db;
|
|||
|
}
|
|||
|
|
|||
|
public Tdto Get(int idWell, int idCategory)
|
|||
|
{
|
|||
|
var dbSet = context.Set<TModel>();
|
|||
|
var entity = dbSet.FirstOrDefault(e =>
|
|||
|
e.IdWell == idWell && e.IdCategory == idCategory);
|
|||
|
|
|||
|
var dto = entity.Adapt<Tdto>();
|
|||
|
return dto;
|
|||
|
}
|
|||
|
|
|||
|
public int Upsert(int idCategory, Tdto value)
|
|||
|
{
|
|||
|
//var dbSet = context.Set<TModel>();
|
|||
|
//var dbSet = db.LastData;
|
|||
|
var model = value.Adapt<TModel>();
|
|||
|
dbSet.Update(model);
|
|||
|
return context.SaveChanges();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|