public async Task <IActionResult> Submit(SubmissionIndexModel model) { int redirectId = 0; if (ModelState.IsValid && model != null) { var currentUser = await _userManager.GetUserAsync(User).ConfigureAwait(false); var now = DateTime.Now; var newBug = new Bug() { Urgency = _bug.GetUrgencyByName(model.Urgency), Title = model.Title, Owner = _bug.GetTeamByName(model.Team), AssignedTo = model.Developer == null ? null : await _userManager.FindByNameAsync(model.Developer).ConfigureAwait(false), CreatedOn = now, Description = model.Description, LogDetail = _bug.CreateEmptyLog(), ProjectAffected = _bug.GetProjectByName(model.ProjectAffected), Status = _bug.GetStatusByName("Open"), CreatedBy = currentUser }; redirectId = _bug.Add(newBug); } return(LocalRedirect("/Bug/Detail/" + redirectId.ToString())); }
public IActionResult DownStats() { //var newFeed = new Feed { }; string country = string.Empty; int scrAPI_Id = 0; int latitude = 0; int longitude = 0; string flag = string.Empty; string iso3 = string.Empty; string iso2 = string.Empty; int cases = 0; int todayCases = 0; int deaths = 0; int todayDeaths = 0; int recovered = 0; int active = 0; int critical = 0; int casesPerOneMillion = 0; int deathsPerOneMillion = 0; var downloadDate = DateTime.Now; // https://corona.lmao.ninja/countries?sort=country // https://corona.lmao.ninja/all // delete any entries for the downloadDate; only one dataset per day var latest = _bug.GetLatestDownloadDate(); _bug.DeleteByDay(latest); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Url); client.DefaultRequestHeaders.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync(Url).Result; if (response.IsSuccessStatusCode) { // load content in db var results = response.Content.ReadAsAsync <IEnumerable <BugListingModel> >().Result; foreach (var x in results) { var newBug = new Bug(); newBug.Country = x.Country; newBug.ScrAPI_Id = x.ScrAPI_Id; newBug.Lat = x.Lat; newBug.Long = x.Long; newBug.Flag = x.Flag; newBug.Iso3 = x.Iso3; newBug.Iso2 = x.Iso2; newBug.Cases = x.Cases; newBug.TodayCases = x.TodayCases; newBug.Deaths = x.Deaths; newBug.TodayDeaths = x.TodayDeaths; newBug.Recovered = x.Recovered; newBug.Active = x.Active; newBug.Critical = x.Critical; if (x.CasesPerOneMillion.HasValue) { newBug.CasesPerOneMillion = (decimal)x.CasesPerOneMillion; } else { newBug.CasesPerOneMillion = 0; } if (x.DeathsPerOneMillion.HasValue) { newBug.DeathsPerOneMillion = (decimal)x.DeathsPerOneMillion; } else { newBug.DeathsPerOneMillion = 0; } //newBug.DeathsPerOneMillion = (decimal)x.DeathsPerOneMillion; newBug.DownloadDate = downloadDate; _bug.Add(newBug); } } return(RedirectToAction("Index")); }