コード例 #1
0
        /// <summary>
        ///     Retrieves tutorings for current user
        /// </summary>
        /// <returns>List of user's tutorings</returns>
        public async Task <List <MyTutoring> > GetMyTutorings()
        {
            var auth = new RestCommandWithAuthentication
            {
                authentication = MvvmNanoIoC.Resolve <Authentication>()
            };

            _restUrl = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/tutoring/my";

            if (MasterDetailViewModel.CurrentMode.Equals(MasterDetailViewModel.Mode.STUDENT))
            {
                _restUrl += "Requests";
            }
            else
            {
                _restUrl += "Offers";
            }

            var uri     = new Uri(string.Format(_restUrl, string.Empty));
            var json    = JsonConvert.SerializeObject(auth);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            Debug.WriteLine(json);
            var response = await _client.PostAsync(uri, content);

            Debug.WriteLine("Response:" + await response.Content.ReadAsStringAsync());
            if (response.IsSuccessStatusCode)
            {
                var rescontent = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <List <MyTutoring> >(rescontent));
            }
            return(null);
        }
コード例 #2
0
 public TutorialsViewModel()
 {
     _themeColor = (Color)Application.Current.Resources["MainColor"];
     SetTutorings();
     MvvmNanoIoC.Resolve <IMessenger>()
     .Subscribe(this, (object arg1, ChangeModeMessage arg2) => { SetTutorings(); });
 }
コード例 #3
0
 /// <summary>
 ///     Set first position and theme color, refresh pins on mode change
 /// </summary>
 public FeedMapViewModel()
 {
     GetFirstPosition();
     _themeColor = (Color)Application.Current.Resources["MainColor"];
     MvvmNanoIoC.Resolve <IMessenger>()
     .Subscribe(this, (object arg1, ChangeModeMessage arg2) => { SetPinsAsync(); });
 }
コード例 #4
0
        /// <summary>
        /// Creates a MvvmNanoContentPage for the given View Model type.
        /// </summary>
        private Page GetPageFor <TViewModel>() where TViewModel : MvvmNanoViewModel
        {
            var viewModel = MvvmNanoIoC.Resolve <TViewModel>();

            viewModel.Initialize();
            return(ResolvePage(viewModel));
        }
コード例 #5
0
ファイル: MainPage.xaml.cs プロジェクト: krdmllr/WorkTimer
        public MainPage()
        {
            InitializeComponent();

            //Manually set view model
            SetViewModel(MvvmNanoIoC.Resolve <MainViewModel>());
        }
コード例 #6
0
        /// <summary>
        /// Creates a MvvmNanoContentPage for the given View Model type and parameter
        /// </summary>
        private Page GetPageFor <TViewModel, TNavigationParameter>(TNavigationParameter navigationParameter) where TViewModel : MvvmNanoViewModel <TNavigationParameter>
        {
            var viewModel = MvvmNanoIoC.Resolve <TViewModel>();

            viewModel.Initialize(navigationParameter);
            return(ResolvePage(viewModel));
        }
コード例 #7
0
ファイル: HistoryPage.xaml.cs プロジェクト: krdmllr/WorkTimer
        public HistoryPage()
        {
            InitializeComponent();

            //Manually set view model
            SetViewModel(MvvmNanoIoC.Resolve <HistoryViewModel>());
        }
コード例 #8
0
        private static Page ResolvePage <TViewModel>(TViewModel viewModel) where TViewModel : IViewModel
        {
            IView viewFor = MvvmNanoIoC.Resolve <IPresenter>().CreateViewFor <TViewModel>();

            viewFor.SetViewModel(viewModel);
            return(viewFor as Page);
        }
コード例 #9
0
        private async Task LoginAsync()
        {
            CheckAuthentication auth = new CheckAuthentication();

            auth.authentication          = new Authentication();
            auth.authentication.password = Password;
            auth.authentication.userName = UserName;

            bool result = await IsValidAuthentication(auth);

            if (result)
            {
                if (PasswordShouldBeSaved)
                {
                    CService.SaveCredentials(UserName, Password);
                }
                MvvmNanoIoC.RegisterAsSingleton <Authentication>(auth.authentication);
                NavigateTo <MasterDetailViewModel>();
            }
            else
            {
                Info     = true;
                InfoText = "Passwort ist nicht korrekt";
                Debug.WriteLine("Not authenticated");
                NotifyPropertyChanged("Info");
                NotifyPropertyChanged("InfoText");
            }
        }
