using System; using System.Linq; using System.Linq.Expressions; using Luticate2.Utils.DataAccess; using Luticate2.Utils.Dbo.Filter; using Luticate2.Utils.Dbo.Result; using Microsoft.EntityFrameworkCore; using TestUtils.DataAccess.Models; using TestUtils.Dbo.PkGuid; namespace TestUtils.DataAccess { public class LuUtilsPkGuidDataAccess : LuEfCrudDataAccess { public LuUtilsPkGuidDataAccess(IServiceProvider serviceProvider) : base(serviceProvider) { } protected override DbSet GetTable(LuUtilsDbContext db) { return db.pk_guid; } protected override pk_guid GetModelFromTCreate(PkGuidAddDbo obj) { return GetModelFromTUpdate(obj, new pk_guid()); } protected override void EditModelFromTUpdate(PkGuidAddDbo obj, pk_guid model) { model.some_int = obj.SomeInt; model.some_text = obj.SomeText; } public static PkGuidDbo GetDboFromModelStatic(pk_guid model) { return new PkGuidDbo { CreatedAt = model.created_at, UpdatedAt = model.updated_at, Id = model.id.ToString(), SomeInt = model.some_int, SomeText = model.some_text }; } protected override PkGuidDbo GetDboFromModel(pk_guid model) { return GetDboFromModelStatic(model); } protected override Expression> GetFilterExpression(LuFilterDbo filter) { return model => LuUtilsDbContext.lu_texts_match(filter.Query, model.some_text + " " + model.some_int.ToString()); } public LuResult SomeTextExists(string someText) { return Execute((db, table) => LuResult.Ok(table.Any(guid => guid.some_text == someText))); } } }