Files

65 lines
2.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using MP.Data.DbModels.Mtc;
using MP.Data.Repository.Utils;
using System.Threading.Tasks;
namespace MP.Data.Repository.Mtc
{
public class MtcSetupRepository : BaseRepository, IMtcSetupRepository
{
#region Public Constructors
public MtcSetupRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory) : base(ctxFactory)
{
}
#endregion Public Constructors
#region Public Methods
/// <inheritdoc />
public async Task<bool> DeleteAsync(string idxMacchina)
{
bool actRes = false;
await using var dbCtx = await CreateContextAsync();
var existing = await GetByIdxAsync(idxMacchina);
if (existing != null)
{
dbCtx.DbSetMtcSetup.Remove(existing);
actRes = await dbCtx.SaveChangesAsync() > 0;
}
return actRes;
}
/// <inheritdoc />
public async Task<MtcSetupModel> GetByIdxAsync(string idxMacchina)
{
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetMtcSetup
//.Include(s => s.MtcDataItems)
.FirstOrDefaultAsync(s => s.IdxMacchina == idxMacchina);
}
/// <inheritdoc />
public async Task<bool> InsertAsync(MtcSetupModel newRec)
{
bool actRes = false;
await using var dbCtx = await CreateContextAsync();
dbCtx.DbSetMtcSetup.Add(newRec);
actRes = await dbCtx.SaveChangesAsync() > 0;
return actRes;
}
/// <inheritdoc />
public async Task<bool> UpdateAsync(MtcSetupModel updRec)
{
bool actRes = false;
await using var dbCtx = await CreateContextAsync();
dbCtx.DbSetMtcSetup.Update(updRec);
actRes = await dbCtx.SaveChangesAsync() > 0;
return actRes;
}
#endregion Public Methods
}
}