Пример #1
0
        public ReestrSettingViewModel(
            ModalNavigationStore modalNavigationStore,
            IBarrelStorageDataService barrelStorageDataService,
            IReestrSettingDataService reestrSettingDataService,
            IRecipeDataService recipeDataService,
            ICustomerDataService customerDataService)
        {
            _modalNavigationStore     = modalNavigationStore;
            _barrelStorageDataService = barrelStorageDataService;
            _reestrSettingDataService = reestrSettingDataService;
            _recipeDataService        = recipeDataService;
            _customerDataService      = customerDataService;

            this.WhenAnyValue(x => x.Password)
            .Throttle(TimeSpan.FromSeconds(1))
            .Where(x => !string.IsNullOrWhiteSpace(x))
            .ObserveOnDispatcher()
            .Subscribe(PasswordChecker);

            this.WhenAnyValue(x => x.SelectedRecipe)
            .Skip(1)
            .SelectMany(async(x) => await _barrelStorageDataService.GetLastBarrelNumber(x))
            .ObserveOnDispatcher()
            .Subscribe(number => ReestrSetting.InitialBarrelNumber = number + 1);

            Task.Run(Initialize);
            SubmitCommand = new DelegateCommand(ExecuteSubmitCommand);
            CancelCommand = new DelegateCommand(() => modalNavigationStore.Close());
        }
Пример #2
0
        private async Task Initialize()
        {
            var rs = await _reestrSettingDataService.GetReestrSetting();

            var collection = await _recipeDataService.GetRecipes();

            var customers = await _customerDataService.GetCustomers();

            var barrelNumber = await _barrelStorageDataService.GetLastBarrelNumber(rs.CurrentRecipe);

            RecipesCollection   = new ObservableCollection <Recipe>(collection);
            CustomersCollection = new ObservableCollection <Customer>(customers);
            ReestrSetting       = rs ?? new ReestrSetting();
            SelectedRecipe      = RecipesCollection.FirstOrDefault(x => x.Id == ReestrSetting.RecipeId);
            SelectedCustomer    = CustomersCollection.FirstOrDefault(x => x.Id == ReestrSetting.CustomerId);
            ReestrSetting.InitialBarrelNumber = barrelNumber + 1;
        }