public KeywordReservationContentViewModel(IInteractionRequestAware viewModel, ReservationItem item) { _reservationService = ServiceLocator.Current.GetInstance <ReservationService>(); Keyword = new ReactiveProperty <string>(item?.KeywordReservation?.Keyword ?? "").AddTo(this); IsRegexMode = new ReactiveProperty <bool>(item?.KeywordReservation?.IsRegex ?? false).AddTo(this); Keyword.SetValidateNotifyError(w => IsRegexMode.Value ? _rgxValidator.Validate(w) : _srValidator.Validate(w)).AddTo(this); RegisterCommand = Keyword.ObserveHasErrors.Select(w => !w).ToReactiveCommand().AddTo(this); RegisterCommand.Subscribe(w => { if (item == null) { _reservationService.InsertKeywordReservation(Keyword.Value, IsRegexMode.Value); } else { item.KeywordReservation.Keyword = Keyword.Value; item.KeywordReservation.IsRegex = IsRegexMode.Value; item.Update(); } viewModel.FinishInteraction.Invoke(); }).AddTo(this); }
public TimeReservationContentViewModel(IInteractionRequestAware viewModel, ReservationItem item) { _reservationService = ServiceLocator.Current.GetInstance <ReservationService>(); StartAt = new ReactiveProperty <string>(item?.StartAt?.ToString() ?? "").AddTo(this); RepetitionType = new ReactiveProperty <EnumWrap <Repetition> >(new EnumWrap <Repetition>(Repetition.None)).AddTo(this); StartAt.SetValidateNotifyError(w => _dtValidator.Validate(w)).AddTo(this); RegisterCommand = StartAt.ObserveHasErrors.Select(w => !w).ToReactiveCommand().AddTo(this); RegisterCommand.Subscribe(w => { if (item == null) { _reservationService.InsertTimeReservaion(DateTime.Parse(StartAt.Value), RepetitionType.Value.EnumValue); } else { item.TimeReservation.StartAt = DateTime.Parse(StartAt.Value); item.Update(); } viewModel.FinishInteraction.Invoke(); }).AddTo(this); }