Ejemplo n.º 1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            string     call       = "https://openexchangerates.org/api/latest.json?app_id=1c20a8ea81d5429cbf2fdc8fa15816a7";
            HttpClient httpClient = new HttpClient();
            var        json       = await httpClient.GetStringAsync(call);

            Console.WriteLine(json);
            // deserializacja
            var data = JsonConvert.DeserializeObject <ExchangeRateFromApi>(json);

            foreach (var x in data.Rates)
            {
                if (x.Key == SingleCurrencyExchange.nameOfCurrency)
                {
                    SingleCurrencyExchange.timeStamp           = data.timeStamp;
                    SingleCurrencyExchange.exchangeRate        = (double)x.Value;
                    SingleCurrencyExchange.resultOfCalculating = (double)(x.Value * SingleCurrencyExchange.amountToExchange);
                    break;
                }
            }
            _context.SingleCurrencyExchange.Add(SingleCurrencyExchange);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(SingleCurrencyExchange).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SingleCurrencyExchangeExists(SingleCurrencyExchange.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SingleCurrencyExchange = await _context.SingleCurrencyExchange.FindAsync(id);

            if (SingleCurrencyExchange != null)
            {
                _context.SingleCurrencyExchange.Remove(SingleCurrencyExchange);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }