Beispiel #1
0
        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 RegistrationTypeSelectionPageViewModel(
            INavigationService navigationService,
            IAnalyticService analyticService,
            IFirebaseAuthService authService,
            IUserDialogs dialogs) : base(navigationService)
        {
            Title = "Registration Type";
            analyticService.TrackScreen("registration-type");

            Tradesman = ReactiveCommand.CreateFromTask(async() =>
            {
                await dialogs.AlertAsync("Coming Soon!").ConfigureAwait(false);
                analyticService.TrackTapEvent("register-as-tradesman");

                //await navigationService.NavigateAsync(nameof(TradesmentRegistrationPage)).ConfigureAwait(false);
            });

            Contractor = ReactiveCommand.CreateFromTask(async() =>
            {
                analyticService.TrackTapEvent("register-as-contractor");
                await navigationService.NavigateAsync(
                    nameof(ContractorRegistrationPage),
                    new NavigationParameters {
                    { "user_id", _userId }
                }).ConfigureAwait(false);
            });

            GoBack = ReactiveCommand.CreateFromTask <Unit, Unit>(async _ =>
            {
                var result = await dialogs.ConfirmAsync(
                    new ConfirmConfig
                {
                    Title      = "Cancel Account Creation?",
                    Message    = "Are you sure you want to cancel account creation?  This will discard any information you have entered so far",
                    OkText     = "Yes",
                    CancelText = "No"
                });
                if (result)
                {
                    analyticService.TrackTapEvent("cancel-account-creation");

                    // make sure we log out so the user has to log in again
                    await authService.Logout();

                    await NavigationService.NavigateToLoginPageAsync().ConfigureAwait(false);
                }

                return(Unit.Default);
            });

            NavigatingTo
            .Where(args => args.ContainsKey("user_id"))
            .Select(args => args["user_id"].ToString())
            .BindTo(this, x => x._userId);
        }
 public CoffeeDetailViewModel(ICoffeeService coffeeService)
 {
     NavigatingTo
     .Where(x => x.ContainsKey("Id"))
     .Select(x => x["Id"])
     .Cast <Guid>()
     .SelectMany(coffeeService.Read)
     .Where(x => x != null)
     .ToProperty(this, x => x.Detail, out _detail)
     .DisposeWith(Garbage);
 }
Beispiel #4
0
        public TestNavigationViewModel()
        {
            NavigatedTo
            .ToProperty(this, nameof(NavigatedToParameter), out _navigatedToParameter)
            .DisposeWith(Garbage);

            NavigatedFrom
            .ToProperty(this, nameof(NavigatedFromParameter), out _navigatedFromParameter)
            .DisposeWith(Garbage);

            NavigatingTo
            .ToProperty(this, nameof(NavigatingToParameter), out _navigatingToParameter)
            .DisposeWith(Garbage);
        }
Beispiel #5
0
        public ContractorRegistrationPageViewModel(
            INavigationService navigationService,
            IAnalyticService analyticService) : base(navigationService)
        {
            Title = "Contractor";
            analyticService.TrackScreen(
                "registration-page",
                new Dictionary <string, string>
            {
                { "registration-type", "contractor" }
            });

            // store the fields in an enumerable for easy use later on in this class
            _validatableFields = new IValidity[]
            {
                CompanyName,
                CompanyEmail,
                CompanyUrl,
                AddressLineOne,
                AddressLineTwo,
                City,
                State,
                Zip,
                PrimaryPhone,
                SecondaryPhone,
                SocialNetwork1,
                SocialNetwork2,
                SocialNetwork3,
                PrimaryContact
            };

            AddValidationRules();

            NavigatingTo
            .Where(args => args.ContainsKey("user_id"))
            .Select(args => args["user_id"].ToString())
            .BindTo(this, x => x._userId);

            Next = ReactiveCommand.CreateFromTask(async() =>
            {
                if (!IsValid())
                {
                    return;
                }

                var contractor = new ContractorAccount
                {
                    AccountId    = _userId,
                    EmailAddress = CompanyEmail.Value,
                    CompanyName  = CompanyName.Value,
                    CompanyUrl   = CompanyUrl.Value,

                    //PrimaryContact = PrimaryContact.Value,
                    PhoneNumber = PrimaryPhone.Value,

                    //SecondaryPhoneNumber = SecondaryPhone.Value,
                    //PhysicalAddress = new Models.Address
                    //{
                    //    Address1 = AddressLineOne.Value,
                    //    Address2 = AddressLineTwo.Value,
                    //    City = City.Value,
                    //    State = State.Value,
                    //    PostalCode = Zip.Value
                    //},
                    //SocialNetwork1 = SocialNetwork1.Value,
                    //SocialNetwork2 = SocialNetwork2.Value,
                    //SocialNetwork3 = SocialNetwork3.Value
                };

                // TODO: ...
                await navigationService.NavigateAsync(
                    nameof(TradeSpecialtiesPage),
                    new NavigationParameters {
                    { "account", contractor }
                }).ConfigureAwait(false);
            });
        }
Beispiel #6
0
        public TradeSpecialtiesPageViewModel(
            INavigationService navigationService,
            IUserDialogs dialogService,
            IContainerRegistry containerRegistry,
            IProjectDataStore projectDataStore) : base(navigationService)
        {
            Title = "Trade Specialties";

            SelectAll = ReactiveCommand.Create(() =>
            {
                foreach (var item in Items)
                {
                    item.IsSelected = true;
                }
            });

            SelectNone = ReactiveCommand.Create(() =>
            {
                foreach (var item in Items)
                {
                    item.IsSelected = false;
                }
            });

            Next = ReactiveCommand.CreateFromTask(async() =>
            {
                // if there are no items selected, they can't move on. Must select at least one specialty
                var selectedItems = Items.Where(item => item.IsSelected).Select(item => item.Item);
                if (!selectedItems.Any())
                {
                    await dialogService.AlertAsync(
                        new AlertConfig
                    {
                        Title   = "Error",
                        Message = "You must select at least one trade specialty",
                        OkText  = "OK"
                    }).ConfigureAwait(false);

                    return;
                }

                if (_account is ContractorAccount contractor)
                {
                    contractor.AccountTrades.Clear();
                    contractor.AccountTrades.AddRange(
                        selectedItems.Select(item => new AccountTrade
                    {
                        AccountId = contractor.AccountId,
                        TradeId   = item.TradeId
                    }));
                }

                // TODO: Save the account...
                containerRegistry.RegisterInstance <IUserService>(new UserService(_account));
                await NavigationService.NavigateHomeAsync().ConfigureAwait(false);
            });

            projectDataStore
            .GetTradesAsync()
            .ContinueWith(t =>
            {
                // TODO: Handle failure?
                Items.AddRange(
                    t.Result.Select(
                        specialty => new SelectionViewModel <Trade>(specialty)
                {
                    DisplayValue = specialty.Name
                }));
            });

            NavigatingTo
            .Select(args => (Account)args["account"])
            .Subscribe(user =>
            {
                _account = user;
            });
        }
Beispiel #7
0
        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();
            }
        }