Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditChargingScheduleViewModel"/> class.
        /// </summary>
        ///
        /// <param name="dataStore"> The data store. </param>
        public EditChargingScheduleViewModel(ChargingScheduleDataStore dataStore)
            : base("Edit Charging Schedule")
        {
            this.DataStore = dataStore;

            this.ViewTitle = "EVDC Charging Schedule";

            this.SaveChargingSchedule    = ReactiveCommand.CreateFromTask(this.SaveChargingScheduleAsync).DisposeWith(this.Disposables);
            this.DeleteChargingSchedule  = ReactiveCommand.CreateFromTask <Guid>(this.DeleteChargingScheduleAsync).DisposeWith(this.Disposables);
            this.RefreshChargingSchedule = ReactiveCommand.Create(() =>
            {
                if (this.DataStore.TryGetData <ChargingSchedule>(out var chargingSchedule))
                {
                    this.ChargingSchedule = (ChargingSchedule)chargingSchedule;
                    return(true);
                }

                return(false);
            })
                                           .DisposeWith(this.Disposables);

            this.RecurringScheduleDaysOfWeek = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames;

            if (this.DataStore.TryGetData <ChargingSchedule>(out var chargingSchedule))
            {
                this.ChargingSchedule = (ChargingSchedule)chargingSchedule;
            }
            else
            {
                this.ChargingSchedule = new ChargingSchedule();
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ListChargingScheduleViewModel"/> class.
        /// </summary>
        ///
        /// <param name="dataStore">                     The data store. </param>
        public ListChargingScheduleViewModel(ChargingScheduleDataStore dataStore)
            : base("Charging Schedule List View Model")
        {
            this.IsChargingScheduleListVisible = true;

            this.ChargingSchedules = new ObservableCollection <ChargingSchedule>();

            this.DataStore = dataStore;

            this.RefreshChargingSchedules = ReactiveCommand.CreateFromTask(this.GetChargingSchedulesAsync).DisposeWith(this.Disposables);

            this.NavigateToEditChargingScheduleViewModel = ReactiveCommand.CreateFromObservable <Guid, IRoutableViewModel>(this.EditChargingSchedule).DisposeWith(this.Disposables);

            this.Schedules = new ();
            for (var i = 0; i < 5; i++)
            {
                this.Schedules.Add(new Models.ChargingSchedule {
                    DateTime = DateTime.Today, Range = "150 mi"
                });
            }

            this.WhenAnyValue(vm => vm.Schedules)
            .Select(schedules => schedules.Any())
            .ToPropertyEx(this, vm => vm.IsChargingScheduleListVisible)
            .DisposeWith(this.Disposables);

            this.WhenAnyValue(vm => vm.DateSelected)
            .Subscribe(dateSelected =>
            {
                if (dateSelected.CompareTo(DateTime.Today) == 1)
                {
                    var chargingSchedule = new ChargingSchedule
                    {
                        DateTime = dateSelected,
                    };
                    if (this.DataStore.TryAddData <ChargingSchedule>(chargingSchedule))
                    {
                        this.HostScreen.Router.Navigate
                        .Execute(Locator.Current.GetService <IRoutableViewModel>(nameof(EditChargingScheduleViewModel)))
                        .Subscribe()
                        .DisposeWith(this.Disposables);
                    }
                }
            })
            .DisposeWith(this.Disposables);
        }