// 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(Dane).State = EntityState.Modified;

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

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

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

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

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            string timeDate = Dane.date;

            string todayDate = DateTime.Now.ToString("yyyy-MM-dd");



            if (Regex.IsMatch(timeDate, @"^\d{4}$|^\d{4}-((0?\d)|(1[012]))-(((0?|[12])\d)|3[01])$", RegexOptions.IgnoreCase))
            {
                if (Int32.Parse(timeDate.Substring(0, 4)) > Int32.Parse(todayDate.Substring(0, 4)))
                {
                    return(RedirectToPage("./Error"));
                }
                else if (Int32.Parse(timeDate.Substring(0, 4)) == Int32.Parse(todayDate.Substring(0, 4)))
                {
                    if (Int32.Parse(timeDate.Substring(5, 2)) > Int32.Parse(todayDate.Substring(5, 2)))
                    {
                        return(RedirectToPage("./Error"));
                    }
                    if (Int32.Parse(timeDate.Substring(5, 2)) == Int32.Parse(todayDate.Substring(5, 2)))
                    {
                        if (Int32.Parse(timeDate.Substring(8, 2)) > Int32.Parse(todayDate.Substring(8, 2)))
                        {
                            return(RedirectToPage("./Error"));
                        }
                    }
                }


                if (Int32.Parse(timeDate.Substring(0, 4)) < 2000)
                {
                    return(RedirectToPage("./Error"));
                }
            }
            else
            {
                return(RedirectToPage("./Error"));
            }



            var ifExists = new List <Dane>();

            ifExists = _context.Dane.Where(x => x.date == timeDate).ToList <Dane>();
            if (ifExists.Count != 0)
            {
                return(RedirectToPage("./Index"));
            }
            else
            {
                string     call       = "http://openexchangerates.org/api/historical/" + timeDate + ".json?app_id=23e326842d4044d1a971b4fb0359c5a3";
                HttpClient httpClient = new HttpClient();
                string     json       = await httpClient.GetStringAsync(call);

                DaneJSON obiektKlasy = JsonConvert.DeserializeObject <DaneJSON>(json);
                Dane.PLN = (float)(Math.Round(Convert.ToDouble(obiektKlasy.rates.PLN), 2));
                Dane.EUR = (float)(Math.Round(Convert.ToDouble(obiektKlasy.rates.EUR), 2));
                //Dane.BTC = obiektKlasy.rates.BTC;
                Dane.BTC       = (float)(Math.Round(Convert.ToDouble(obiektKlasy.rates.EUR), 7));
                Dane.COP       = (float)(Math.Round(Convert.ToDouble(obiektKlasy.rates.COP), 2));
                Dane.timestamp = obiektKlasy.timestamp;
                _context.Dane.Add(Dane);


                await _context.SaveChangesAsync();

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