Beispiel #1
0
        public static async Task <Uri> CreateAuctionAsync(AuctionItems auctionItems)
        {
            using (var db = new LiteDatabase(@"Auctions.db"))
            {
                var items = db.GetCollection <AuctionItems>("auctionitems");

                var record = items.FindById(auctionItems.auctionItemId);

                HttpResponseMessage response = await client1.PostAsJsonAsync("api/bids", items);

                response.EnsureSuccessStatusCode();

                if (ReservePriceCheck(record.auctionItemId))
                {
                    record.CurrentBid = Math.Max(record.CurrentBid, record.maxAutoBidAmountmax);
                }

                if (record.CurrentBid - record.maxAutoBidAmountmax > 1)

                {
                    Logger Log = new Logger();
                    Log.Write(255, "You have been outbid by higher bidder");
                }
                var maxAutoBidAmountmaxCurrent = record.maxAutoBidAmountmax;
                return(response.Headers.Location);
            }
        }
Beispiel #2
0
        private bool IsAlreadyAuctioned(NPC auctioneer, ILootable item)
        {
            if (item == null)
            {
                return(true);
            }

            var itemId = item.EntityId.Low;

            //if (AllowInterFactionAuctions)
            //    return NeutralAuctions.HasItemById(itemId);

            //if (auctioneer.AuctioneerEntry.Auctions.HasItemById(itemId))
            //    return true;

            //switch (auctioneer.AuctioneerEntry.LinkedHouseFaction)
            //{
            //    case AuctionHouseFaction.Alliance:
            //        return NeutralAuctions.HasItemById(itemId) || HordeAuctions.HasItemById(itemId);
            //    case AuctionHouseFaction.Horde:
            //        return NeutralAuctions.HasItemById(itemId) || AllianceAuctions.HasItemById(itemId);
            //    case AuctionHouseFaction.Neutral:
            //        return AllianceAuctions.HasItemById(itemId) || HordeAuctions.HasItemById(itemId);
            //    default:
            //        return true;
            //}
            return(AuctionItems.ContainsKey(itemId));
        }
