public Auction ToAuction(IAuctionRepository auctionRepository, bool offersFromDb = true, bool productsFromDb = true)
        {
            List <Offer> offerList;

            if (!offersFromDb)
            {
                offerList = Offers.Select(offerJson => offerJson.ToOffer(auctionRepository)).ToList();
            }
            else
            {
                offerList = auctionRepository.Find(Id).Offers.ToList();
            }

            List <Product> productList;

            if (!productsFromDb)
            {
                productList = Products.Select(productJson => productJson.ToProduct()).ToList();
            }
            else
            {
                productList = auctionRepository.Find(Id).Products.ToList();
            }

            return(new Auction
            {
                Id = Id,
                Products = productList,
                Description = Description,
                Owner = Owner.ToUser(),
                Offers = offerList,
                CreationDate = CreationDate
            });
        }
Exemple #2
0
        private int GetOfferIndex(int id)
        {
            log.Trace($"Getting offer's index {id}");
            int index = Offers.Select(g => g.Id)
                        .ToList()
                        .IndexOf(id);

            return(index == -1 ?
                   OutgoingOffers.Select(g => g.Id)
                   .ToList()
                   .IndexOf(id) :
                   index);
        }
Exemple #3
0
        public void RemoveOffer(int id, bool isOutgoing = false)
        {
            log.Trace($"Removing offer {id}");
            int index = isOutgoing ? OutgoingOffers.Select(e => e.Id)
                        .ToList()
                        .IndexOf(id) : Offers.Select(e => e.Id)
                        .ToList()
                        .IndexOf(id);

            if (index != -1)
            {
                App.Current.Dispatcher.Invoke(() => {
                    var refOffers = (isOutgoing ? OutgoingOffers : Offers);
                    refOffers.RemoveAt(index);

                    if (refOffers.Count < 8)
                    {
                        if (isOutgoing)
                        {
                            if (OverflowOutgoingOffers.Count > 0)
                            {
                                OutgoingOffers.Add(OverflowOutgoingOffers.Dequeue());
                                ReorderOutgoingOffers();
                            }
                        }
                        else
                        {
                            if (OverflowOffers.Count > 0)
                            {
                                Offers.Add(OverflowOffers.Dequeue());
                            }
                        }
                    }

                    UpdateOffers();
                    AppService.Instance.FocusGame();
                });
            }
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            Bus.Listen <string>("db")
            .Where(m => m == "Reload")
            .Subscribe(_ => CatalogOffers?.Clear(), CloseCancellation.Token);

            Offers.Select(v => {
                v = v ?? new List <Offer>();
                if (IsFilterByCatalogName)
                {
                    return(v.GroupBy(g => g.GroupName)
                           .Select(g => new object[] { new GroupHeader(g.Key) }.Concat(g))
                           .SelectMany(o => o)
                           .ToList());
                }
                else
                {
                    return(v.Cast <object>().ToList());
                }
            })
            .Subscribe(DisplayItems);
            CurrentDisplayItem.OfType <Offer>().Subscribe(CurrentOffer);
            CurrentOffer.Subscribe(CurrentDisplayItem);
            //.Skip(1) - пропускаем начальные значения
            CurrentRegion.Cast <Object>().Skip(1)
            .Merge(CurrentFilter.Skip(1))
            .Merge(CurrentProducer.Skip(1))
            .Merge(HideJunk.Select(v => (object)v).Skip(1))
            .Subscribe(_ => Filter());
            DbReloadToken.SelectMany(_ => Env.RxQuery(s => {
                if (IsFilterByCatalogName)
                {
                    var catalogs = s.Query <Catalog>()
                                   .Fetch(c => c.Name)
                                   .Where(c => c.Name == filterCatalogName).ToArray();
                    var ids = catalogs.Select(c => c.Id).ToArray();

                    var result = s.Query <Offer>()
                                 .Where(o => ids.Contains(o.CatalogId))
                                 .Fetch(o => o.Price)
                                 .ToList();
                    result.Each(o => o.GroupName = catalogs.Where(c => c.Id == o.CatalogId)
                                                   .Select(c => c.FullName)
                                                   .FirstOrDefault());
                    return(result);
                }
                else
                {
                    var catalogId = filterCatalog.Id;
                    return(s.Query <Offer>().Where(o => o.CatalogId == catalogId)
                           .Fetch(o => o.Price)
                           .ToList());
                }
            })).CatchSubscribe(x => {
                CatalogOffers = x;
                UpdateFilters();
                Filter(false);
                UpdateOffers(Offers.Value);
                if (x.Count == 0)
                {
                    Manager.Warning("Нет предложений");
                    TryClose();
                }
            }, CloseCancellation);

            UpdateMaxProducers();
        }