Beispiel #1
0
 private async System.Threading.Tasks.Task NavigateButton_OnClickedInEditCompAsync(object sender, EventArgs e, Button butt, Competition selectedComp)
 {
     if (Crit())
     {
         int              type   = LiveType.SelectedIndex;
         Competition      comp   = new Competition(selectedComp.Id, eventName.Text, startDate.Date, endDate.Date, description.Text, type, selectedComp.fk_CreatorId);
         CompetitionRepos compet = new CompetitionRepos();
         compet.updateCompetition(comp);
         ;
         await Navigation.PushAsync(new CompetitionDetails(selectedComp));
     }
     else
     {
         errorLabel.IsVisible = true;
     }
 }
        public bool allCompetitions()
        {
            CompetitionRepos   rep   = new CompetitionRepos();
            List <Competition> comps = rep.getCompetition();

            if (comps.Count() > 0)
            {
                foreach (var item in comps)
                {
                    Label.Text += item.Name + "  ----  " + item.StartDate.ToString("yyyy-MM-dd") + "  ----  " + item.EndDate.ToString("yyyy-MM-dd") + "\n";
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public CompetitionList(int ind = 0, int sortIndex = -1, int filterIndex = -1)
        {
            Button seeLive = new Button
            {
                Text              = "Peržiūrėti aktyvius",
                BackgroundColor   = Color.White,
                BorderColor       = Color.Black,
                BorderWidth       = 3,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };

            Button butt = new Button
            {
                Text              = "Next page",
                BackgroundColor   = Color.White,
                BorderColor       = Color.Black,
                BorderWidth       = 3,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };

            Label = new Label
            {
                IsVisible         = false,
                TextColor         = Color.Red,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };

            CompetitionRepos   rep   = new CompetitionRepos();
            List <Competition> comps = rep.getCompetition();

            switch (sortIndex)
            {
            case 0:
                comps = comps.OrderByDescending(i => i.Name).ToList();
                break;

            case 1:
                comps = comps.OrderBy(i => i.Name).ToList();
                break;

            case 2:
                comps = comps.OrderByDescending(i => i.StartDate).ToList();
                break;

            case 3:
                comps = comps.OrderBy(i => i.StartDate).ToList();
                break;

            case 4:
                comps = rep.getFavoriteCompetition();
                break;

            case 5:
                comps = rep.getFavoriteCompetition();
                comps.Reverse();
                break;

            default:
                break;
            }

            switch (filterIndex)
            {
            case 0:
                List <Competition> myComps = new List <Competition>();
                foreach (var item in comps)
                {
                    if (item.fk_CreatorId == Session.Id)
                    {
                        myComps.Add(item);
                    }
                }
                comps = myComps;
                if (comps.Count <= 0)
                {
                    Label.IsVisible = true;
                    Label.Text      = "You haven't created any competitions";
                }
                break;

            case 1:
                comps = rep.getFavoriteCompetition(Session.Id);
                if (comps.Count <= 0)
                {
                    Label.IsVisible = true;
                    Label.Text      = "You haven't favorited any competitions";
                }
                break;

            case 2:
                comps = rep.getCompetition();
                break;

            default:
                break;
            }

            Button competition1 = new Button();
            Button competition2 = new Button();
            Button competition3 = new Button();
            Button competition4 = new Button();
            Button competition5 = new Button();

            competition1.IsVisible = false;
            competition2.IsVisible = false;
            competition3.IsVisible = false;
            competition4.IsVisible = false;
            competition5.IsVisible = false;


            if (comps.Count >= ind * 5 + 1)
            {
                competition1 = new Button()
                {
                    IsVisible         = true,
                    Text              = $"{comps[ind * 5].Name}",
                    BackgroundColor   = Color.White,
                    BorderColor       = Color.Black,
                    BorderWidth       = 3,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    WidthRequest      = 250
                };
            }
            if (comps.Count >= ind * 5 + 2)
            {
                competition2 = new Button()
                {
                    IsVisible         = true,
                    Text              = $"{comps[ind * 5 + 1].Name}",
                    BackgroundColor   = Color.White,
                    BorderColor       = Color.Black,
                    BorderWidth       = 3,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    WidthRequest      = 250
                };
            }
            if (comps.Count >= ind * 5 + 3)
            {
                competition3 = new Button()
                {
                    IsVisible         = true,
                    Text              = $"{comps[ind * 5 + 2].Name}",
                    BackgroundColor   = Color.White,
                    BorderColor       = Color.Black,
                    BorderWidth       = 3,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    WidthRequest      = 250
                };
            }
            if (comps.Count >= ind * 5 + 4)
            {
                competition4 = new Button()
                {
                    IsVisible         = true,
                    Text              = $"{comps[ind * 5 + 3].Name}",
                    BackgroundColor   = Color.White,
                    BorderColor       = Color.Black,
                    BorderWidth       = 3,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    WidthRequest      = 250
                };
            }
            if (comps.Count >= ind * 5 + 5)
            {
                competition5 = new Button()
                {
                    IsVisible         = true,
                    Text              = $"{comps[ind * 5 + 4].Name}",
                    BackgroundColor   = Color.White,
                    BorderColor       = Color.Black,
                    BorderWidth       = 3,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    WidthRequest      = 250
                };
            }

            var criteriaList = new List <string>();

            criteriaList.Add("Name Descending");
            criteriaList.Add("Name Ascending");
            criteriaList.Add("Start Date Descending");
            criteriaList.Add("Start Date Ascending");
            criteriaList.Add("Favorite Count Descending");
            criteriaList.Add("Favorite Count Ascending");

            Picker picker = new Picker
            {
                Title           = "Sort Competitions",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };

            picker.ItemsSource = criteriaList;

            var filterCriteriaList = new List <string>();

            filterCriteriaList.Add("My competitions");
            filterCriteriaList.Add("Favorited competitions");
            filterCriteriaList.Add("All competitions");

            Picker filterPicker = new Picker
            {
                Title           = "Filter Competitions",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };

            filterPicker.ItemsSource = filterCriteriaList;

            //seeLive.Clicked += async (sender, args) => NavigateButton_OnClickedInLogin(sender, args, seeLive);

            bool allow = competition1.IsVisible && competition2.IsVisible && competition3.IsVisible && competition4.IsVisible && competition5.IsVisible;

            butt.Clicked += async(sender, args) => await NavigateButton_OnClickedInAllComps(sender, args, ind, allow, sortIndex, filterIndex);

            picker.SelectedIndexChanged       += (sender, args) => NavigatePicker_OnClickedInAllComps(picker, filterIndex);
            filterPicker.SelectedIndexChanged += (sender, args) => NavigateFilterPicker_OnClickedInAllComps(filterPicker);

            competition1.Clicked += async(sender, args) => await GoToCompetitonDetails(sender, args, comps[ind * 5]);

            competition2.Clicked += async(sender, args) => await GoToCompetitonDetails(sender, args, comps[ind * 5 + 1]);

            competition3.Clicked += async(sender, args) => await GoToCompetitonDetails(sender, args, comps[ind * 5 + 2]);

            competition4.Clicked += async(sender, args) => await GoToCompetitonDetails(sender, args, comps[ind * 5 + 3]);

            competition5.Clicked += async(sender, args) => await GoToCompetitonDetails(sender, args, comps[ind * 5 + 4]);

            ScrollView scrollView = new ScrollView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content         = new StackLayout
                {
                    Children =
                    {
                        new Label {
                            Text = "Competitions list", HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand
                        },
                        Label,
                        competition1,
                        competition2,
                        competition3,
                        competition4,
                        competition5,
                        butt,
                        picker,
                        filterPicker
                    }
                }
            };

            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;
        }