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.

PkGuidBusiness.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Luticate2.Utils.Business;
  2. using Luticate2.Utils.Dbo.Result;
  3. using TestUtils.DataAccess;
  4. using TestUtils.Dbo.PkGuid;
  5. namespace WebApiUtils.Business
  6. {
  7. public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, string>
  8. {
  9. private readonly LuUtilsPkGuidDataAccess _dataAccess;
  10. public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness) : base(dataAccess, notificationsBusiness)
  11. {
  12. _dataAccess = dataAccess;
  13. EntityType = "pkguid";
  14. }
  15. public LuResult<bool> SomeTextExists(string someText)
  16. {
  17. return _dataAccess.SomeTextExists(someText);
  18. }
  19. protected override LuResult<PkGuidAddDbo> CheckAdd(PkGuidAddDbo obj)
  20. {
  21. var res = SomeTextExists(obj.SomeText);
  22. if (!res)
  23. {
  24. return res.To<PkGuidAddDbo>();
  25. }
  26. if (res.Data)
  27. {
  28. return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText already exists", "");
  29. }
  30. if (obj.SomeText.EndsWith("_edited"))
  31. {
  32. return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText can not end with '_edited'", "");
  33. }
  34. return LuResult<PkGuidAddDbo>.Ok(obj);
  35. }
  36. protected override LuResult<PkGuidAddDbo> CheckEdit(PkGuidDbo dbo, PkGuidAddDbo update)
  37. {
  38. if (dbo.SomeText != update.SomeText)
  39. {
  40. var res = SomeTextExists(update.SomeText);
  41. if (!res)
  42. {
  43. return res.To<PkGuidAddDbo>();
  44. }
  45. if (res.Data)
  46. {
  47. return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText already exists", "");
  48. }
  49. }
  50. if (!update.SomeText.EndsWith("_edited"))
  51. {
  52. return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText must end with '_edited'", "");
  53. }
  54. return LuResult<PkGuidAddDbo>.Ok(update);
  55. }
  56. }
  57. }