public async Task Validate(Habitant habitant) { if (!await ExistHabitantAsync(habitant).ConfigureAwait(false)) { habitant.AddBrokenRule("Habitant not found"); } if (await ExistHabitantWithNameAsync(habitant).ConfigureAwait(false)) { habitant.AddBrokenRule("Habitant with the same name found"); } await CheckCommonDataForUpdateAndInsert(habitant); habitant.Validate("Can not update habitant"); }
public async Task Validate(Habitant habitant) { if (!await ExistHabitantAsync(habitant).ConfigureAwait(false)) { habitant.AddBrokenRule("Habitant not found"); habitant.Validate("Can not delete habitant"); } }
protected async Task CheckCommonDataForUpdateAndInsert(Habitant habitant) { if (!await ExistHairColorForHabitant(habitant).ConfigureAwait(false)) { habitant.AddBrokenRule("Defined Hair Color for habitant does not exist"); } if (!await ExistProfessionsForHabitant(habitant).ConfigureAwait(false)) { habitant.AddBrokenRule("Defined Professions for habitant does not exist"); } foreach (var friend in habitant.Friends) { if (!await ExistHabitantWithNameAsync(friend).ConfigureAwait(false)) { habitant.AddBrokenRule($"Friend '{friend}' not found"); } } }