コード例 #10
0
 public RegisterPage()
 {
     InitializeComponent();
     MvvmNanoIoC.Resolve <IMessenger>().Subscribe <DialogMessage>(this, (object arg1, DialogMessage arg2) =>
     {
         DisplayAlert(arg2.Header, arg2.Text, "ok");
     });
 }
コード例 #11
0
        /// <summary>
        /// Resolves the page that is associated with the given ViewModel.
        /// </summary>
        /// <typeparam name="TViewModel"></typeparam>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private Page ResolvePage <TViewModel>(TViewModel viewModel) where TViewModel : IViewModel
        {
            var view = MvvmNanoIoC.Resolve <IPresenter>().CreateViewFor <TViewModel>();

            view.SetViewModel(viewModel);

            return(view as Page);
        }
コード例 #12
0
        private static void SetupDependencies()
        {
            MvvmNanoIoC.Register <IMessenger, MvvmNano.Forms.MvvmNanoFormsMessenger>();
            MvvmNanoIoC.Register <TutorScoutRestService, TutorScoutRestService>();
            MvvmNanoIoC.RegisterAsSingleton <GeocodeService, GeocodeService>();
            MvvmNanoIoC.RegisterAsSingleton <GeocodeAutocompleteService, GeocodeAutocompleteService>();

            MvvmNanoIoC.Register <CredentialService, CredentialService>();
        }
コード例 #13
0
        public override void Initialize()
        {
            base.Initialize();

            CService = MvvmNanoIoC.Resolve <CredentialService>();

            Info     = IsNotConnected();
            InfoText = "Keine Verbindung zum Internet";
        }
コード例 #14
0
ファイル: TabbedPage.cs プロジェクト: aspnetde/MvvmNano
        private void AddChild <TViewModel, TPage>()
            where TViewModel : MvvmNanoViewModel
            where TPage : Page, IView, new()
        {
            var page = new TPage();

            page.SetViewModel(MvvmNanoIoC.Resolve <TViewModel>());
            Children.Add(page);
        }
コード例 #15
0
        private IViewModel <TNavigationParameter> CreateViewModel <TViewModel, TNavigationParameter>()
        {
            var viewModel = MvvmNanoIoC.Resolve <TViewModel>() as IViewModel <TNavigationParameter>;

            if (viewModel == null)
            {
                throw new MvvmNanoFormsPresenterException($"{typeof(TViewModel)} does not implement IViewModel<{typeof(TNavigationParameter).Name}>");
            }
            return(viewModel);
        }
コード例 #16
0
        public MessageViewModel()
        {
            _themeColor = (Color)Application.Current.Resources["MainColor"];


            AddToolBarItem();

            MvvmNanoIoC.Resolve <MessageService>().Subscribe(this);

            Load();
        }
コード例 #17
0
        private static IViewModel CreateViewModel <TViewModel>(Type viewModelType)
        {
            var viewModel = MvvmNanoIoC.Resolve <TViewModel>() as IViewModel;

            if (viewModel == null)
            {
                throw new MvvmNanoFormsPresenterException(viewModelType + " does not implement IViewModel.");
            }

            return(viewModel);
        }
コード例 #18
0
        private static IViewModel <TNavigationParameter> CreateViewModel <TViewModel, TNavigationParameter>(Type viewModelType)
        {
            var viewModel = MvvmNanoIoC.Resolve <TViewModel>() as IViewModel <TNavigationParameter>;

            if (viewModel == null)
            {
                throw new MvvmNanoFormsPresenterException(viewModelType + " does not implement IViewModel<" + typeof(TNavigationParameter).Name + ">");
            }

            return(viewModel);
        }
