public async Task <WwwFeedback> GetFeedback(WwwContext context, WwwWalk walk, WwwSchool school, WwwClass wwwclass, WwwEntity entity) { WwwFeedback feedback = new WwwFeedback(); feedback.SchoolPosition = (await context.wwwSchools.AsNoTracking().OrderByDescending(o => o.TotalRuns).ToListAsync()).FindIndex(f => f.ID == school.ID) + 1; feedback.SchoolPercentage = MathF.Round(school.TotalRuns * 100 / walk.TotalRuns, 2); feedback.SchoolTotal = MathF.Round(school.TotalRuns, 2); feedback.ClassPosition = (await context.wwwClasses.AsNoTracking().OrderByDescending(o => o.TotalRuns).ToListAsync()).FindIndex(f => f.ID == wwwclass.ID) + 1; feedback.ClassPercentage = MathF.Round(wwwclass.TotalRuns * 100 / walk.TotalRuns, 2); feedback.ClassTotal = MathF.Round(wwwclass.TotalRuns, 2); feedback.EntPosition = (await context.wwwEntities.AsNoTracking().OrderByDescending(o => o.TotalRuns).ToListAsync()).FindIndex(f => f.ID == entity.ID) + 1; feedback.EntPercentage = MathF.Round(entity.TotalRuns * 100 / walk.TotalRuns, 2); feedback.EntTotal = MathF.Round(entity.TotalRuns, 2); var years = await context.wwwClasses.AsNoTracking().Select(s => s.Year).Distinct().ToArrayAsync(); List <KeyValuePair <int, float> > YearList = new List <KeyValuePair <int, float> >(); foreach (var year in years) { float sum = await context.wwwClasses.AsNoTracking().Where(x => x.Year == year).SumAsync(s => s.TotalRuns); YearList.Add(new KeyValuePair <int, float>(year, sum)); if (year == wwwclass.Year) { feedback.YearTotal = sum; } } feedback.YearPosition = YearList.Select(s => s.Value).OrderByDescending(o => o).ToList().FindIndex(f => f == feedback.YearTotal) + 1; feedback.YearPercentage = MathF.Round(feedback.YearTotal * 100 / walk.TotalRuns, 2); return(feedback); }
public async Task <WwwFeedback> Submit(EntityRunFormData formData) { WwwFeedback feedback = null; HttpResponseMessage response = null; if (isAdmin) { isAdmin = false; } try { response = await Http.PostAsJsonAsync <EntityRunFormData>("api/submit", formData); } catch (Exception e) { logger.LogError(e.Message); return(feedback); } if (response.IsSuccessStatusCode) { try { var content = await response.Content.ReadAsStringAsync(); if (!String.IsNullOrEmpty(content)) { feedback = JsonSerializer.Deserialize <WwwFeedback>(content, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); } } catch (Exception e) { logger.LogError(e.Message); } if (feedback.EntPosition == 1337 && feedback.SchoolTotal == 1337) { isAdmin = true; return(null); } } return(feedback); }
private async Task HandleValidSubmit() { badgeClass = "d-none"; badgeInfo = ""; if (String.IsNullOrEmpty(formData.Walk)) { formData.Walk = WwwData.s_walk; } if (String.IsNullOrEmpty(formData.School)) { formData.School = WwwData.s_school; } feedback = await dataService.Submit(formData); if (feedback == null) { if (dataService.isAdmin) { badgeClass = "badge badge-success"; badgeInfo = "Admin mode enabled."; } else { badgeClass = "badge badge-warning"; badgeInfo = "Datenbank Fehler, bitter versuche es später noch einmal."; } } else { if (feedback.EntPosition == -1) { badgeClass = "badge badge-danger"; badgeInfo = "Das eingegebene Passwort stimmt nicht."; formData.Credential = String.Empty; feedback = null; } else if (feedback.EntPosition == -2) { badgeClass = "badge badge-warning"; badgeInfo = "Das Pseudonym ist schon in einer anderen Klasse vergeben."; feedback = null; } else if (feedback.EntPosition < 0) { badgeClass = "badge badge-warning"; badgeInfo = "Datenbank Fehler, bitter versuche es später noch einmal."; feedback = null; } else { badgeClass = "badge badge-success"; badgeInfo = "Der Lauf wurde erfolgreich gespeichert."; formData.Credential = String.Empty; } } var schools = await dataService.GetTableData("school"); if (schools.Any()) { SchoolInfo = schools.First(); } StateHasChanged(); if (feedback != null) { await js.InvokeVoidAsync("Scroll", "map"); } }