Esempio n. 1
0
        public async Task CompleteAuctionAndGenerateOrder()
        {
            var itemsToBeCompletedQuery = _itemAuctioningRepository.GetAll().Where(i => i.Deadline <= DateTime.Now);
            var random = new Random();

            foreach (var itemAuctioning in itemsToBeCompletedQuery)
            {
                // get bidding
                var bidding = await _biddingRepository.GetAll().Where(b => b.ItemId == itemAuctioning.Id)
                              .OrderByDescending(b => b.CreationTime).FirstOrDefaultAsync();

                if (bidding == null)
                {
                    continue;
                }

                // get buyer and seller
                User buyer = null, seller = null;
                if (bidding.CreatorUserId != null)
                {
                    buyer = await _userRepository.GetAsync(bidding.CreatorUserId.Value);
                }
                if (itemAuctioning.CreatorUserId != null)
                {
                    seller = await _userRepository.GetAsync(itemAuctioning.CreatorUserId.Value);
                }

                // get address
                var address = await _addressRepository.GetAll().Where(a => a.CreatorUserId.Value == buyer.Id && a.IsDefault).FirstOrDefaultAsync();

                // create order
                if (buyer != null && seller != null)
                {
                    var order = new OrderWaitingForPayment
                    {
                        Code = DateTime.Now.Ticks + random.Next(0, 99999).ToString().PadLeft(5, '0'),
                        //AddressId = address.Id,
                        Amount          = bidding.Price,
                        ItemPriceAmount = bidding.Price,
                        BuyerId         = buyer.Id,
                        SellerId        = seller.Id,
                        OrderTime       = DateTime.Now,
                        ItemId          = itemAuctioning.Id
                    };
                    await _orderRepository.InsertAsync(order);
                }

                // change item status
                var itemComplete = new ItemCompleted
                {
                    Id                  = itemAuctioning.Id,
                    Code                = itemAuctioning.Code,
                    PillarId            = itemAuctioning.PillarId,
                    CategoryId          = itemAuctioning.CategoryId,
                    StartPrice          = itemAuctioning.StartPrice,
                    StepPrice           = itemAuctioning.StepPrice,
                    PriceLimit          = itemAuctioning.PriceLimit,
                    StartTime           = itemAuctioning.StartTime,
                    Title               = itemAuctioning.Title,
                    Description         = itemAuctioning.Description,
                    BiddingCount        = itemAuctioning.BiddingCount,
                    HighestBiddingPrice = itemAuctioning.HighestBiddingPrice
                };
                await _itemCompleteRepository.InsertAsync(itemComplete);

                await _itemAuctioningRepository.DeleteAsync(itemAuctioning.Id);
            }
        }
        // Called when the item kills itself after finishing typing the text
        private void OnItemCompleted(EventArgs e)
        {
            EventHandler handler = ItemCompleted;

            ItemCompleted?.Invoke(this, e);
        }
