public async Task Load()
        {
            using (var client = new HttpClient())
            {
                URLBuilder url = new URLBuilder(_filter, controller);
                url.URL += "&ShowMyOffers=true";
                var request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Get
                };
                request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response = await client.SendAsync(request);

                var contents = await response.Content.ReadAsStringAsync();

                List <BuyOfferDto> result = JsonConvert.DeserializeObject <List <BuyOfferDto> >(contents);
                BuyOffers.Clear();
                foreach (BuyOfferDto bo in result)
                {
                    BuyOfferWrapper boffer = bo.createBuyOffer();
                    BuyOffers.Add(boffer);
                }
            }
        }
Example #2
0
        public override void ParseFromNetworkMessage(NetworkMessage message)
        {
            TypeId = message.ReadUInt16();

            BuyOffers.Capacity = (int)message.ReadUInt32();
            for (uint i = 0; i < BuyOffers.Capacity; ++i)
            {
                BuyOffers.Add(message.ReadMarketOffer((int)MarketOfferType.Buy, TypeId));
            }

            SellOffers.Capacity = (int)message.ReadUInt32();
            for (uint i = 0; i < SellOffers.Capacity; ++i)
            {
                SellOffers.Add(message.ReadMarketOffer((int)MarketOfferType.Sell, TypeId));
            }
        }
        public async Task AddOffer()
        {
            if (_createdOffer.Name == null || _createdOffer.Name == "" || _createdOffer.Product.Name == null || CreatedOffer.Amount <= 0 || CreatedOffer?.Price <= 0)
            {
                ErrorString = (string)Application.Current.FindResource("InvalidBuyOfferError");
                return;
            }
            CreatedOffer.Product.CheckForNull();
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                BuyOfferDto content = createOffer(_createdOffer);
                var         json    = Newtonsoft.Json.JsonConvert.SerializeObject(content);
                URLBuilder  url     = new URLBuilder(controller);
                var         request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Post,
                    Content    = new StringContent(json,
                                                   Encoding.UTF8,
                                                   "application/json")
                };
                request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    BuyOffers.Add(_createdOffer);
                    _createdOffer = BuyOfferWrapper.CreateEmptyBuyOffer(_user);
                }
                else
                {
                    ErrorString = (string)Application.Current.FindResource("InvalidBuyOfferError");
                    return;
                }
            }
            ErrorString = null;
        }