private void PostCommentOnClick(object sender, EventArgs e, Entry entry, Competition comp) { if (!entry.IsVisible) { entry.IsVisible = true; return; } else { if (meetsCommentCriteria(entry)) { //Post a comment CommentRepos commentRep = new CommentRepos(); Comment com = new Comment(0, DateTime.Now, entry.Text, comp.Id, Session.Id); try { MySQLManager.InsertComment(com); entry.Text = ""; entry.IsVisible = false; Navigation.PushAsync(new CompetitionDetails(comp)); } catch { return; } } else { //error msg mby } } }
private async System.Threading.Tasks.Task NavigateButton_OnClickedInLoginAsync(object sender, EventArgs e, Button butt) { if (Crit()) { User user = new User(Session.Id, usernameEntry.Text, emailEntry.Text, passwordEntry.Text, firstnameEntry.Text, Session.Registrationdate); MySQLManager.UpdateUserInfo(user); await Navigation.PushAsync(new ProfileDetails()); } else { errorLabel.IsVisible = true; } }
private bool isFavorited(Competition selectedComp) { FavoriteRepos rep = new FavoriteRepos(); List <Favorite> fvs = MySQLManager.LoadFavs(); foreach (var item in fvs) { if (item.fk_Competitionsid == selectedComp.Id && item.fk_Usersid == Session.Id) { return(true); } } return(false); }
private async void NavigateButton_OnClickedInLogin(object sender, EventArgs e, Button butt) { if (Crit()) { List <User> users = MySQLManager.LoadUsers(); User usr = users.Where(x => x.email == emailEntry.Text).FirstOrDefault(); setUserSession(usr); await Navigation.PushAsync(new HomePage()); } else { errorLabel.IsVisible = true; } }
private void FavoriteButtonOnClick(object sender, EventArgs e, Button button, Competition selectedCom) { FavoriteRepos favRep = new FavoriteRepos(); if (isFavorited(selectedCom)) { button.BackgroundColor = Color.Orange; MySQLManager.DeleteFavorite(new Favorite(0, selectedCom.Id, Session.Id)); button.BackgroundColor = Color.LightGray; } else { Favorite fav = new Favorite(0, selectedCom.Id, Session.Id); MySQLManager.InsertFavorite(fav); button.BackgroundColor = Color.Orange; } }
bool MeetsCriteria2(User user) { try { var users = MySQLManager.LoadUsers(); if (users.Where(x => x.email == user.email).Count() > 0) { return(false); } } catch { return(false); } return(true); }
bool Crit() { List <User> users = MySQLManager.LoadUsers(); try { if (users.Where(x => x.email == emailEntry.Text).Count() < 1) { return(false); } User usr = users.Where(x => x.email == emailEntry.Text).FirstOrDefault(); return(usr.password == passwordEntry.Text); } catch { return(false); } }
async Task OnButtonClicked(object sender, EventArgs args, Button butt, competitionCreationSeed seed) { if (!MeetsCriteria(seed)) { errorLabel.IsVisible = true; } else { int type = LiveType.SelectedIndex; Assets.Competition comp = new Assets.Competition(0, eventName.Text, startDate.Date, endDate.Date, description.Text, type, Session.Id); int compIndex = MySQLManager.InsertCompetition(comp); foreach (var item in seed.Tasks) { item.fk_Competition_id = compIndex; MySQLManager.InsertTask(item); } await Navigation.PushAsync(new HomePage()); } }
async Task OnButtonClicked(object sender, EventArgs args, Button butt) { if (!MeetsCriteria()) { errorLabel.IsVisible = true; } else { User user = new User(0, username.Text, emailEntry.Text, password.Text, firstNameEntry.Text, DateTime.Now); if (!MeetsCriteria2(user)) { errorLabel2.IsVisible = true; return; } butt.Text = MySQLManager.InsertUser(user); await Navigation.PushAsync(new Login()); } }
public CompetitionDetails(Competition selectedComp) { User creator = MySQLManager.LoadUsers().Where(x => x.id == selectedComp.fk_CreatorId).FirstOrDefault(); Button FavoriteButton = new Button { Text = "☆", HeightRequest = 50, WidthRequest = 50, FontSize = 25, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, TextColor = Color.Yellow, BackgroundColor = Color.LightGray }; Button editButton = new Button(); Button EnterButton = new Button(); TaskRepos rep = new TaskRepos(); List <Task> tasks = rep.getTasks(selectedComp.Id); editButton.IsVisible = false; EnterButton.IsVisible = false; if (creator.id == Session.Id) { editButton = new Button() { IsVisible = true, Text = "Edit", BackgroundColor = Color.White, BorderColor = Color.Black, BorderWidth = 3, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, }; } else { EnterButton = new Button() { IsVisible = true, Text = "Enter", BackgroundColor = Color.White, BorderColor = Color.Black, BorderWidth = 3, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, }; } Entry commentEntry = new Entry() { IsVisible = false, BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, WidthRequest = 200, HeightRequest = 200 }; Button PostCommentButton = new Button() { Text = "Post", BackgroundColor = Color.White, BorderColor = Color.Black, BorderWidth = 3, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, }; if (isFavorited(selectedComp)) { FavoriteButton.BackgroundColor = Color.Orange; } FavoriteButton.Clicked += async(sender, args) => FavoriteButtonOnClick(sender, args, FavoriteButton, selectedComp); PostCommentButton.Clicked += async(sender, args) => PostCommentOnClick(sender, args, commentEntry, selectedComp); EnterButton.Clicked += async(sender, args) => await EnterButtonOnClick(sender, args, selectedComp); editButton.Clicked += async(sender, args) => await EditButtonClick(sender, args, editButton, selectedComp); List <User> users = MySQLManager.LoadUsers(); User usr = users.Where(x => x.id == selectedComp.fk_CreatorId).FirstOrDefault(); StackLayout C = new StackLayout(); C.Children.Add(new Label { Text = selectedComp.Name, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }); C.Children.Add(new Label { Text = $"Created by: {usr.username}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }); C.Children.Add(new Label { Text = $"{selectedComp.Description}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }); C.Children.Add(new Label { Text = $"Total tasks: {tasks.Count}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }); C.Children.Add(FavoriteButton); C.Children.Add(editButton); C.Children.Add(EnterButton); C.Children.Add(new Label { Text = $"Comments:", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }); C.Children.Add(commentEntry); C.Children.Add(PostCommentButton); List <Comment> comments = MySQLManager.LoadCommentByCompetition(selectedComp.Id); foreach (var item in comments) { try { C.Children.Add(new Label { Text = $"{users.Where(x => x.id == item.fk_Usersid).FirstOrDefault().username}:{comments.Count}\n" + $"{item.Commentaras}\n{item.Date}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, WidthRequest = 200, HeightRequest = 150 }); } catch { continue; } } ScrollView scrollView = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand, Content = C }; Content = scrollView; }
public ProfileDetails() { CompetitionRepos compet = new CompetitionRepos(); User creator = MySQLManager.LoadUsers().Where(x => x.id == Session.Id).FirstOrDefault(); int total = compet.getTotalCompetitionCount(Session.Id); Button editButton = new Button(); TaskRepos rep = new TaskRepos(); editButton.IsVisible = false; if (creator.id == Session.Id) { editButton = new Button() { IsVisible = true, Text = "Edit", BackgroundColor = Color.White, BorderColor = Color.Black, BorderWidth = 3, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, }; } editButton.Clicked += async(sender, args) => await EditButtonClick(sender, args, editButton); ScrollView scrollView = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand, Content = new StackLayout { Children = { new Label { Text = "Profile details: ", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }, new Label { Text = $"Username: {creator.username}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }, //cia pakeisti i user username new Label { Text = $"Email: {creator.email}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }, new Label { Text = $"First name: {creator.first_name}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }, new Label { Text = $"Registration date: {creator.registration_date}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }, new Label { Text = $"Total competitions created: {total}", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }, editButton } } }; Content = scrollView; }