Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial the updates #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BackEndTests/BackEndTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
40 changes: 25 additions & 15 deletions Web/ApiControllers/MapController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.KeyVault.Models;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
Expand All @@ -21,11 +23,25 @@ namespace Web.ApiControllers
[ApiController]
public class MapController : ControllerBase
{
private readonly ILogger _logger;
private readonly ApplicationDbContext _context;
private readonly HttpClient client = new HttpClient() { BaseAddress = new Uri("https://api.mapbox.com/directions/v5/mapbox/driving/") };
public static string AccessToken { get; set; }
public static MapConfiguration MapConfiguration { get; set; }


public MapController(ApplicationDbContext context,
IOptions<MapConfiguration> mapConfiguration,
ILogger<MapController> logger)
{
_context = context;
_logger = logger;

MapConfiguration = mapConfiguration.Value;

AccessToken = GetAccessToken().GetAwaiter().GetResult();
}

public static async Task<string> GetAccessToken()
{
string accessToken = AccessToken;
Expand All @@ -51,20 +67,11 @@ public static async Task<string> GetAccessToken()
catch (KeyVaultErrorException kvee)
{
// TODO
Debug.WriteLine(kvee.Message);
}

return accessToken;
}

public MapController(ApplicationDbContext context, IOptions<MapConfiguration> mapConfiguration)
{
_context = context;

MapConfiguration = mapConfiguration.Value;

AccessToken = GetAccessToken().GetAwaiter().GetResult();
}

[HttpGet("{location}")]
public async Task<ActionResult<object>> GetClosestLocations(string location)
{
Expand All @@ -77,11 +84,14 @@ public async Task<ActionResult<object>> GetClosestLocations(string location)

var pollingPlaceCoordinate = new GeoCoordinate(latitude, longitude);

var nearestPollingPlaces = _context.PollingPlaces
.Where(pollingPlace => pollingPlace.ElectionId == _context.StateSingleton.First().RunningElectionID)
.OrderBy(pollingPlace => new GeoCoordinate(pollingPlace.Latitude, pollingPlace.Longitude).GetDistanceTo(pollingPlaceCoordinate))
.Take(20)
.ToList();
var nearestPollingPlaces = (
_context.PollingPlaces
.Where(pollingPlace => pollingPlace.ElectionId == _context.StateSingleton.First().RunningElectionID)
.Take(20)
.ToList()
)
.OrderBy(pp => new GeoCoordinate(pp.Latitude, pp.Longitude).GetDistanceTo(pollingPlaceCoordinate))
.Select(cr => cr).ToList();

foreach (var pollingPlace in nearestPollingPlaces)
{
Expand Down
1 change: 0 additions & 1 deletion Web/Areas/Identity/IdentityHostingStartup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down
71 changes: 43 additions & 28 deletions Web/CmsControllers/CandidatesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ public async Task<IActionResult> Index()
.Where(r => r.ElectionId == _managedElectionID)
.OrderBy(r => r.BallotOrder)
.ToListAsync();
var candidateRaces = await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenBy(cr => cr.BallotOrder)

var candidateRaces = (
await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenBy(cr => cr.BallotOrder)
.ToListAsync()
)
.GroupBy(cr => cr.RaceId)
.ToListAsync();
.Select(cr => cr).ToList();


var unlisted = await _context.Candidates
.Include(c => c.Organization)
.Where(c => c.ElectionId == _managedElectionID && c.CandidateRaces.Count == 0)
Expand Down Expand Up @@ -67,14 +73,17 @@ public virtual async Task<IActionResult> GetCandidates(string orderBy)

if ("ballot-order".Equals(orderBy))
{
model.CandidatesByRace = await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenBy(cr => cr.BallotOrder)
model.CandidatesByRace = (
await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenBy(cr => cr.BallotOrder)
.ToListAsync()
)
.GroupBy(cr => cr.RaceId)
.ToListAsync();
.Select(cr => cr).ToList();

model.UnlistedCandidates = await _context.Candidates
.Include(c => c.Organization)
Expand All @@ -84,14 +93,17 @@ public virtual async Task<IActionResult> GetCandidates(string orderBy)
}
else if ("alphabet".Equals(orderBy))
{
model.CandidatesByRace = await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenBy(cr => cr.Candidate.Name)
model.CandidatesByRace = (
await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenBy(cr => cr.Candidate.Name)
.ToListAsync()
)
.GroupBy(cr => cr.RaceId)
.ToListAsync();
.Select(cr => cr).ToList();

model.UnlistedCandidates = await _context.Candidates
.Include(c => c.Organization)
Expand All @@ -101,14 +113,17 @@ public virtual async Task<IActionResult> GetCandidates(string orderBy)
}
else if ("reverse-alphabet".Equals(orderBy))
{
model.CandidatesByRace = await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenByDescending(cr => cr.Candidate.Name)
model.CandidatesByRace = (
await _context.CandidateRaces
.Include(cr => cr.Race)
.Include(cr => cr.Candidate)
.Include(cr => cr.Candidate.Organization)
.Where(cr => cr.Candidate.ElectionId == _managedElectionID)
.OrderBy(cr => cr.RaceId).ThenByDescending(cr => cr.Candidate.Name)
.ToListAsync()
)
.GroupBy(cr => cr.RaceId)
.ToListAsync();
.Select(cr => cr).ToList();

model.UnlistedCandidates = await _context.Candidates
.Include(c => c.Organization)
Expand Down
5 changes: 4 additions & 1 deletion Web/CmsControllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Web.Data;
using Web.Models;
using Web.ViewModels;
Expand All @@ -16,10 +17,12 @@ public class HomeController : Controller
{
private readonly ApplicationDbContext _context;
private readonly int _managedElectionID;
private readonly ILogger _logger;

public HomeController(ApplicationDbContext context)
public HomeController(ApplicationDbContext context, ILogger<HomeController> logger)
{
_context = context;
_logger = logger;
_managedElectionID = _context.StateSingleton.Find(State.STATE_ID).ManagedElectionID;
}

Expand Down
Loading