From c1fa8dff0e699eeb182d82c80c6ef650c7812ef6 Mon Sep 17 00:00:00 2001 From: tao Date: Tue, 10 Nov 2020 16:25:47 -0800 Subject: [PATCH 1/2] initial the updates --- BackEndTests/BackEndTests.csproj | 2 +- Web/ApiControllers/MapController.cs | 40 +- Web/Areas/Identity/IdentityHostingStartup.cs | 1 - Web/CmsControllers/CandidatesController.cs | 71 +- Web/CmsControllers/HomeController.cs | 5 +- .../Migrations/20201102214619_M1.Designer.cs | 768 +++++++++++++++++ Web/Data/Migrations/20201102214619_M1.cs | 791 ++++++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 766 +++++++++++++++++ Web/Program.cs | 14 +- Web/Startup.cs | 130 +-- Web/Web.csproj | 32 +- 11 files changed, 2501 insertions(+), 119 deletions(-) create mode 100644 Web/Data/Migrations/20201102214619_M1.Designer.cs create mode 100644 Web/Data/Migrations/20201102214619_M1.cs create mode 100644 Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs diff --git a/BackEndTests/BackEndTests.csproj b/BackEndTests/BackEndTests.csproj index 6f611f3..b547568 100644 --- a/BackEndTests/BackEndTests.csproj +++ b/BackEndTests/BackEndTests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.2 + netcoreapp3.1 false diff --git a/Web/ApiControllers/MapController.cs b/Web/ApiControllers/MapController.cs index e9c0c72..e479a49 100644 --- a/Web/ApiControllers/MapController.cs +++ b/Web/ApiControllers/MapController.cs @@ -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; @@ -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, + ILogger logger) + { + _context = context; + _logger = logger; + + MapConfiguration = mapConfiguration.Value; + + AccessToken = GetAccessToken().GetAwaiter().GetResult(); + } + public static async Task GetAccessToken() { string accessToken = AccessToken; @@ -51,20 +67,11 @@ public static async Task GetAccessToken() catch (KeyVaultErrorException kvee) { // TODO + Debug.WriteLine(kvee.Message); } return accessToken; } - - public MapController(ApplicationDbContext context, IOptions mapConfiguration) - { - _context = context; - - MapConfiguration = mapConfiguration.Value; - - AccessToken = GetAccessToken().GetAwaiter().GetResult(); - } - [HttpGet("{location}")] public async Task> GetClosestLocations(string location) { @@ -77,11 +84,14 @@ public async Task> 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) { diff --git a/Web/Areas/Identity/IdentityHostingStartup.cs b/Web/Areas/Identity/IdentityHostingStartup.cs index 7531fa8..c2b7571 100644 --- a/Web/Areas/Identity/IdentityHostingStartup.cs +++ b/Web/Areas/Identity/IdentityHostingStartup.cs @@ -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; diff --git a/Web/CmsControllers/CandidatesController.cs b/Web/CmsControllers/CandidatesController.cs index b8238f1..bbb79b6 100644 --- a/Web/CmsControllers/CandidatesController.cs +++ b/Web/CmsControllers/CandidatesController.cs @@ -32,14 +32,20 @@ public async Task 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) @@ -67,14 +73,17 @@ public virtual async Task 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) @@ -84,14 +93,17 @@ public virtual async Task 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) @@ -101,14 +113,17 @@ public virtual async Task 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) diff --git a/Web/CmsControllers/HomeController.cs b/Web/CmsControllers/HomeController.cs index afaffe2..095df07 100644 --- a/Web/CmsControllers/HomeController.cs +++ b/Web/CmsControllers/HomeController.cs @@ -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; @@ -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 logger) { _context = context; + _logger = logger; _managedElectionID = _context.StateSingleton.Find(State.STATE_ID).ManagedElectionID; } diff --git a/Web/Data/Migrations/20201102214619_M1.Designer.cs b/Web/Data/Migrations/20201102214619_M1.Designer.cs new file mode 100644 index 0000000..fb0d5e7 --- /dev/null +++ b/Web/Data/Migrations/20201102214619_M1.Designer.cs @@ -0,0 +1,768 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Web.Data; + +namespace Web.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20201102214619_M1")] + partial class M1 + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.4-servicing-10062"); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Web.Models.BallotIssue", b => + { + b.Property("BallotIssueId") + .ValueGeneratedOnAdd(); + + b.Property("BallotIssueTitle"); + + b.Property("Description"); + + b.Property("ElectionId"); + + b.HasKey("BallotIssueId"); + + b.HasIndex("ElectionId"); + + b.ToTable("BallotIssues"); + }); + + modelBuilder.Entity("Web.Models.Candidate", b => + { + b.Property("CandidateId") + .ValueGeneratedOnAdd(); + + b.Property("ElectionId"); + + b.Property("Name"); + + b.Property("OrganizationId"); + + b.Property("Picture"); + + b.HasKey("CandidateId"); + + b.HasIndex("ElectionId"); + + b.HasIndex("OrganizationId"); + + b.ToTable("Candidates"); + }); + + modelBuilder.Entity("Web.Models.CandidateDetail", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("CandidateId"); + + b.Property("Format"); + + b.Property("Lang"); + + b.Property("Text"); + + b.Property("Title"); + + b.HasKey("ID"); + + b.HasIndex("CandidateId"); + + b.ToTable("CandidateDetails"); + }); + + modelBuilder.Entity("Web.Models.CandidateRace", b => + { + b.Property("CandidateRaceId") + .ValueGeneratedOnAdd(); + + b.Property("BallotOrder"); + + b.Property("CandidateId"); + + b.Property("RaceId"); + + b.HasKey("CandidateRaceId"); + + b.HasIndex("CandidateId"); + + b.HasIndex("RaceId"); + + b.ToTable("CandidateRaces"); + }); + + modelBuilder.Entity("Web.Models.Contact", b => + { + b.Property("ContactId") + .ValueGeneratedOnAdd(); + + b.Property("CandidateId"); + + b.Property("ContactMethod"); + + b.Property("ContactValue"); + + b.HasKey("ContactId"); + + b.HasIndex("CandidateId"); + + b.ToTable("Contacts"); + }); + + modelBuilder.Entity("Web.Models.Election", b => + { + b.Property("ElectionId") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("ElectionName"); + + b.Property("EndDate"); + + b.Property("StartDate"); + + b.HasKey("ElectionId"); + + b.ToTable("Elections"); + }); + + modelBuilder.Entity("Web.Models.Image", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Format"); + + b.Property("Placement") + .IsRequired(); + + b.Property("ThemeName") + .IsRequired(); + + b.Property("Type"); + + b.Property("Value") + .IsRequired(); + + b.HasKey("ID"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("Web.Models.IssueOption", b => + { + b.Property("IssueOptionId") + .ValueGeneratedOnAdd(); + + b.Property("BallotIssueId"); + + b.Property("IssueOptionInfo"); + + b.HasKey("IssueOptionId"); + + b.HasIndex("BallotIssueId"); + + b.ToTable("IssueOptions"); + }); + + modelBuilder.Entity("Web.Models.OGAudio", b => + { + b.Property("OGAudioID") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("Description"); + + b.Property("OpenGraphId"); + + b.Property("SecureURL"); + + b.Property("Type"); + + b.HasKey("OGAudioID"); + + b.HasIndex("OpenGraphId"); + + b.ToTable("OGAudio"); + }); + + modelBuilder.Entity("Web.Models.OGImage", b => + { + b.Property("OGImageId") + .ValueGeneratedOnAdd(); + + b.Property("Alt"); + + b.Property("Content"); + + b.Property("Height"); + + b.Property("OpenGraphId"); + + b.Property("SecureURL"); + + b.Property("Type"); + + b.Property("Width"); + + b.HasKey("OGImageId"); + + b.HasIndex("OpenGraphId"); + + b.ToTable("OGImage"); + }); + + modelBuilder.Entity("Web.Models.OGVideo", b => + { + b.Property("OGVideoID") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("Height"); + + b.Property("OpenGraphId"); + + b.Property("SecureURL"); + + b.Property("Type"); + + b.Property("Width"); + + b.HasKey("OGVideoID"); + + b.HasIndex("OpenGraphId"); + + b.ToTable("OGVideo"); + }); + + modelBuilder.Entity("Web.Models.OpenGraph", b => + { + b.Property("OpenGraphId") + .ValueGeneratedOnAdd(); + + b.Property("Determiner"); + + b.Property("Image"); + + b.Property("Locale"); + + b.Property("SiteName"); + + b.Property("Title"); + + b.Property("URL"); + + b.HasKey("OpenGraphId"); + + b.ToTable("OpenGraph"); + }); + + modelBuilder.Entity("Web.Models.Organization", b => + { + b.Property("OrganizationId") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name"); + + b.HasKey("OrganizationId"); + + b.ToTable("Organizations"); + }); + + modelBuilder.Entity("Web.Models.PollingPlace", b => + { + b.Property("PollingPlaceId") + .ValueGeneratedOnAdd(); + + b.Property("Address"); + + b.Property("AdvanceOnly"); + + b.Property("ElectionId"); + + b.Property("Email"); + + b.Property("Latitude"); + + b.Property("LocalArea"); + + b.Property("Longitude"); + + b.Property("ParkingInfo"); + + b.Property("Phone"); + + b.Property("PollingPlaceName"); + + b.Property("PollingStationName"); + + b.Property("WheelchairInfo"); + + b.HasKey("PollingPlaceId"); + + b.HasIndex("ElectionId"); + + b.ToTable("PollingPlaces"); + }); + + modelBuilder.Entity("Web.Models.PollingPlaceDate", b => + { + b.Property("PollingDateId") + .ValueGeneratedOnAdd(); + + b.Property("EndTime"); + + b.Property("PollingDate"); + + b.Property("PollingPlaceId"); + + b.Property("StartTime"); + + b.HasKey("PollingDateId"); + + b.HasIndex("PollingPlaceId"); + + b.ToTable("PollingPlaceDates"); + }); + + modelBuilder.Entity("Web.Models.Race", b => + { + b.Property("RaceId") + .ValueGeneratedOnAdd(); + + b.Property("BallotOrder"); + + b.Property("Description"); + + b.Property("ElectionId"); + + b.Property("NumberNeeded"); + + b.Property("PositionName") + .IsRequired(); + + b.HasKey("RaceId"); + + b.HasIndex("ElectionId"); + + b.ToTable("Races"); + }); + + modelBuilder.Entity("Web.Models.SocialMedia", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("ElectionId"); + + b.Property("Link") + .IsRequired(); + + b.Property("MediaName") + .IsRequired(); + + b.Property("Message"); + + b.HasKey("ID"); + + b.HasIndex("ElectionId"); + + b.ToTable("SocialMedias"); + }); + + modelBuilder.Entity("Web.Models.State", b => + { + b.Property("StateId") + .ValueGeneratedOnAdd(); + + b.Property("ManagedElectionID"); + + b.Property("RunningElectionID"); + + b.HasKey("StateId"); + + b.HasIndex("ManagedElectionID"); + + b.HasIndex("RunningElectionID"); + + b.ToTable("StateSingleton"); + }); + + modelBuilder.Entity("Web.Models.Step", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("ElectionId"); + + b.Property("StepDescription"); + + b.Property("StepNumber"); + + b.Property("StepTitle"); + + b.HasKey("ID"); + + b.ToTable("Steps"); + }); + + modelBuilder.Entity("Web.Models.Theme", b => + { + b.Property("ThemeName") + .ValueGeneratedOnAdd(); + + b.Property("Selected"); + + b.HasKey("ThemeName"); + + b.ToTable("Themes"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.BallotIssue", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.Candidate", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Web.Models.Organization", "Organization") + .WithMany("Candidates") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.CandidateDetail", b => + { + b.HasOne("Web.Models.Candidate", "Candidate") + .WithMany("Details") + .HasForeignKey("CandidateId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.CandidateRace", b => + { + b.HasOne("Web.Models.Candidate", "Candidate") + .WithMany("CandidateRaces") + .HasForeignKey("CandidateId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Web.Models.Race", "Race") + .WithMany("CandidateRaces") + .HasForeignKey("RaceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.Contact", b => + { + b.HasOne("Web.Models.Candidate", "Candidate") + .WithMany("Contacts") + .HasForeignKey("CandidateId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.IssueOption", b => + { + b.HasOne("Web.Models.BallotIssue") + .WithMany("BallotIssueOptions") + .HasForeignKey("BallotIssueId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.OGAudio", b => + { + b.HasOne("Web.Models.OpenGraph", "OpenGraph") + .WithMany("Audios") + .HasForeignKey("OpenGraphId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.OGImage", b => + { + b.HasOne("Web.Models.OpenGraph", "OpenGraph") + .WithMany("Images") + .HasForeignKey("OpenGraphId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.OGVideo", b => + { + b.HasOne("Web.Models.OpenGraph", "OpenGraph") + .WithMany("Videos") + .HasForeignKey("OpenGraphId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.PollingPlace", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.PollingPlaceDate", b => + { + b.HasOne("Web.Models.PollingPlace", "PollingPlace") + .WithMany("PollingPlaceDates") + .HasForeignKey("PollingPlaceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.Race", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.SocialMedia", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.State", b => + { + b.HasOne("Web.Models.Election", "ManagedElection") + .WithMany() + .HasForeignKey("ManagedElectionID") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Web.Models.Election", "RunningElection") + .WithMany() + .HasForeignKey("RunningElectionID") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Web/Data/Migrations/20201102214619_M1.cs b/Web/Data/Migrations/20201102214619_M1.cs new file mode 100644 index 0000000..2f570af --- /dev/null +++ b/Web/Data/Migrations/20201102214619_M1.cs @@ -0,0 +1,791 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Web.Data.Migrations +{ + public partial class M1 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + PasswordHash = table.Column(nullable: true), + SecurityStamp = table.Column(nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false), + TwoFactorEnabled = table.Column(nullable: false), + LockoutEnd = table.Column(nullable: true), + LockoutEnabled = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Elections", + columns: table => new + { + ElectionId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + StartDate = table.Column(nullable: false), + EndDate = table.Column(nullable: false), + ElectionName = table.Column(nullable: true), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Elections", x => x.ElectionId); + }); + + migrationBuilder.CreateTable( + name: "Images", + columns: table => new + { + ID = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ThemeName = table.Column(nullable: false), + Placement = table.Column(nullable: false), + Type = table.Column(nullable: true), + Value = table.Column(nullable: false), + Format = table.Column(nullable: true), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Images", x => x.ID); + }); + + migrationBuilder.CreateTable( + name: "OpenGraph", + columns: table => new + { + OpenGraphId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Title = table.Column(nullable: true), + URL = table.Column(nullable: true), + Image = table.Column(nullable: true), + Determiner = table.Column(nullable: true), + Locale = table.Column(nullable: true), + SiteName = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_OpenGraph", x => x.OpenGraphId); + }); + + migrationBuilder.CreateTable( + name: "Organizations", + columns: table => new + { + OrganizationId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(nullable: true), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Organizations", x => x.OrganizationId); + }); + + migrationBuilder.CreateTable( + name: "Steps", + columns: table => new + { + ID = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ElectionId = table.Column(nullable: false), + StepNumber = table.Column(nullable: false), + StepTitle = table.Column(nullable: true), + StepDescription = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Steps", x => x.ID); + }); + + migrationBuilder.CreateTable( + name: "Themes", + columns: table => new + { + ThemeName = table.Column(nullable: false), + Selected = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Themes", x => x.ThemeName); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + RoleId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(nullable: false), + ProviderKey = table.Column(nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(nullable: false), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(nullable: false), + LoginProvider = table.Column(nullable: false), + Name = table.Column(nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "BallotIssues", + columns: table => new + { + BallotIssueId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ElectionId = table.Column(nullable: false), + BallotIssueTitle = table.Column(nullable: true), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_BallotIssues", x => x.BallotIssueId); + table.ForeignKey( + name: "FK_BallotIssues_Elections_ElectionId", + column: x => x.ElectionId, + principalTable: "Elections", + principalColumn: "ElectionId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PollingPlaces", + columns: table => new + { + PollingPlaceId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ElectionId = table.Column(nullable: false), + PollingPlaceName = table.Column(nullable: true), + PollingStationName = table.Column(nullable: true), + Address = table.Column(nullable: true), + WheelchairInfo = table.Column(nullable: true), + ParkingInfo = table.Column(nullable: true), + Latitude = table.Column(nullable: false), + Longitude = table.Column(nullable: false), + AdvanceOnly = table.Column(nullable: false), + LocalArea = table.Column(nullable: true), + Phone = table.Column(nullable: true), + Email = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PollingPlaces", x => x.PollingPlaceId); + table.ForeignKey( + name: "FK_PollingPlaces_Elections_ElectionId", + column: x => x.ElectionId, + principalTable: "Elections", + principalColumn: "ElectionId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Races", + columns: table => new + { + RaceId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ElectionId = table.Column(nullable: false), + BallotOrder = table.Column(nullable: false), + PositionName = table.Column(nullable: false), + Description = table.Column(nullable: true), + NumberNeeded = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Races", x => x.RaceId); + table.ForeignKey( + name: "FK_Races_Elections_ElectionId", + column: x => x.ElectionId, + principalTable: "Elections", + principalColumn: "ElectionId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SocialMedias", + columns: table => new + { + ID = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ElectionId = table.Column(nullable: false), + MediaName = table.Column(nullable: false), + Message = table.Column(nullable: true), + Link = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SocialMedias", x => x.ID); + table.ForeignKey( + name: "FK_SocialMedias_Elections_ElectionId", + column: x => x.ElectionId, + principalTable: "Elections", + principalColumn: "ElectionId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "StateSingleton", + columns: table => new + { + StateId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + RunningElectionID = table.Column(nullable: false), + ManagedElectionID = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StateSingleton", x => x.StateId); + table.ForeignKey( + name: "FK_StateSingleton_Elections_ManagedElectionID", + column: x => x.ManagedElectionID, + principalTable: "Elections", + principalColumn: "ElectionId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_StateSingleton_Elections_RunningElectionID", + column: x => x.RunningElectionID, + principalTable: "Elections", + principalColumn: "ElectionId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OGAudio", + columns: table => new + { + OGAudioID = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Content = table.Column(nullable: true), + SecureURL = table.Column(nullable: true), + Type = table.Column(nullable: true), + Description = table.Column(nullable: true), + OpenGraphId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OGAudio", x => x.OGAudioID); + table.ForeignKey( + name: "FK_OGAudio_OpenGraph_OpenGraphId", + column: x => x.OpenGraphId, + principalTable: "OpenGraph", + principalColumn: "OpenGraphId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OGImage", + columns: table => new + { + OGImageId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Content = table.Column(nullable: true), + SecureURL = table.Column(nullable: true), + Type = table.Column(nullable: true), + Width = table.Column(nullable: false), + Height = table.Column(nullable: false), + Alt = table.Column(nullable: true), + OpenGraphId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OGImage", x => x.OGImageId); + table.ForeignKey( + name: "FK_OGImage_OpenGraph_OpenGraphId", + column: x => x.OpenGraphId, + principalTable: "OpenGraph", + principalColumn: "OpenGraphId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OGVideo", + columns: table => new + { + OGVideoID = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Content = table.Column(nullable: true), + SecureURL = table.Column(nullable: true), + Type = table.Column(nullable: true), + Width = table.Column(nullable: false), + Height = table.Column(nullable: false), + OpenGraphId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OGVideo", x => x.OGVideoID); + table.ForeignKey( + name: "FK_OGVideo_OpenGraph_OpenGraphId", + column: x => x.OpenGraphId, + principalTable: "OpenGraph", + principalColumn: "OpenGraphId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Candidates", + columns: table => new + { + CandidateId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ElectionId = table.Column(nullable: false), + Name = table.Column(nullable: true), + Picture = table.Column(nullable: true), + OrganizationId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Candidates", x => x.CandidateId); + table.ForeignKey( + name: "FK_Candidates_Elections_ElectionId", + column: x => x.ElectionId, + principalTable: "Elections", + principalColumn: "ElectionId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Candidates_Organizations_OrganizationId", + column: x => x.OrganizationId, + principalTable: "Organizations", + principalColumn: "OrganizationId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "IssueOptions", + columns: table => new + { + IssueOptionId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + IssueOptionInfo = table.Column(nullable: true), + BallotIssueId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IssueOptions", x => x.IssueOptionId); + table.ForeignKey( + name: "FK_IssueOptions_BallotIssues_BallotIssueId", + column: x => x.BallotIssueId, + principalTable: "BallotIssues", + principalColumn: "BallotIssueId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PollingPlaceDates", + columns: table => new + { + PollingDateId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + PollingPlaceId = table.Column(nullable: false), + PollingDate = table.Column(nullable: false), + StartTime = table.Column(nullable: false), + EndTime = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PollingPlaceDates", x => x.PollingDateId); + table.ForeignKey( + name: "FK_PollingPlaceDates_PollingPlaces_PollingPlaceId", + column: x => x.PollingPlaceId, + principalTable: "PollingPlaces", + principalColumn: "PollingPlaceId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CandidateDetails", + columns: table => new + { + ID = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + CandidateId = table.Column(nullable: false), + Title = table.Column(nullable: true), + Text = table.Column(nullable: true), + Format = table.Column(nullable: false), + Lang = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CandidateDetails", x => x.ID); + table.ForeignKey( + name: "FK_CandidateDetails_Candidates_CandidateId", + column: x => x.CandidateId, + principalTable: "Candidates", + principalColumn: "CandidateId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CandidateRaces", + columns: table => new + { + CandidateRaceId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + CandidateId = table.Column(nullable: false), + RaceId = table.Column(nullable: false), + BallotOrder = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CandidateRaces", x => x.CandidateRaceId); + table.ForeignKey( + name: "FK_CandidateRaces_Candidates_CandidateId", + column: x => x.CandidateId, + principalTable: "Candidates", + principalColumn: "CandidateId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CandidateRaces_Races_RaceId", + column: x => x.RaceId, + principalTable: "Races", + principalColumn: "RaceId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Contacts", + columns: table => new + { + ContactId = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ContactMethod = table.Column(nullable: false), + ContactValue = table.Column(nullable: true), + CandidateId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Contacts", x => x.ContactId); + table.ForeignKey( + name: "FK_Contacts_Candidates_CandidateId", + column: x => x.CandidateId, + principalTable: "Candidates", + principalColumn: "CandidateId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_BallotIssues_ElectionId", + table: "BallotIssues", + column: "ElectionId"); + + migrationBuilder.CreateIndex( + name: "IX_CandidateDetails_CandidateId", + table: "CandidateDetails", + column: "CandidateId"); + + migrationBuilder.CreateIndex( + name: "IX_CandidateRaces_CandidateId", + table: "CandidateRaces", + column: "CandidateId"); + + migrationBuilder.CreateIndex( + name: "IX_CandidateRaces_RaceId", + table: "CandidateRaces", + column: "RaceId"); + + migrationBuilder.CreateIndex( + name: "IX_Candidates_ElectionId", + table: "Candidates", + column: "ElectionId"); + + migrationBuilder.CreateIndex( + name: "IX_Candidates_OrganizationId", + table: "Candidates", + column: "OrganizationId"); + + migrationBuilder.CreateIndex( + name: "IX_Contacts_CandidateId", + table: "Contacts", + column: "CandidateId"); + + migrationBuilder.CreateIndex( + name: "IX_IssueOptions_BallotIssueId", + table: "IssueOptions", + column: "BallotIssueId"); + + migrationBuilder.CreateIndex( + name: "IX_OGAudio_OpenGraphId", + table: "OGAudio", + column: "OpenGraphId"); + + migrationBuilder.CreateIndex( + name: "IX_OGImage_OpenGraphId", + table: "OGImage", + column: "OpenGraphId"); + + migrationBuilder.CreateIndex( + name: "IX_OGVideo_OpenGraphId", + table: "OGVideo", + column: "OpenGraphId"); + + migrationBuilder.CreateIndex( + name: "IX_PollingPlaceDates_PollingPlaceId", + table: "PollingPlaceDates", + column: "PollingPlaceId"); + + migrationBuilder.CreateIndex( + name: "IX_PollingPlaces_ElectionId", + table: "PollingPlaces", + column: "ElectionId"); + + migrationBuilder.CreateIndex( + name: "IX_Races_ElectionId", + table: "Races", + column: "ElectionId"); + + migrationBuilder.CreateIndex( + name: "IX_SocialMedias_ElectionId", + table: "SocialMedias", + column: "ElectionId"); + + migrationBuilder.CreateIndex( + name: "IX_StateSingleton_ManagedElectionID", + table: "StateSingleton", + column: "ManagedElectionID"); + + migrationBuilder.CreateIndex( + name: "IX_StateSingleton_RunningElectionID", + table: "StateSingleton", + column: "RunningElectionID"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "CandidateDetails"); + + migrationBuilder.DropTable( + name: "CandidateRaces"); + + migrationBuilder.DropTable( + name: "Contacts"); + + migrationBuilder.DropTable( + name: "Images"); + + migrationBuilder.DropTable( + name: "IssueOptions"); + + migrationBuilder.DropTable( + name: "OGAudio"); + + migrationBuilder.DropTable( + name: "OGImage"); + + migrationBuilder.DropTable( + name: "OGVideo"); + + migrationBuilder.DropTable( + name: "PollingPlaceDates"); + + migrationBuilder.DropTable( + name: "SocialMedias"); + + migrationBuilder.DropTable( + name: "StateSingleton"); + + migrationBuilder.DropTable( + name: "Steps"); + + migrationBuilder.DropTable( + name: "Themes"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + + migrationBuilder.DropTable( + name: "Races"); + + migrationBuilder.DropTable( + name: "Candidates"); + + migrationBuilder.DropTable( + name: "BallotIssues"); + + migrationBuilder.DropTable( + name: "OpenGraph"); + + migrationBuilder.DropTable( + name: "PollingPlaces"); + + migrationBuilder.DropTable( + name: "Organizations"); + + migrationBuilder.DropTable( + name: "Elections"); + } + } +} diff --git a/Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..303ff15 --- /dev/null +++ b/Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,766 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Web.Data; + +namespace Web.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.4-servicing-10062"); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Web.Models.BallotIssue", b => + { + b.Property("BallotIssueId") + .ValueGeneratedOnAdd(); + + b.Property("BallotIssueTitle"); + + b.Property("Description"); + + b.Property("ElectionId"); + + b.HasKey("BallotIssueId"); + + b.HasIndex("ElectionId"); + + b.ToTable("BallotIssues"); + }); + + modelBuilder.Entity("Web.Models.Candidate", b => + { + b.Property("CandidateId") + .ValueGeneratedOnAdd(); + + b.Property("ElectionId"); + + b.Property("Name"); + + b.Property("OrganizationId"); + + b.Property("Picture"); + + b.HasKey("CandidateId"); + + b.HasIndex("ElectionId"); + + b.HasIndex("OrganizationId"); + + b.ToTable("Candidates"); + }); + + modelBuilder.Entity("Web.Models.CandidateDetail", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("CandidateId"); + + b.Property("Format"); + + b.Property("Lang"); + + b.Property("Text"); + + b.Property("Title"); + + b.HasKey("ID"); + + b.HasIndex("CandidateId"); + + b.ToTable("CandidateDetails"); + }); + + modelBuilder.Entity("Web.Models.CandidateRace", b => + { + b.Property("CandidateRaceId") + .ValueGeneratedOnAdd(); + + b.Property("BallotOrder"); + + b.Property("CandidateId"); + + b.Property("RaceId"); + + b.HasKey("CandidateRaceId"); + + b.HasIndex("CandidateId"); + + b.HasIndex("RaceId"); + + b.ToTable("CandidateRaces"); + }); + + modelBuilder.Entity("Web.Models.Contact", b => + { + b.Property("ContactId") + .ValueGeneratedOnAdd(); + + b.Property("CandidateId"); + + b.Property("ContactMethod"); + + b.Property("ContactValue"); + + b.HasKey("ContactId"); + + b.HasIndex("CandidateId"); + + b.ToTable("Contacts"); + }); + + modelBuilder.Entity("Web.Models.Election", b => + { + b.Property("ElectionId") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("ElectionName"); + + b.Property("EndDate"); + + b.Property("StartDate"); + + b.HasKey("ElectionId"); + + b.ToTable("Elections"); + }); + + modelBuilder.Entity("Web.Models.Image", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Format"); + + b.Property("Placement") + .IsRequired(); + + b.Property("ThemeName") + .IsRequired(); + + b.Property("Type"); + + b.Property("Value") + .IsRequired(); + + b.HasKey("ID"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("Web.Models.IssueOption", b => + { + b.Property("IssueOptionId") + .ValueGeneratedOnAdd(); + + b.Property("BallotIssueId"); + + b.Property("IssueOptionInfo"); + + b.HasKey("IssueOptionId"); + + b.HasIndex("BallotIssueId"); + + b.ToTable("IssueOptions"); + }); + + modelBuilder.Entity("Web.Models.OGAudio", b => + { + b.Property("OGAudioID") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("Description"); + + b.Property("OpenGraphId"); + + b.Property("SecureURL"); + + b.Property("Type"); + + b.HasKey("OGAudioID"); + + b.HasIndex("OpenGraphId"); + + b.ToTable("OGAudio"); + }); + + modelBuilder.Entity("Web.Models.OGImage", b => + { + b.Property("OGImageId") + .ValueGeneratedOnAdd(); + + b.Property("Alt"); + + b.Property("Content"); + + b.Property("Height"); + + b.Property("OpenGraphId"); + + b.Property("SecureURL"); + + b.Property("Type"); + + b.Property("Width"); + + b.HasKey("OGImageId"); + + b.HasIndex("OpenGraphId"); + + b.ToTable("OGImage"); + }); + + modelBuilder.Entity("Web.Models.OGVideo", b => + { + b.Property("OGVideoID") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("Height"); + + b.Property("OpenGraphId"); + + b.Property("SecureURL"); + + b.Property("Type"); + + b.Property("Width"); + + b.HasKey("OGVideoID"); + + b.HasIndex("OpenGraphId"); + + b.ToTable("OGVideo"); + }); + + modelBuilder.Entity("Web.Models.OpenGraph", b => + { + b.Property("OpenGraphId") + .ValueGeneratedOnAdd(); + + b.Property("Determiner"); + + b.Property("Image"); + + b.Property("Locale"); + + b.Property("SiteName"); + + b.Property("Title"); + + b.Property("URL"); + + b.HasKey("OpenGraphId"); + + b.ToTable("OpenGraph"); + }); + + modelBuilder.Entity("Web.Models.Organization", b => + { + b.Property("OrganizationId") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name"); + + b.HasKey("OrganizationId"); + + b.ToTable("Organizations"); + }); + + modelBuilder.Entity("Web.Models.PollingPlace", b => + { + b.Property("PollingPlaceId") + .ValueGeneratedOnAdd(); + + b.Property("Address"); + + b.Property("AdvanceOnly"); + + b.Property("ElectionId"); + + b.Property("Email"); + + b.Property("Latitude"); + + b.Property("LocalArea"); + + b.Property("Longitude"); + + b.Property("ParkingInfo"); + + b.Property("Phone"); + + b.Property("PollingPlaceName"); + + b.Property("PollingStationName"); + + b.Property("WheelchairInfo"); + + b.HasKey("PollingPlaceId"); + + b.HasIndex("ElectionId"); + + b.ToTable("PollingPlaces"); + }); + + modelBuilder.Entity("Web.Models.PollingPlaceDate", b => + { + b.Property("PollingDateId") + .ValueGeneratedOnAdd(); + + b.Property("EndTime"); + + b.Property("PollingDate"); + + b.Property("PollingPlaceId"); + + b.Property("StartTime"); + + b.HasKey("PollingDateId"); + + b.HasIndex("PollingPlaceId"); + + b.ToTable("PollingPlaceDates"); + }); + + modelBuilder.Entity("Web.Models.Race", b => + { + b.Property("RaceId") + .ValueGeneratedOnAdd(); + + b.Property("BallotOrder"); + + b.Property("Description"); + + b.Property("ElectionId"); + + b.Property("NumberNeeded"); + + b.Property("PositionName") + .IsRequired(); + + b.HasKey("RaceId"); + + b.HasIndex("ElectionId"); + + b.ToTable("Races"); + }); + + modelBuilder.Entity("Web.Models.SocialMedia", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("ElectionId"); + + b.Property("Link") + .IsRequired(); + + b.Property("MediaName") + .IsRequired(); + + b.Property("Message"); + + b.HasKey("ID"); + + b.HasIndex("ElectionId"); + + b.ToTable("SocialMedias"); + }); + + modelBuilder.Entity("Web.Models.State", b => + { + b.Property("StateId") + .ValueGeneratedOnAdd(); + + b.Property("ManagedElectionID"); + + b.Property("RunningElectionID"); + + b.HasKey("StateId"); + + b.HasIndex("ManagedElectionID"); + + b.HasIndex("RunningElectionID"); + + b.ToTable("StateSingleton"); + }); + + modelBuilder.Entity("Web.Models.Step", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("ElectionId"); + + b.Property("StepDescription"); + + b.Property("StepNumber"); + + b.Property("StepTitle"); + + b.HasKey("ID"); + + b.ToTable("Steps"); + }); + + modelBuilder.Entity("Web.Models.Theme", b => + { + b.Property("ThemeName") + .ValueGeneratedOnAdd(); + + b.Property("Selected"); + + b.HasKey("ThemeName"); + + b.ToTable("Themes"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.BallotIssue", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.Candidate", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Web.Models.Organization", "Organization") + .WithMany("Candidates") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.CandidateDetail", b => + { + b.HasOne("Web.Models.Candidate", "Candidate") + .WithMany("Details") + .HasForeignKey("CandidateId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.CandidateRace", b => + { + b.HasOne("Web.Models.Candidate", "Candidate") + .WithMany("CandidateRaces") + .HasForeignKey("CandidateId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Web.Models.Race", "Race") + .WithMany("CandidateRaces") + .HasForeignKey("RaceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.Contact", b => + { + b.HasOne("Web.Models.Candidate", "Candidate") + .WithMany("Contacts") + .HasForeignKey("CandidateId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.IssueOption", b => + { + b.HasOne("Web.Models.BallotIssue") + .WithMany("BallotIssueOptions") + .HasForeignKey("BallotIssueId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.OGAudio", b => + { + b.HasOne("Web.Models.OpenGraph", "OpenGraph") + .WithMany("Audios") + .HasForeignKey("OpenGraphId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.OGImage", b => + { + b.HasOne("Web.Models.OpenGraph", "OpenGraph") + .WithMany("Images") + .HasForeignKey("OpenGraphId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.OGVideo", b => + { + b.HasOne("Web.Models.OpenGraph", "OpenGraph") + .WithMany("Videos") + .HasForeignKey("OpenGraphId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.PollingPlace", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.PollingPlaceDate", b => + { + b.HasOne("Web.Models.PollingPlace", "PollingPlace") + .WithMany("PollingPlaceDates") + .HasForeignKey("PollingPlaceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.Race", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.SocialMedia", b => + { + b.HasOne("Web.Models.Election", "Election") + .WithMany() + .HasForeignKey("ElectionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Web.Models.State", b => + { + b.HasOne("Web.Models.Election", "ManagedElection") + .WithMany() + .HasForeignKey("ManagedElectionID") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Web.Models.Election", "RunningElection") + .WithMany() + .HasForeignKey("RunningElectionID") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Web/Program.cs b/Web/Program.cs index 44d49e1..119e65a 100644 --- a/Web/Program.cs +++ b/Web/Program.cs @@ -6,19 +6,23 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace Web { - public static class Program + public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } } diff --git a/Web/Startup.cs b/Web/Startup.cs index bccffc5..ab4f187 100644 --- a/Web/Startup.cs +++ b/Web/Startup.cs @@ -2,16 +2,14 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.UI; using Microsoft.AspNetCore.Localization; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Newtonsoft.Json; -using Swashbuckle.AspNetCore.Swagger; using System; using System.Collections.Generic; using System.Globalization; @@ -19,28 +17,37 @@ using Web.ApiControllers; using Web.Data; using Web.Models; +using Microsoft.OpenApi.Models; +using Microsoft.Extensions.Logging; +using System.Diagnostics; namespace Web { public class Startup { - public Startup(IConfiguration configuration) + public IConfiguration _configuration { get; } + public IWebHostEnvironment _hostingEnvironment { get; } + + public Startup(IConfiguration configuration, + IWebHostEnvironment hostingEnvironment) { - Configuration = configuration; + _configuration = configuration; + _hostingEnvironment = hostingEnvironment; } - public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddCors(o => o.AddPolicy("EmailPolicy", builder => + services.AddCors(options => { - builder.AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - })); + options.AddPolicy("EmailPolicy", + builder => builder + .AllowAnyOrigin() + .AllowAnyMethod() + //.AllowCredentials() + .AllowAnyHeader() + ); + }); services.Configure(options => { @@ -49,15 +56,15 @@ public void ConfigureServices(IServiceCollection services) options.MinimumSameSitePolicy = SameSiteMode.None; }); - services.Configure(Configuration.GetSection("EmailConfiguration")); - services.Configure(Configuration.GetSection("MapConfiguration")); + services.Configure(_configuration.GetSection("EmailConfiguration")); + services.Configure(_configuration.GetSection("MapConfiguration")); //Choosing a db service CheckDB check = new CheckDB(); //check for environment variables (described in docs/dbconfig.md) //if variable is not set, grab from appsettings.json - String ConnectionString = check.getConnectionStringEnvVar() ?? Configuration.GetConnectionString("DefaultConnection"); + String ConnectionString = check.getConnectionStringEnvVar() ?? _configuration.GetConnectionString("DefaultConnection"); //if not set just use sqlite String DatabaseType = check.checkType() ?? "sqlite"; @@ -65,11 +72,11 @@ public void ConfigureServices(IServiceCollection services) switch (DatabaseType) { case "mssql": - var host = Configuration["DBHOST"] ?? "172.19.0.1"; - var db = Configuration["DBNAME"] ?? "openvoting"; - var port = Configuration["DBPORT"] ?? "1433"; - var username = Configuration["DBUSERNAME"] ?? "sa"; - var password = Configuration["DBPASSWORD"] ?? "Sql!Expre55"; + var host = _configuration["DBHOST"] ?? "172.19.0.1"; + var db = _configuration["DBNAME"] ?? "openvoting"; + var port = _configuration["DBPORT"] ?? "1433"; + var username = _configuration["DBUSERNAME"] ?? "sa"; + var password = _configuration["DBPASSWORD"] ?? "Sql!Expre55"; string connStr = $"Data Source={host},{port};Integrated Security=False;"; connStr += $"User ID={username};Password={password};Database={db};"; @@ -78,10 +85,10 @@ public void ConfigureServices(IServiceCollection services) options.UseSqlServer(connStr)); break; case "mysql": - host = Configuration["DBHOST"] ?? "localhost"; - port = Configuration["DBPORT"] ?? "3306"; - password = Configuration["DBPASSWORD"] ?? "secret"; - db = Configuration["DBNAME"] ?? "openvoting"; + host = _configuration["DBHOST"] ?? "localhost"; + port = _configuration["DBPORT"] ?? "3306"; + password = _configuration["DBPASSWORD"] ?? "secret"; + db = _configuration["DBNAME"] ?? "openvoting"; services.AddDbContext(options => { options.UseMySql($"server={host}; userid=root; pwd={password};" @@ -94,23 +101,23 @@ public void ConfigureServices(IServiceCollection services) break; } - services.AddIdentity( - option => - { - option.Password.RequireDigit = false; - option.Password.RequiredLength = 6; - option.Password.RequireNonAlphanumeric = false; - option.Password.RequireUppercase = false; - option.Password.RequireLowercase = false; - } - ).AddEntityFrameworkStores() - .AddDefaultTokenProviders() - .AddDefaultUI(UIFramework.Bootstrap4); - + services.AddDefaultIdentity( + options => + { + options.Password.RequireDigit = false; + options.Password.RequiredLength = 6; + options.Password.RequireNonAlphanumeric = false; + options.Password.RequireUppercase = false; + options.Password.RequireLowercase = false; + options.SignIn.RequireConfirmedAccount = false; + }) + .AddRoles() + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new Info + c.SwaggerDoc("v1", new OpenApiInfo { Title = "VotingTool API", Version = "v1", @@ -124,18 +131,23 @@ public void ConfigureServices(IServiceCollection services) opts.ResourcesPath = "Resources"; }); - services.AddMvc() + services.AddControllersWithViews() .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix) .AddDataAnnotationsLocalization() - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddJsonOptions( options => { - options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; - options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); - }); + options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; + options.JsonSerializerOptions.PropertyNamingPolicy = null; + + //options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; + //options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); + } + ); + + services.AddRazorPages(); - services.AddHttpClient(); + // 2.2 services.AddHttpClient(); services.Configure(opts => { @@ -151,7 +163,7 @@ public void ConfigureServices(IServiceCollection services) try { - var local_access_token = Configuration["mapkey"]; + var local_access_token = _configuration["mapkey"]; if (!string.IsNullOrEmpty(local_access_token)) { if (string.IsNullOrEmpty(MapController.AccessToken)) @@ -162,7 +174,7 @@ public void ConfigureServices(IServiceCollection services) } catch (Exception ex) { - + Debug.WriteLine(ex.Message); } } @@ -170,26 +182,27 @@ public void ConfigureServices(IServiceCollection services) public void Configure( IApplicationBuilder app, ApplicationDbContext context, - IHostingEnvironment env) + IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseDatabaseErrorPage(); + } else { app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseCors("EmailPolicy"); app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseCookiePolicy(); + app.UseRouting(); + // 22 app.UseCookiePolicy(); app.UseAuthentication(); + app.UseAuthorization(); app.UseSwagger(); @@ -202,13 +215,22 @@ public void Configure( var options = app.ApplicationServices.GetService>(); app.UseRequestLocalization(options.Value); - app.UseMvc(routes => + // app.UseMvc(routes => + // { + // routes.MapRoute( + // name: "default", + // template: "{controller=Home}/{action=Index}/{id?}"); + // }); + + app.UseEndpoints(endpoints => { - routes.MapRoute( + endpoints.MapControllerRoute( name: "default", - template: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Home}/{action=Index}/{id?}"); + endpoints.MapRazorPages(); }); + context.Database.EnsureCreated(); if (!context.Elections.Any()) diff --git a/Web/Web.csproj b/Web/Web.csproj index 4a5333e..6eb2e2e 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -1,9 +1,9 @@  - netcoreapp2.2 + netcoreapp3.1 aspnet-Web-F4539E3B-43FE-4645-AEED-E60BAA3CD25F - OutOfProcess + 1 @@ -16,19 +16,23 @@ - + - - - - - - - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + From 6cf6d50ea1add71f05da4cf55e83bb81c41a2ada Mon Sep 17 00:00:00 2001 From: tao Date: Thu, 10 Dec 2020 15:07:03 -0800 Subject: [PATCH 2/2] Task62619 - PYV backend cms navigation text --- Web/Views/Candidates/Create.cshtml | 2 +- Web/Views/Elections/Index.cshtml | 2 +- Web/Views/PollingPlaces/Index.cshtml | 2 +- Web/Views/Shared/_Layout.cshtml | 16 ++++++++-------- Web/Views/SocialMedias/Index.cshtml | 2 +- Web/Views/State/Index.cshtml | 2 +- Web/Views/Themes/Index.cshtml | 2 +- Web/Views/UserManagement/Edit.cshtml | 2 +- Web/Views/UserManagement/Index.cshtml | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Web/Views/Candidates/Create.cshtml b/Web/Views/Candidates/Create.cshtml index 95782b2..9b49101 100644 --- a/Web/Views/Candidates/Create.cshtml +++ b/Web/Views/Candidates/Create.cshtml @@ -3,7 +3,7 @@ @inject IViewLocalizer Localizer @{ - ViewData["Title"] = @Localizer["Create New Candidate"]; + ViewData["Title"] = @Localizer["Create candidate"]; }