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