You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuUtilsPkGuidDataAccess.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. using Luticate2.Utils.DataAccess;
  5. using Luticate2.Utils.Dbo.Filter;
  6. using Luticate2.Utils.Dbo.Result;
  7. using Microsoft.EntityFrameworkCore;
  8. using TestUtils.DataAccess.Models;
  9. using TestUtils.Dbo.PkGuid;
  10. namespace TestUtils.DataAccess
  11. {
  12. public class LuUtilsPkGuidDataAccess : LuEfCrudDataAccess<pk_guid, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, LuUtilsDbContext, string>
  13. {
  14. public LuUtilsPkGuidDataAccess(IServiceProvider serviceProvider) : base(serviceProvider)
  15. {
  16. }
  17. protected override DbSet<pk_guid> GetTable(LuUtilsDbContext db)
  18. {
  19. return db.pk_guid;
  20. }
  21. protected override pk_guid GetModelFromTCreate(PkGuidAddDbo obj)
  22. {
  23. return GetModelFromTUpdate(obj, new pk_guid());
  24. }
  25. protected override void EditModelFromTUpdate(PkGuidAddDbo obj, pk_guid model)
  26. {
  27. model.some_int = obj.SomeInt;
  28. model.some_text = obj.SomeText;
  29. }
  30. protected override PkGuidDbo GetDboFromModel(pk_guid model)
  31. {
  32. return new PkGuidDbo
  33. {
  34. CreatedAt = model.created_at,
  35. UpdatedAt = model.updated_at,
  36. Id = model.id.ToString(),
  37. SomeInt = model.some_int,
  38. SomeText = model.some_text
  39. };
  40. }
  41. protected override Expression<Func<pk_guid, bool>> GetFilterExpression(LuFilterDbo filter)
  42. {
  43. return model => LuUtilsDbContext.lu_texts_match(filter.Query, model.some_text + " " + model.some_int.ToString());
  44. }
  45. public LuResult<bool> SomeTextExists(string someText)
  46. {
  47. return Execute((db, table) => LuResult<bool>.Ok(table.Any(guid => guid.some_text == someText)));
  48. }
  49. }
  50. }