protected override void OnInitialize()
        {
            base.OnInitialize();

            Promotions = new PromotionPopup(Shell.Config, CurrentCatalogName, Env);
            ParentModel.ObservableForProperty(m => (object)m.FilterByMnn, skipInitial: false)
            .Merge(ParentModel.ObservableForProperty(m => (object)m.CurrentFilter))
            .Merge(ParentModel.ObservableForProperty(m => (object)m.ShowWithoutOffers))
            .Select(_ => RxQuery(LoadCatalogNames))
            .Switch()
            .Subscribe(CatalogNames, CloseCancellation.Token);
            CatalogNames.Subscribe(_ => {
                CurrentCatalogName.Value = CurrentCatalogName.Value
                                           ?? (CatalogNames.Value ?? Enumerable.Empty <CatalogName>()).FirstOrDefault();
            });

            ProducerPromotions = new ProducerPromotionPopup(Shell.Config, CurrentCatalogName, Env);
        }
Ejemplo n.º 2
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            Promotions         = new PromotionPopup(Shell.Config, CurrentCatalog.Select(x => x?.Name), Env);
            ProducerPromotions = new ProducerPromotionPopup(Shell.Config, CurrentCatalog.Select(x => x?.Name), Env);

            OrderWarning = new InlineEditWarning(UiScheduler, Manager);
            CurrentOffer
            .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler)
            .Select(_ => RxQuery(LoadHistoryOrders))
            .Switch()
            .Subscribe(HistoryOrders, CloseCancellation.Token);
            CurrentOffer
            .Where(x => !(x?.StatLoaded).GetValueOrDefault())
            .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler)
            .Select(_ => RxQuery(LoadStat))
            .Switch()
            .Subscribe(x => {
                if (x == null || CurrentOffer.Value == null)
                {
                    return;
                }
                ApplyStat(x);
            }, CloseCancellation.Token);

            CurrentOffer
#if !DEBUG
            .Throttle(Consts.ScrollLoadTimeout)
#endif
            .Select(x => RxQuery(s => {
                if (x == null)
                {
                    return(null);
                }
                if (CurrentCatalog.Value?.Id == x.CatalogId)
                {
                    return(CurrentCatalog.Value);
                }
                var sql = @"select c.*, cn.*, m.*, cn.DescriptionId as Id
from Catalogs c
join CatalogNames cn on cn.Id = c.NameId
left join Mnns m on m.Id = cn.MnnId
where c.Id = ?";
                return(s
                       .Connection.Query <Catalog, CatalogName, Mnn, ProductDescription, Catalog>(sql, (c, cn, m, d) => {
                    c.Name = cn;
                    if (cn != null)
                    {
                        cn.Mnn = m;
                        cn.Description = d;
                    }
                    return c;
                }, new { x.CatalogId }).FirstOrDefault());
            }))
            .Switch()
            .Subscribe(CurrentCatalog, CloseCancellation.Token);

            //изменения в LastEditOffer могут произойти уже после перехода на другое предложение
            //по этому нужно отслеживать изменения в CurrentOffer и LastEditOffer
            var observable = this.ObservableForProperty(m => m.CurrentOffer.Value.OrderCount)
                             .Merge(this.ObservableForProperty(m => m.LastEditOffer.Value.OrderCount))
                             .Throttle(Consts.RefreshOrderStatTimeout, UiScheduler)
                             .Select(e => new Stat(Address));

            OnCloseDisposable.Add(Bus.RegisterMessageSource(observable));
        }