/// <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); }
public TutorialsViewModel() { _themeColor = (Color)Application.Current.Resources["MainColor"]; SetTutorings(); MvvmNanoIoC.Resolve <IMessenger>() .Subscribe(this, (object arg1, ChangeModeMessage arg2) => { SetTutorings(); }); }
/// <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(); }); }
/// <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)); }
public MainPage() { InitializeComponent(); //Manually set view model SetViewModel(MvvmNanoIoC.Resolve <MainViewModel>()); }
/// <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)); }
public HistoryPage() { InitializeComponent(); //Manually set view model SetViewModel(MvvmNanoIoC.Resolve <HistoryViewModel>()); }
private static Page ResolvePage <TViewModel>(TViewModel viewModel) where TViewModel : IViewModel { IView viewFor = MvvmNanoIoC.Resolve <IPresenter>().CreateViewFor <TViewModel>(); viewFor.SetViewModel(viewModel); return(viewFor as Page); }
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"); } }
public RegisterPage() { InitializeComponent(); MvvmNanoIoC.Resolve <IMessenger>().Subscribe <DialogMessage>(this, (object arg1, DialogMessage arg2) => { DisplayAlert(arg2.Header, arg2.Text, "ok"); }); }
/// <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); }
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>(); }
public override void Initialize() { base.Initialize(); CService = MvvmNanoIoC.Resolve <CredentialService>(); Info = IsNotConnected(); InfoText = "Keine Verbindung zum Internet"; }
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); }
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); }
public MessageViewModel() { _themeColor = (Color)Application.Current.Resources["MainColor"]; AddToolBarItem(); MvvmNanoIoC.Resolve <MessageService>().Subscribe(this); Load(); }
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); }
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); }
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>(); }
private async Task Setup() { try { await MvvmNanoIoC.Resolve <ILocationService>().StartService(); } catch (Exception ex) { Debug.WriteLine(ex); } }
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); }
private void LogIn() { if (!IsFormValid) { return; } MvvmNanoIoC.Resolve <IUserData>().User = new User(Username); NavigateTo <MasterViewModel>(); }
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(); }
private void SetUpMainPage() { var viewModel = MvvmNanoIoC.Resolve <LoginViewModel>(); viewModel.Initialize(); var page = new LoginPage(); page.SetViewModel(viewModel); MainPage = new MvvmNanoNavigationPage(page); }
///<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); }
/// <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); }); }
/// <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; } }
///<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); }
/// <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(); }
/// <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); }