/// Join a club after being invited; ignores if exclusive and returns the status of trying to join the club as an int: /// 1 - success, 2 - club full, 4 - already in club public async Task<int> JoinClubByInvite(string accountId, string clubId) { //assumes the club exists as a precondition Club club = await clubTable.LookupAsync(clubId); if (club.NumMembers >= CLUB_SIZE) { return 2; } var list = await memberJuncTable.Where(item => item.AccountId == accountId && item.ClubId == club.Id).ToListAsync(); if (list.Count > 0) { return 4; } //assuming all precondition do not prevent user from joining club MemberJunction memberJunc = new MemberJunction(accountId, club.Id); await memberJuncTable.InsertAsync(memberJunc); //update club club.NumMembers++; await clubTable.UpdateAsync(club); //update user Account account = await accountTable.LookupAsync(accountId); account.NumClubsIn++; await accountTable.UpdateAsync(account); //add DBNotifications DBNotification DBNotification = new DBNotification(account.Id,"join","You joined the club "+club.Title+"!"); await dbNotificationTable.InsertAsync(DBNotification); return 1; }
/// Create a club; returns true if success, false if fails; fails if club name already in use or user is banned public async Task<bool> CreateClub(string title, string color, bool exclusive, List<string> tagList) { //check if banned (must get current instance of user account incase ban happend since login) User = await accountTable.LookupAsync(User.Id); if (DateTime.Compare(User.Banned, DateTime.Now) > 0) { return false; } Club club = new Club(User.CurrentCloudId, title, color, exclusive, User.Id); //check if the club name is in use var list = await clubTable.Where(item => item.Title.ToLower() == club.Title.ToLower() && item.CloudId==User.CurrentCloudId).ToListAsync(); if (list.Count > 0) { return false; } else { await clubTable.InsertAsync(club); //add tags to table based on title string[] titleTagList = title.Split(' '); foreach (string key in titleTagList) { Tag tag = new Tag(key.ToLower(), club.Id, club.CloudId); await tagTable.InsertAsync(tag); } //add tags to table based on tagList foreach (string key in tagList) { Tag tag = new Tag(key.ToLower(), club.Id,club.CloudId); await tagTable.InsertAsync(tag); } //add club founder to memberJunction //club size is initialized to one automatically MemberJunction memberJunction = new MemberJunction(User.Id, club.Id); await memberJuncTable.InsertAsync(memberJunction); //update user account User.NumClubsCreated++; User.NumClubsIn++; User.Points++; await accountTable.UpdateAsync(User); //make DBNotification DBNotification DBNotification = new DBNotification(User.Id, "join", "You created the club " + club.Title + "!"); await dbNotificationTable.InsertAsync(DBNotification); return true; } }