コード例 #19
0
ファイル: App.xaml.cs プロジェクト: krdmllr/WorkTimer
 private static void SetUpDependencies()
 {
     MvvmNanoIoC.RegisterAsSingleton(CrossLocalNotifications.Current);
     MvvmNanoIoC.RegisterAsSingleton(CrossVibrate.Current);
     MvvmNanoIoC.RegisterAsSingleton(CrossPermissions.Current);
     MvvmNanoIoC.RegisterAsSingleton(CrossGeolocator.Current);
     MvvmNanoIoC.RegisterAsSingleton <ISettingStorage, SettingStorage>();
     MvvmNanoIoC.RegisterAsSingleton <IDataService, DataService>();
     MvvmNanoIoC.RegisterAsSingleton <IWorkManager, WorkManager>();
     MvvmNanoIoC.RegisterAsSingleton <ILocationService, LocationService>();
 }
コード例 #20
0
ファイル: App.xaml.cs プロジェクト: krdmllr/WorkTimer
 private async Task Setup()
 {
     try
     {
         await MvvmNanoIoC.Resolve <ILocationService>().StartService();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
     }
 }
コード例 #21
0
        private IViewModel CreateViewModel <TViewModel>()
        {
            var viewModel = MvvmNanoIoC.Resolve <TViewModel>() as IViewModel;

            if (viewModel == null)
            {
                throw new MvvmNanoFormsPresenterException($"{typeof(TViewModel)} does not implement IViewModel.");
            }

            return(viewModel);
        }
コード例 #22
0
        private void LogIn()
        {
            if (!IsFormValid)
            {
                return;
            }

            MvvmNanoIoC.Resolve <IUserData>().User = new User(Username);

            NavigateTo <MasterViewModel>();
        }
コード例 #23
0
        public ProfileViewModel()
        {
            _themeColor = (Color)Application.Current.Resources["MainColor"];

            GetMyUserInfo();

            var CService = MvvmNanoIoC.Resolve <CredentialService>();

            PasswordWasSaved = CService.DoCredentialsExist();

            var master = (MasterDetailPage)Application.Current.MainPage;

            _EditSwitch = new ToolbarItem
            {
                Text = "\uf044"
            };

            _logout = new ToolbarItem
            {
                Text = "\uf08b"
            };

            _logout.Clicked += (sender, e) =>
            {
                ((ToolbarItem)sender).IsEnabled = false;
                RemovePass();
            };


            _EditSwitch.Clicked += async(sender, e) =>
            {
                if (!EditMode)
                {
                    _EditSwitch.Text = "\uf00c";
                }
                else
                {
                    _EditSwitch.Text = "\uf044";
                    NotifyPropertyChanged("UserInfo");
                    var updateUser = new UpdateProfile();
                    updateUser.firstName     = _userInfo.firstName;
                    updateUser.lastName      = _userInfo.lastName;
                    updateUser.gender        = _userInfo.gender;
                    updateUser.note          = _userInfo.description;
                    updateUser.email         = _userInfo.email != OldUserData.email ? _userInfo.email : null;
                    updateUser.maxGraduation = _userInfo.maxGraduation;
                    await MvvmNanoIoC.Resolve <TutorScoutRestService>().UpdateUser(updateUser);
                }
                EditMode = !EditMode;
                ViewMode = !EditMode;
            };

            AddToolBarItem();
        }
コード例 #24
0
ファイル: App.cs プロジェクト: iamvignesh/MvvmNano
        private void SetUpMainPage()
        {
            var viewModel = MvvmNanoIoC.Resolve <LoginViewModel>();

            viewModel.Initialize();

            var page = new LoginPage();

            page.SetViewModel(viewModel);

            MainPage = new MvvmNanoNavigationPage(page);
        }
コード例 #25
0
        ///<summary>
        ///     Send a Message
        /// </summary>
        /// <param name="msg">Message to send</param>
        /// <returns>true if successfull, false otherwise</returns>

        public async Task <bool> SendMessage(SendMessage msg)
        {
            msg.authentication = MvvmNanoIoC.Resolve <Authentication>();
            _restUrl           = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/message/sendMessage";
            var uri     = new Uri(string.Format(_restUrl, string.Empty));
            var json    = JsonConvert.SerializeObject(msg);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = null;

            response = await _client.PostAsync(uri, content);

            return(response.IsSuccessStatusCode);
        }
