Exemplo n.º 1
0
        private void HomeView_Loaded(object sender, RoutedEventArgs e)
        {
            MainWindow    = (MainWindow)Window.GetWindow(this);
            MainViewModel = (MainViewModel)MainWindow.DataContext;

            MainWindow.Width  = 1200;
            MainWindow.Height = 800;
            MainWindow.CenterWindowOnScreen();

            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
            {
                Request request = new Request
                {
                    Type         = RequestResponseType.FindCurrentUser,
                    SessionToken = MainModel.SessionToken
                };
                NetworkListener.SendRequest(request);
            }));

            ModelChangedHandler handler = null;

            handler = (string fieldName, Object field) =>
            {
                if (fieldName == "User")
                {
                    User user = MainModel.User;

                    ((HomeViewModel)DataContext).DisplayName = $"{user.FirstName} {user.LastName} ({user.Username})";
                }

                MainModel.ModelChanged -= handler;
            };

            MainModel.ModelChanged += handler;
        }
Exemplo n.º 2
0
        private void Login(object sender, RoutedEventArgs e)
        {
            Request request = new Request
            {
                Type = RequestResponseType.Login,
                User = new User
                {
                    Username = usernameOrEmail.Text,
                    Email    = usernameOrEmail.Text,
                    Password = password.Password
                }
            };

            ModelChangedHandler handler = null;

            handler = (string fieldName, Object field) =>
            {
                if (fieldName == "SessionToken")
                {
                    MainViewModel.CurrentView = new HomeView();
                }

                MainModel.ModelChanged -= handler;
            };

            MainModel.ModelChanged += handler;

            NetworkListener.SendRequest(request);
        }
Exemplo n.º 3
0
        private void EventView_Loaded(object sender, RoutedEventArgs e)
        {
            ModelChangedHandler handler = null;

            handler = (string fieldName, Object field) =>
            {
                if (fieldName == "User")
                {
                    User user = MainModel.User;

                    if (user != null)
                    {
                        if (user.JoinedEvents != null)
                        {
                            foreach (Event @event in MainModel.User.JoinedEvents)
                            {
                                events.Children.Add(new EventCardView
                                {
                                    DataContext = new EventCardViewModel
                                    {
                                        Title       = @event.Title,
                                        Description = @event.Description
                                    }
                                });
                            }
                        }
                        else
                        {
                            mainGrid.Children.Add(new Label
                            {
                                Content = "There are no events yet..."
                            });
                        }
                    }
                }
            };

            MainModel.ModelChanged += handler;
        }