Skip to content

Commit 49bb428

Browse files
committed
refactoring the validate delete method returning string :d
1 parent eada6c7 commit 49bb428

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

Core/Domain/Partners/Partner.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,22 @@ protected Partner()
3939
Accounts = null;
4040
}
4141

42-
/// <summary>
43-
///
44-
/// </summary>
45-
/// <returns></returns>
46-
public string ValidateDelete ()
42+
public bool CanDelete (out string errorMessage)
4743
{
44+
errorMessage = string.Empty;
4845
if (Contacts.Any())
4946
{
50-
return "Partner has existing Contacts";
47+
errorMessage = "Partner has existing Contacts";
48+
return false;
5149
}
5250

5351
if (Accounts.Any())
5452
{
55-
return "Partner has existing Accounts";
53+
errorMessage = "Partner has existing Accounts";
54+
return false;
5655
}
57-
58-
return null;
56+
57+
return true;
5958
}
6059
}
6160
}

Service/Controllers/PartnerApiController.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ public async Task<IHttpActionResult> DeleteAsync(int id)
111111
{
112112
return NotFound();
113113
}
114-
115-
var deletionError = partner.ValidateDelete();
116-
117-
if (deletionError != null)
114+
;
115+
if (partner.CanDelete(out string deletionError))
118116
{
119117
var httpError = new HttpError(deletionError);
120118

0 commit comments

Comments
 (0)