public IActionResult Refresh(string idString) { if (string.IsNullOrWhiteSpace(idString)) { return(new BadRequestObjectResult("The ID is null or Empty.")); } var id = int.Parse(idString); var problem = Context.EulerProblems.Find(id); if (problem == null) { return(new BadRequestObjectResult("No Problem with ID {id} exists yet.")); } var data = ProjectEulerScraper.GetAll(id); problem.Title = data[EulerProblemPart.Title]; problem.Description = data[EulerProblemPart.Description]; problem.PublishDate = DateParser.ParseEulerDate(data[EulerProblemPart.PublishDate]); problem.Difficulty = int.Parse(Regex.Replace(data[EulerProblemPart.Difficulty], @"[^\d]", "")); Warn("Updated Problem: " + problem); return(TrySaveChanges(problem)); }
public IActionResult RefreshAll(bool shouldOverride) { var ping = new Ping(); if (!ProjectEulerScraper.IsAvailable("https://projecteuler.net/").Result) { return(new NotFoundObjectResult("projecteuler.net is not reachable.")); } Warn("Refreshing all problems..."); for (var i = 1;; i++) { if (!ProjectEulerScraper.ProblemExists("https://projecteuler.net/problem=" + i)) { break; } var data = ProjectEulerScraper.GetAll(i); var problem = Context.EulerProblems.Find(i); if (problem == null) { Context.Add(problem = new EulerProblem(i, null, null)); } problem.Title = data[EulerProblemPart.Title]; problem.Description = data[EulerProblemPart.Description]; problem.PublishDate = DateParser.ParseEulerDate(data[EulerProblemPart.PublishDate]); problem.Difficulty = data[EulerProblemPart.Difficulty] == null ? null : (int?)int.Parse( Regex.Replace(data[EulerProblemPart.Difficulty], @"[^\d]", "")); Info($"Problem {i} created: " + problem); } Info("Finished refreshing all problems."); return(TrySaveChanges(Context.EulerProblems)); }