private async Task ValidateApartment(ApartmentDto apartment) { const int MIN_AREA_FOR_UNIT = 20; if (apartment.Area < MIN_AREA_FOR_UNIT) { throw new ValidationException(ErrorCodes.Invalid_Area, $"Area of an Apartment can not be smaller than 20"); } var building = await _buildingrepository.GetBuildingAsync(apartment.BuildingId); if (building.NumberOfUnits < apartment.Number) { throw new ValidationException(ErrorCodes.Max_Apartment_Number, $"Number Unit should not be greater than counts of building aparment"); } foreach (var c in await _buildingrepository.GetBuildingApartments(building.BuildingId)) { if (c.Number == apartment.Number) { throw new ValidationException(ErrorCodes.Invalid_Apartment_Number, $"This apartment Number Already exists"); } } }