public FrontClubMember(Account clubMember, int friendship) { this.friendship = friendship; ch = new ColorHandler(); Id = clubMember.Id; this.Emoji = clubMember.Emoji; this.Username = clubMember.Username; NotFriends = false; AreFriends = !NotFriends; UserColor = clubMember.Color; FriendIndicator = ch.fromStringToColor("yellow"); switch (this.friendship) { case 0: NotFriends = true; AreFriends = false; break; case 1: FriendIndicator = ch.fromStringToColor("yellow"); break; case 2: FriendIndicator = ch.fromStringToColor("green"); break; default: break; } }
//FUNCTIONS /// Create an account; returns 0 if successful, 1 if username is already in use, 2 if email is public async Task<int> CreateAccount(string username, string password, string email) { Account account = new Account(username, password, email); //check if username in use var usernameList = await accountTable.Where(item => item.Username == account.Username).ToListAsync(); var emailList = await accountTable.Where(item => item.Email == account.Email).ToListAsync(); //if username in use if (usernameList.Count > 0 ) { return 1; } //if email in use else if (emailList.Count > 0) { return 2; } //if ok else { await accountTable.InsertAsync(account); return 0; } }
public FrontComment(Comment comment, Account authorAccount, bool showReport = false) { this.ShowReport = showReport; Id = comment.Id; IsMember = true; ClubRequestBool = false; Time = comment.Time; Text = comment.Text; NumDroplets = comment.NumDroplets; ClubId = comment.ClubId; Picture = comment.Picture; UserEmoji = authorAccount.Emoji; AuthorAccountColor = authorAccount.Color; TextColor = "black"; if (comment.AuthorId == App.dbWrapper.GetUser().Id) { AuthorUsername = "******"; TextColor = AuthorAccountColor; } else { AuthorUsername = authorAccount.Username; } }
public FrontComment(ClubRequest clubRequest, Account authorAccount, bool isMember) { IsMember = isMember; ClubRequestBool = true; ClubId = clubRequest.ClubId; ClubRequestText = clubRequest.Text; ClubRequestUsername = authorAccount.Username; ClubRequestInstance = clubRequest; }
public FrontFriends(Account account, bool inSameClub) { ch = new ColorHandler(); Emoji = account.Emoji; Username = account.Username; Id = account.Id; if (inSameClub) { SharedClubIndicator = ch.fromStringToColor("green"); } else { SharedClubIndicator = ch.fromStringToColor("green"); } }
public FriendProfilePage(Account user, int activeFriendRequest, FriendRequest friendRequest = null) { //activeFriendRequest key 0 = not friends 1 = pending request from them 2 =friends 3= pending request from you ch = new ColorHandler(); this.activeFriendRequest = activeFriendRequest; this.friendRequest = friendRequest; this.user = user; BackgroundColor = ch.fromStringToColor("purple"); this.ToolbarItems.Add(new ToolbarItem { Icon = "Settings_Top.png", Order = ToolbarItemOrder.Primary, Command = new Command(() => menuPopup()) }); this.Padding = new Thickness(0, Device.OnPlatform(10, 0, 0), 0, 0); updateView(); }
/// sets the user to null rather than an account value public void LogoutUser() { User = null; }
///Create a comment; returns 1 if success, 2 if not a member of the club, 3 if banned /// NOTE: calling thigs with push notifications before finished registering, ERROR public async Task<int> CreateComment(string text, string clubId) { //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 3; } System.Diagnostics.Debug.WriteLine("mydebug---"+User.Id); Club club = await clubTable.LookupAsync(clubId); System.Diagnostics.Debug.WriteLine("mydebug----"+club.Id); //check if user is in club var list = await memberJuncTable.Where(item => item.AccountId == User.Id && item.ClubId == club.Id).ToListAsync(); if (list.Count > 0) { Comment comment = new Comment(User.Id, clubId, text); await commentTable.InsertAsync(comment); //update user User.NumComments++; await accountTable.UpdateAsync(User); System.Diagnostics.Debug.WriteLine("mydebug----" + "finished"); return 1; } else { return 2; } }
/// 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; } }
/// NOTE: DEPRACATED; WILL BE REMOVED SOON /*public async Task<bool> CreateAccount(string username, string password) { Account account = new Account(username, password, "no email"); //check if username in use var usernameList = await accountTable.Where(item => item.Username == account.Username).ToListAsync(); //var emailList = await accountTable.Where(item => item.Email == account.Email).ToListAsync(); if (usernameList.Count > 0) { return false; } else { await accountTable.InsertAsync(account); return true; } }*/ /// Login to an account; returns 1 if successful, 0 if failure public async Task<bool> LoginAccount(string username, string password) { var list = await accountTable.Where(item => item.Username == username && item.Password == password).ToListAsync(); if (list.Count > 0) { //set user User = list[0]; //establish push notification services CreatePushRegister(); return true; } else { return false; } }