1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using Luticate2.Utils.Business;
- using Luticate2.Utils.Dbo.Result;
- using TestUtils.DataAccess;
- using TestUtils.Dbo.PkGuid;
-
- namespace WebApiUtils.Business
- {
- public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, string>
- {
- private readonly LuUtilsPkGuidDataAccess _dataAccess;
-
- public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness) : base(dataAccess, notificationsBusiness)
- {
- _dataAccess = dataAccess;
- EntityType = "pkguid";
- }
-
- public LuResult<bool> SomeTextExists(string someText)
- {
- return _dataAccess.SomeTextExists(someText);
- }
-
- protected override LuResult<PkGuidAddDbo> CheckAdd(PkGuidAddDbo obj)
- {
- var res = SomeTextExists(obj.SomeText);
- if (!res)
- {
- return res.To<PkGuidAddDbo>();
- }
- if (res.Data)
- {
- return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText already exists", "");
- }
- if (obj.SomeText.EndsWith("_edited"))
- {
- return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText can not end with '_edited'", "");
- }
- return LuResult<PkGuidAddDbo>.Ok(obj);
- }
-
- protected override LuResult<PkGuidAddDbo> CheckEdit(PkGuidDbo dbo, PkGuidAddDbo update)
- {
- if (dbo.SomeText != update.SomeText)
- {
- var res = SomeTextExists(update.SomeText);
- if (!res)
- {
- return res.To<PkGuidAddDbo>();
- }
- if (res.Data)
- {
- return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText already exists", "");
- }
- }
- if (!update.SomeText.EndsWith("_edited"))
- {
- return LuResult<PkGuidAddDbo>.Error(LuStatus.InputError, "someText must end with '_edited'", "");
- }
- return LuResult<PkGuidAddDbo>.Ok(update);
- }
- }
- }
|