Esempio n. 3
0
        public async Task CompleteAuction(EntityDto <Guid> input)
        {
            // get bidding
            var itemAuctioning = await _itemAuctioningRepository.FirstOrDefaultAsync(input.Id);

            if (itemAuctioning == null)
            {
                throw new UserFriendlyException("此ID的货品不存在");
            }

            var bidding = await _biddingRepository.GetAll().Where(b => b.ItemId == itemAuctioning.Id)
                          .OrderByDescending(b => b.CreationTime).FirstOrDefaultAsync();

            if (bidding == null)
            {
                throw new UserFriendlyException("没有人出价,请手动流拍");
            }


            // get buyer and seller
            User buyer = null, seller = null;

            if (bidding.CreatorUserId != null)
            {
                buyer = await _userRepository.GetAsync(bidding.CreatorUserId.Value);
            }
            if (itemAuctioning.CreatorUserId != null)
            {
                seller = await _userRepository.GetAsync(itemAuctioning.CreatorUserId.Value);
            }

            // get address
            var address = await _addressRepository.GetAll().Where(a => a.CreatorUserId.Value == buyer.Id && a.IsDefault).FirstOrDefaultAsync();

            // create order
            var random = new Random();

            if (buyer != null && seller != null)
            {
                var order = new OrderWaitingForPayment
                {
                    Code            = DateTime.Now.Ticks + random.Next(0, 99999).ToString().PadLeft(5, '0'),
                    BuyerId         = buyer.Id,
                    SellerId        = seller.Id,
                    AddressId       = address.Id,
                    Amount          = bidding.Price,
                    ItemPriceAmount = bidding.Price,
                    OrderTime       = DateTime.Now,
                    ItemId          = itemAuctioning.Id
                };
                await _orderRepository.InsertAsync(order);
            }

            // change item status
            var itemComplete = new ItemCompleted
            {
                Id                  = itemAuctioning.Id,
                Code                = itemAuctioning.Code,
                PillarId            = itemAuctioning.PillarId,
                CategoryId          = itemAuctioning.CategoryId,
                StartPrice          = itemAuctioning.StartPrice,
                StepPrice           = itemAuctioning.StepPrice,
                PriceLimit          = itemAuctioning.PriceLimit,
                StartTime           = itemAuctioning.StartTime,
                Title               = itemAuctioning.Title,
                Description         = itemAuctioning.Description,
                BiddingCount        = itemAuctioning.BiddingCount,
                HighestBiddingPrice = itemAuctioning.HighestBiddingPrice,
                Deadline            = itemAuctioning.Deadline
            };
            await _itemCompletedRepository.InsertAsync(itemComplete);

            await _itemAuctioningRepository.DeleteAsync(itemAuctioning.Id);
        }
Esempio n. 4
0
        void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.UserState is UnpackStatus)
            {
                string message = null;
                if (e.UserState is QueueStarted)
                {
                    message = "Started unpacking items in queue.";
                }
                else if (e.UserState is QueueCompleted)
                {
                    message = "Unpacking of all queued items is completed";
                }
                else if (e.UserState is QueueCanceled)
                {
                    message = "Unpacking canceled";
                }
                else if (e.UserState is QueueProgressChanged)
                {
                    QueueProgressChanged queueProgressChanged = e.UserState as QueueProgressChanged;
                    EditQueueInfo(queueProgressChanged);
                }
                else if (e.UserState is ItemAdded)
                {
                    ItemAdded itemAdded = e.UserState as ItemAdded;
                    SetItemsLeft(itemAdded.ItemsInQueue);
                    message = string.Format("Added item \"{0}\"", GetFileName(itemAdded.Item));
                    EditItemQueueListBox(itemAdded.Item, "Idle");
                }
                else if (e.UserState is ItemStarted)
                {
                    ItemStarted itemStarted = e.UserState as ItemStarted;
                    message = string.Format("Unpacking of item \"{0}\" started", GetFileName(itemStarted.Item));
                    EditItemQueueListBox(itemStarted.Item, "Unpackning (0%)");
                }
                else if (e.UserState is ItemProgressChanged)
                {
                    ItemProgressChanged itemProgressChanged = e.UserState as ItemProgressChanged;
                    EditItemQueueListBox(itemProgressChanged.Item, string.Format("Unpacking ({0}% {1})",
                                                                                 itemProgressChanged.PercentCompleted, ConvertEta(itemProgressChanged.Eta)));
                }
                else if (e.UserState is ItemCompleted)
                {
                    ItemCompleted itemCompleted = e.UserState as ItemCompleted;
                    SetItemsLeft(itemCompleted.ItemsLeftInQueue);
                    message = string.Format("Unpacking of item \"{0}\" completed", GetFileName(itemCompleted.Item));
                    EditItemQueueListBox(itemCompleted.Item, "Completed");
                }
                else if (e.UserState is UnpackerError)
                {
                    UnpackerError unpackerError = e.UserState as UnpackerError;
                    message = string.Format("Error unpacking item: {0}", unpackerError.ErrorMessage);
                    EditItemQueueListBox(unpackerError.Item, string.Format("Error: {0}", unpackerError.ErrorMessage));
                }

                UpdateStatus(message);
            }
            else if (e.UserState is string)
            {
                UpdateUnpackerOutput(e.UserState as string);
            }
        }