public ActionResult <List <POItemDTO> > BuyItem(int id, int amount)
        {
            try
            {
                PetOwner user = GetUser();

                Market        markt = GetMarket();
                MarketListing ml    = GetListingWithID(markt, id);

                int valueOfTransaction = ml.ListingAmount * amount;

                if (valueOfTransaction > user.WalletAmount)
                {
                    throw new Exception("You don't have enough funds for the transaction");
                }

                Item it = ml.BuyItem(amount);

                user.WalletAmount -= valueOfTransaction;
                user.AddItem(it, amount);

                _poc.SaveChanges();

                return(Ok(user.POI.Select(po => new POItemDTO(po)).ToList()));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Error", e.Message);
                return(BadRequest(ModelState));
            }
        }
        public async Task <MarketListing> GetLiveListingDataAsync()
        {
            Uri    uri  = new Uri("http://berlox.com/finance/listz.bin");
            string json = string.Empty;

            byte[] buff = await this.GetWebData(uri, true);

            if (buff != null && buff.Length > 0)
            {
                byte[] key = DataKey.GetCurrentKey();
                json = await Task.Factory.StartNew <string>((Func <string>)(() => Compression.DecompressToString(new SimpleAES(key).Decrypt(buff))));
            }
            MarketListing result = await Task.Factory.StartNew <MarketListing>((Func <MarketListing>)(() => JsonConvert.DeserializeObject <MarketListing>(json)));

            await this.SaveCityListAsync(result);

            return(result);
        }
Beispiel #3
0
        public bool SellSelectedGrid(GridStamp Stamp, long Price, string Description)
        {
            Stamp.GridForSale = true;


            MarketListing NewListing = new MarketListing(Stamp);

            NewListing.SetUserInputs(Description, Price);
            NewListing.Seller = Identity.DisplayName;
            //We will set this into the file. (in the block we will dynamically get palyer name and faction)
            NewListing.SetPlayerData(SteamID, Identity.IdentityId);
            HangarMarketController.SaveNewMarketFile(NewListing);



            //Save player file
            SavePlayerFile();

            HangarMarketController.NewGridOfferListed(NewListing);
            return(true);
        }
 private async Task SaveCityListAsync(MarketListing listing)
 {
     if (listing != null)
     {
         if (listing.Deals != null)
         {
             try
             {
                 string[] cities = listing.Cities == null || listing.Cities.Count <= 0 ? Enumerable.ToArray <string>((IEnumerable <string>)Enumerable.OrderBy <string, string>(Enumerable.Distinct <string>(Enumerable.Select <MarketDeal, string>((IEnumerable <MarketDeal>)listing.Deals, (Func <MarketDeal, string>)(d => d.City))), (Func <string, string>)(x => x))) : listing.Cities.ToArray();
                 if (cities.Length != 0)
                 {
                     string txt = string.Join("\r\n", cities);
                     await this.WriteLocalFileAsync("cities.txt", txt);
                 }
             }
             catch
             {
             }
         }
     }
 }
 public MarketListingDTO(MarketListing list)
 {
     Quantity      = list.Quantity;
     ListingAmount = list.ListingAmount;
     Item          = new ItemDTO(list.Item);
 }