Beispiel #3
0
        public static async Task RunAsync()
        {
            client1.BaseAddress = new Uri("");

            client1.DefaultRequestHeaders.Accept.Clear();
            client1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            try
            {
                AuctionItems items = new AuctionItems
                {
                    auctionItemId       = 1234,
                    BidderName          = "ABC Dealership",
                    maxAutoBidAmountmax = 9500
                };

                var url = await CreateAuctionAsync(items);

                Console.WriteLine($"Created at {url}");

                items = await GetAuctionAsync(url);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
Beispiel #4
0
 private bool IsAlreadyAuctioned(NPC auctioneer, ILootable item)
 {
     if (item == null)
     {
         return(true);
     }
     return(AuctionItems.ContainsKey(item.EntityId.Low));
 }
Beispiel #5
0
        public async Task <AuctionItems> GetAuctionAsyncTests()

        {
            AuctionItems items      = null;
            var          controller = new ValuesController();
            AuctionItems result     = await controller.GetAuctionAsync((string)items);

            Assert.IsNotNull(result, "error");
            return(result);
        }
Beispiel #6
0
        public async Task <Uri> CreateAuctionAsyncTests()
        {
            var          controller = new ValuesController();
            AuctionItems items      = new AuctionItems
            {
                auctionItemId = 1234, maxAutoBidAmountmax = 9500, BidderName = "ABC DealerShip"
            };
            Uri result = await controller.CreateAuctionAsync(items);

            Assert.AreEqual(result, "success");
            return(result);
        }
Beispiel #7
0
        public ActionResult <AuctionItems> GetAuctionItems(int id)
        {
            var db = new LiteDatabase(@"Auctions.db");

            var collection = db.GetCollection <AuctionItems>("auctionItems");

            AuctionItems auction = collection.FindById(id);


            if (auction != null)
            {
                return(auction);
            }
            return(auction);
        }
Beispiel #8
0
 public ValuesController()
 {
     using (var db = new LiteDatabase(@"Auctions.db"))
     {
         var items       = db.GetCollection <AuctionItems>("auctionitems");
         var auctionlist = new AuctionItems
         {
             auctionItemId = 1234,
             BidderName    = "",
             CurrentBid    = 0,
             reservePrice  = 10450
         };
         items.Insert(auctionlist);
     }
 }
Beispiel #9
0
        public void AuctionSellItem(Character chr, NPC auctioneer, EntityId itemId, uint bid, uint buyout, uint time, uint stackSize)
        {
            if (!DoAuctioneerInteraction(chr, auctioneer))
            {
                return;
            }

            var item = chr.Inventory.GetItem(itemId, false);

            var msg = AuctionCheatChecks(auctioneer, item, bid, time);

            if (msg == AuctionError.Ok)
            {
                // Check that character has enough money to cover the deposit
                var houseFaction = auctioneer.AuctioneerEntry.LinkedHouseFaction;
                var deposit      = GetAuctionDeposit(item, houseFaction, time);
                if (chr.Money < deposit)
                {
                    AuctionHandler.SendAuctionCommandResult(chr.Client, null, AuctionAction.SellItem, AuctionError.NotEnoughMoney);
                    return;
                }

                if (item.Amount > stackSize)
                {
                    item = item.Split((int)stackSize);
                }

                if (item == null)
                {
                    AuctionHandler.SendAuctionCommandResult(chr.Client, null, AuctionAction.SellItem, AuctionError.ItemNotFound);
                    return;
                }


                // Charge the deposit to the character
                chr.Money -= deposit;


                // Create the new Auction and add it to the list.

                var newAuction = new Auction
                {
                    BidderLowId    = 0,
                    BuyoutPrice    = buyout,
                    CurrentBid     = bid,
                    Deposit        = deposit,
                    HouseFaction   = houseFaction,
                    ItemLowId      = item.EntityId.Low,
                    ItemTemplateId = item.Template.Id,
                    OwnerLowId     = chr.EntityId.Low,
                    TimeEnds       = DateTime.Now.AddMinutes(time),
                    IsNew          = true
                };



                //save new auction to database and add item to items container
                RealmServer.IOQueue.AddMessage(new Util.Threading.Message(() =>
                {
                    ItemRecord record  = item.Record;
                    record.IsAuctioned = true;
                    record.Save();
                    auctioneer.AuctioneerEntry.Auctions.AddAuction(
                        newAuction);
                    AuctionItems.Add(newAuction.ItemLowId, record);
                    item.Remove(false);
                    AuctionListOwnerItems(chr, auctioneer);
                }));

                // Send the all-good message
                AuctionHandler.SendAuctionCommandResult(chr.Client, newAuction, AuctionAction.SellItem, AuctionError.Ok);
            }
            else
            {
                AuctionHandler.SendAuctionCommandResult(chr.Client, null, AuctionAction.SellItem, msg);
            }
        }
        private void getListings(string sSort, int iCategory)
        {
            AuctionItems auctionItems = new AuctionItems();

            using (SqlConnection conn = new SqlConnection(Common.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("spListings", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    if (iCategory.Equals(0))
                    {
                        cmd.Parameters.Add(new SqlParameter("@cat_id", DBNull.Value));
                    }
                    else
                    {
                        cmd.Parameters.Add(new SqlParameter("@cat_id", iCategory));
                    }

                    conn.Open();
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            AuctionItem item = new AuctionItem();

                            item.Id          = dr["item_id"].ToString();
                            item.Name        = dr["item_name"].ToString();
                            item.Description = dr["item_description"].ToString();
                            item.DateOpen    = DateTime.Parse(dr["item_date_open"].ToString());
                            item.DateClose   = DateTime.Parse(dr["item_date_close"].ToString());
                            item.Seller      = dr["item_seller"].ToString();
                            item.Location    = dr["item_location"].ToString();
                            if (dr["item_amount"].ToString().Equals(string.Empty))
                            {
                                item.BidAmount = 0;
                            }
                            else
                            {
                                item.BidAmount = decimal.Parse(dr["item_amount"].ToString());
                            }
                            item.Buyer     = dr["item_bidder"].ToString();
                            item.BidNumber = int.Parse(dr["item_bids"].ToString());
                            //item.Category = dr["cat_name"].ToString();
                            auctionItems.Add(item);
                        }
                    }
                }
            }

            if (auctionItems.Count == 0)
            {
                AuctionItem item = new AuctionItem();
                item.Description = "No items listed.";
                auctionItems.Add(item);
                //Response.Write("No items listed.");
            }
            //else
            //{
            //Sort
            if (sSort.Equals("DateClose") ||
                sSort.Equals("Name") ||
                sSort.Equals("Buyer") ||
                sSort.Equals("BidAmount") ||
                sSort.Equals("Category"))
            {
                auctionItems.Sort(sSort, SortOrderEnum.Ascending);
            }
            else
            {
                auctionItems.Sort(sSort, SortOrderEnum.Descending);
            }

            dlListings.DataSource = auctionItems;
            dlListings.DataBind();
            //}
        }