public async Task <ActionResult <SharePrice> > PostSharePrice(SharePrice sharePrice)
        {
            _context.SharePrice.Add(sharePrice);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSharePrice", new { id = sharePrice.Id }, sharePrice));
        }
        public async Task <IActionResult> PutSharePrice(int id, SharePrice sharePrice)
        {
            if (id != sharePrice.Id)
            {
                return(BadRequest());
            }

            _context.Entry(sharePrice).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SharePriceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
    private SharePrice GetSharePrice(string stock, string exchange)
    {
        var request      = new RestRequest($"shareprice/{exchange}?share={stock}", DataFormat.Json);
        var responseJson = _client.Get(request);
        var content      = responseJson.Content;

        var   sellRegex  = new Regex(".*\"price\":(.*),\"buySell\":\"sell\",\"amount\":(.*)}.*");
        float sellPrice  = float.Parse(sellRegex.Match(content).Groups[1].Value, CultureInfo.InvariantCulture);
        int   sellAmount = int.Parse(sellRegex.Match(content).Groups[2].Value);

        var   buyRegex  = new Regex(".*\"price\":(.*),\"buySell\":\"buy\",\"amount\":(.*)},{.*");
        float buyPrice  = float.Parse(buyRegex.Match(content).Groups[1].Value, CultureInfo.InvariantCulture);
        int   buyAmount = int.Parse(buyRegex.Match(content).Groups[2].Value);

        SharePrice price = new SharePrice()
        {
            SellPrice  = sellPrice,
            SellAmount = sellAmount,
            BuyPrice   = buyPrice,
            BuyAmount  = buyAmount
        };

        return(price);
    }