public JsonResult AddFavorite(int reportID) { // see if user already has report favorited var userfavs = _context.Favorites.Where(f => f.UserID == _userManager.GetUserId(User) && f.ReportID == reportID).FirstOrDefault(); if (userfavs == null) { Favorite fav = new Favorite { UserID = _userManager.GetUserId(User), ReportID = reportID }; _context.Favorites.Add(fav); _context.SaveChanges(); } return(Json(new { success = true })); }
public JsonResult RunScraper(int batchSize) { var scraper = UFOScraper.GetSingletonScraper(); scraper.BatchSize = 100; // turn on the scraper if its not already on if (scraper.IsRunning) { return(new JsonResult("{ \"success\":false, msg:\"Scraper is already running!\" }")); } var currentIds = _context.Reports.Select(r => r.ReportId).ToHashSet(); new TaskFactory() .StartNew(() => { try { return(scraper.GetReports(currentIds)); } catch (Exception) { } return(new List <Report>()); }).ContinueWith((result) => { if (result.IsCompletedSuccessfully) { var newReports = result.Result; try { _context.Reports.AddRange(newReports); _context.SaveChanges(); } catch (Exception) { } } }); return(new JsonResult(new { success = true })); }