|
|
|
@ -45,26 +45,27 @@ struct CreateClubView: View { |
|
|
|
Logger.error(error) |
|
|
|
Logger.error(error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let existingOrCreatedClub = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode) |
|
|
|
let club = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode) |
|
|
|
|
|
|
|
club.creator = Store.main.userId |
|
|
|
|
|
|
|
|
|
|
|
//update existing club if rights ok / freshly created club with data input from user |
|
|
|
//update existing club if rights ok / freshly created club with data input from user |
|
|
|
if existingOrCreatedClub.hasBeenCreated(by: Store.main.userId) { |
|
|
|
if club.hasBeenCreated(by: Store.main.userId) { |
|
|
|
existingOrCreatedClub.update(fromClub: club) |
|
|
|
club.update(fromClub: club) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
try dataStore.clubs.addOrUpdate(instance: existingOrCreatedClub) |
|
|
|
try dataStore.clubs.addOrUpdate(instance: club) |
|
|
|
} catch { |
|
|
|
} catch { |
|
|
|
Logger.error(error) |
|
|
|
Logger.error(error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//save into user |
|
|
|
//save into user |
|
|
|
if dataStore.user.clubs.contains(where: { $0 == existingOrCreatedClub.id }) == false { |
|
|
|
if dataStore.user.clubs.contains(where: { $0 == club.id }) == false { |
|
|
|
dataStore.user.clubs.append(existingOrCreatedClub.id) |
|
|
|
dataStore.user.clubs.append(club.id) |
|
|
|
self.dataStore.saveUser() |
|
|
|
self.dataStore.saveUser() |
|
|
|
} |
|
|
|
} |
|
|
|
dismiss() |
|
|
|
dismiss() |
|
|
|
selection?(existingOrCreatedClub) |
|
|
|
selection?(club) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|