public ContactUsPageViewModel( INavigationService navigationService, IAnalyticService analyticService, IUserService userService) : base(navigationService) { Title = "Contact Us"; analyticService.TrackScreen("contact-us-page"); AddValidationRules(); Submit = ReactiveCommand.CreateFromTask( async _ => { if (!IsValid()) { return; } analyticService.TrackTapEvent("submit"); var random = new Random(); await Task.Delay(random.Next(400, 2000)); await NavigationService.GoBackAsync(useModalNavigation: true).ConfigureAwait(false); }); Submit.IsExecuting .StartWith(false) .ToProperty(this, x => x.IsBusy, out _isBusy); NavigatingTo .Take(1) .Subscribe(_ => { Email.Value = userService.AuthenticatedUser.EmailAddress; }); }
public EditProjectPageViewModel( INavigationService navigationService, IUserDialogs dialogService, IAnalyticService analyticService) : base(navigationService) { Title = "New Project"; analyticService.TrackScreen("edit-project-page"); // store the fields in an enumerable for easy use later on in this class _validatableFields = new IValidity[] { ProjectName, //StartStatus, Description, SkillsRequired, PayRate, //PaymentType }; AddValidationRules(); Save = ReactiveCommand.CreateFromTask(async() => { if (!IsValid()) { return; } analyticService.TrackTapEvent("save"); if (_project != null) { // if the product was being edited, map the local fields back to the project and // save it //_project.Name = ProjectName.Value; _project.Description = Description.Value; //_project.SkillsRequired = SkillsRequired.Value; //_project.PaymentRate = decimal.Parse(PayRate.Value); //_project.PaymentType = PaymentType.Value; //switch (StartStatus.Value) //{ // case ProjectStartStatus.ReadyNow: // _project.EstimatedStartDate = DateTime.Today; // break; // case ProjectStartStatus.OneToTwoWeeks: _project.EstimatedStartDate = // DateTime.Today.AddDays(7); break; // case ProjectStartStatus.ThreeToFourWeeks: _project.EstimatedStartDate = // DateTime.Today.AddDays(7 * 3); break; // case ProjectStartStatus.FiveOrMoreWeeks: _project.EstimatedStartDate = // DateTime.Today.AddDays(7 * 5); break; // default: // throw new InvalidOperationException("Invalid start status"); //} // TODO: projectDataStore.Update(_project); } else { // the project was a new project. Save it // TODO: projectDataStore.Save(_project); } // TODO: Return the project in the navigation parameters so we can refresh it in the UI of the calling page. await NavigationService.GoBackAsync(useModalNavigation: true).ConfigureAwait(false); }); Cancel = ReactiveCommand.CreateFromTask(async() => { if (_validatableFields.Any(field => field.IsChanged)) { bool keepEditing = await dialogService.ConfirmAsync( new ConfirmConfig { Title = "Unsaved changes", Message = "Are you sure you want to discard this project?", OkText = "Keep Editing", CancelText = "Discard" }); if (keepEditing) { // the user has chosen the option to continue editing return; } } analyticService.TrackTapEvent("cancel"); // if there are no changes, or the user chooses to discard, go back to the previous screen await NavigationService.GoBackAsync(useModalNavigation: true).ConfigureAwait(false); }); NavigatingTo .Take(1) .Where(args => args.ContainsKey("project")) .Select(args => (Project)args["project"]) .Subscribe(project => { // store the project being edited _project = project; Title = "Edit Project"; // map the project being edited to the local fields //ProjectName.Value = project.Name; //StartStatus.Value = project.StartStatus; Description.Value = project.Description; //SkillsRequired.Value = project.SkillsRequired; //PayRate.Value = project.PaymentRate.ToString(); //PaymentType.Value = project.PaymentType; // accept changes for all fields foreach (var field in _validatableFields) { field.AcceptChanges(); } }); // accept changes so we can determine whether they've been changed later on foreach (var field in _validatableFields) { field.AcceptChanges(); } }