コード例 #26
0
 /// <summary>
 /// Get Tutorings and subscribe to mode changes
 /// </summary>
 public FeedListViewModel()
 {
     GetTutoringsAsync(MasterDetailViewModel.CurrentMode);
     ThemeColor = (Color)Application.Current.Resources["MainColor"];
     MvvmNanoIoC.Resolve <IMessenger>().Subscribe(this, (object arg1, ChangeModeMessage arg2) =>
     {
         _tut = new ObservableCollection <Tutoring>();
         NotifyPropertyChanged("Tutorings");
         Debug.WriteLine("updateColor");
         ThemeColor = (Color)Application.Current.Resources["MainColor"];
         GetTutoringsAsync(arg2.NewMode);
     });
 }
コード例 #27
0
        /// <summary>
        /// Creates the page for the given <see cref="viewModelType"/>.
        /// </summary>
        /// <param name="viewModelType">View model type of the desired page.</param>
        /// <returns></returns>
        private Page CreatePage(Type viewModelType)
        {
            try
            {
                var viewModel = GetViewModel(viewModelType);
                var view      = MvvmNanoIoC.Resolve <IPresenter>().CreateViewFor(viewModelType);
                view.SetViewModel(viewModel);

                return(view as Page);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }
        }
コード例 #28
0
        ///<summary>
        ///     Deletes a message
        /// </summary>
        /// <param name="messageId">Number of message to delete</param>
        /// <returns>true if successfull, false otherwise</returns>
        public async Task <bool> DeleteMessage(int messageId)
        {
            var dm = new DeleteMessage();

            dm.messageId      = messageId;
            dm.authentication = MvvmNanoIoC.Resolve <Authentication>();
            _restUrl          = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/message/deleteMessage";
            var uri     = new Uri(string.Format(_restUrl, string.Empty));
            var json    = JsonConvert.SerializeObject(dm);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = null;

            response = await _client.PostAsync(uri, content);

            Debug.WriteLine(response.Content.ReadAsStringAsync());
            return(response.IsSuccessStatusCode);
        }
コード例 #29
0
        /// <summary>
        /// Set Title according to mode, subscribe to mode changes to change title later and add toolbaritems
        /// </summary>
        public CreateViewModel()
        {
            _ct        = new CreateTutoring();
            _pageTitle = MasterDetailViewModel.CurrentMode == MasterDetailViewModel.Mode.STUDENT
                ? "Neue Anfrage erstellen"
                : "Neues Angebot erstellen";

            MvvmNanoIoC.Resolve <IMessenger>().Subscribe(this, (object arg1, ChangeModeMessage arg2) =>
            {
                _pageTitle = arg2.NewMode == MasterDetailViewModel.Mode.STUDENT
                    ? "Neue Anfrage erstellen"
                    : "Neues Angebot erstellen";
                NotifyPropertyChanged("PageTitle");
            });

            AddToolBarItem();
        }
コード例 #30
0
        /// <summary>
        ///     Gets Tutorings in ragne of 100000km, maximum 50
        /// </summary>
        /// <returns>List of Tutorings</returns>
        public async Task <List <Tutoring> > GetTutorings()
        {
            Debug.WriteLine("Getting Offers");
            var serv            = LocationService.GetInstance();
            var tutoringRequest = new TutoringRequest
            {
                latitude       = (int)(await serv.GetPosition()).Latitude,
                longitude      = (int)(await serv.GetPosition()).Longitude,
                authentication = MvvmNanoIoC.Resolve <Authentication>(),
                rangeKm        = 100000,
                rowLimit       = 50,
                rowOffset      = 0
            };

            Debug.WriteLine(MvvmNanoIoC.Resolve <Authentication>().userName);
            _restUrl = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/tutoring/";

            //Add corresponding string
            if (MasterDetailViewModel.CurrentMode.Equals(MasterDetailViewModel.Mode.STUDENT))
            {
                _restUrl += "offers";
            }
            else
            {
                _restUrl += "requests";
            }

            var uri  = new Uri(string.Format(_restUrl, string.Empty));
            var json = JsonConvert.SerializeObject(tutoringRequest);

            Debug.WriteLine("JSON Serialized:" + json);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await _client.PostAsync(uri, content);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("Got Offers");
                var rescontent = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <List <Tutoring> >(rescontent));
            }
            Debug.WriteLine(await response.Content.ReadAsStringAsync());
            return(null);
        }