Permalink
Browse files

Restructured the application - moved all data related code to Data pr…

…oject. Moved all WebSite related code into WebApp. Made sure it still compiles and runs fine.
  • Loading branch information...
jkaleta committed Mar 10, 2018
1 parent f6a9fdc commit d32e952227c1f079500856eef2455928e59e2347
Showing with 105 additions and 156 deletions.
  1. +11 −0 Data/Data.csproj
  2. +1 −1 Data/DataContext.cs
  3. 0 { → Data}/Migrations/20180128232859_Initial.Designer.cs
  4. 0 { → Data}/Migrations/20180128232859_Initial.cs
  5. 0 { → Data}/Migrations/MicroBankContextModelSnapshot.cs
  6. +1 −1 Data/{ → Models}/BankAccount.cs
  7. +1 −1 Data/{ → Models}/Customer.cs
  8. +0 −108 Pages/Index.cshtml
  9. +0 −3 Pages/_ViewImports.cshtml
  10. +1 −1 { → WebApp}/Pages/About.cshtml
  11. +1 −1 { → WebApp}/Pages/About.cshtml.cs
  12. +1 −1 { → WebApp}/Pages/Account/Create.cshtml
  13. +2 −1 { → WebApp}/Pages/Account/Create.cshtml.cs
  14. +1 −1 { → WebApp}/Pages/Account/List.cshtml
  15. +2 −1 { → WebApp}/Pages/Account/List.cshtml.cs
  16. +1 −1 { → WebApp}/Pages/Contact.cshtml
  17. +1 −1 { → WebApp}/Pages/Contact.cshtml.cs
  18. +1 −1 { → WebApp}/Pages/Error.cshtml
  19. +1 −1 { → WebApp}/Pages/Error.cshtml.cs
  20. +8 −0 WebApp/Pages/Index.cshtml
  21. +1 −1 { → WebApp}/Pages/Index.cshtml.cs
  22. 0 { → WebApp}/Pages/_Layout.cshtml
  23. 0 { → WebApp}/Pages/_ValidationScriptsPartial.cshtml
  24. +3 −0 WebApp/Pages/_ViewImports.cshtml
  25. 0 { → WebApp}/Pages/_ViewStart.cshtml
  26. 0 { → WebApp}/Program.cs
  27. +31 −13 { → WebApp}/Startup.cs
  28. +9 −5 microbank.csproj → WebApp/WebApp.csproj
  29. 0 { → WebApp}/appsettings.Development.json
  30. 0 { → WebApp}/appsettings.json
  31. 0 { → WebApp}/bundleconfig.json
  32. 0 { → WebApp}/wwwroot/css/site.css
  33. 0 { → WebApp}/wwwroot/css/site.min.css
  34. BIN { → WebApp}/wwwroot/favicon.ico
  35. 0 { → WebApp}/wwwroot/images/banner1.svg
  36. 0 { → WebApp}/wwwroot/images/banner2.svg
  37. 0 { → WebApp}/wwwroot/images/banner3.svg
  38. 0 { → WebApp}/wwwroot/images/banner4.svg
  39. 0 { → WebApp}/wwwroot/js/site.js
  40. 0 { → WebApp}/wwwroot/js/site.min.js
  41. 0 { → WebApp}/wwwroot/lib/bootstrap/.bower.json
  42. 0 { → WebApp}/wwwroot/lib/bootstrap/LICENSE
  43. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css
  44. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css.map
  45. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css.map
  46. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/css/bootstrap.css
  47. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map
  48. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map
  49. BIN { → WebApp}/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
  50. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.svg
  51. BIN { → WebApp}/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf
  52. BIN { → WebApp}/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff
  53. BIN { → WebApp}/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2
  54. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/js/bootstrap.js
  55. 0 { → WebApp}/wwwroot/lib/bootstrap/dist/js/npm.js
  56. 0 { → WebApp}/wwwroot/lib/jquery-validation-unobtrusive/.bower.json
  57. 0 { → WebApp}/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js
  58. 0 { → WebApp}/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js
  59. 0 { → WebApp}/wwwroot/lib/jquery-validation/.bower.json
  60. 0 { → WebApp}/wwwroot/lib/jquery-validation/LICENSE.md
  61. 0 { → WebApp}/wwwroot/lib/jquery-validation/dist/additional-methods.js
  62. 0 { → WebApp}/wwwroot/lib/jquery-validation/dist/jquery.validate.js
  63. 0 { → WebApp}/wwwroot/lib/jquery/.bower.json
  64. 0 { → WebApp}/wwwroot/lib/jquery/LICENSE.txt
  65. 0 { → WebApp}/wwwroot/lib/jquery/dist/jquery.js
  66. 0 { → WebApp}/wwwroot/lib/jquery/dist/jquery.min.map
  67. +27 −13 microbank.sln
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
</ItemGroup>

</Project>
@@ -11,6 +11,6 @@ public MicroBankContext(DbContextOptions options)

// public DbSet<BankAccount> BankAccounts { get; set; }

public DbSet<Customer> Customers {get; set;}
public DbSet<Models.Customer> Customers {get; set;}
}
}
@@ -1,7 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;

namespace microbank.Data
namespace microbank.Data.Models
{
public class BankAccount
{
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace microbank.Data
namespace microbank.Data.Models
{
public class Customer
{

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,5 +1,5 @@
@page
@model AboutModel
@model microbank.WebApp.Pages.AboutModel
@{
ViewData["Title"] = "About";
}
@@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace microbank.Pages
namespace microbank.WebApp.Pages
{
public class AboutModel : PageModel
{
@@ -1,5 +1,5 @@
@page
@model microbank.Pages.Account.CreateModel
@model microbank.WebApp.Pages.Account.CreateModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<html>
@@ -1,9 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using microbank.Data.Models;
using microbank.Data;

namespace microbank.Pages.Account
namespace microbank.WebApp.Pages.Account
{
public class CreateModel : PageModel
{
@@ -1,5 +1,5 @@
@page
@model microbank.Pages.Account.ListModel
@model microbank.WebApp.Pages.Account.ListModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<html>
@@ -2,10 +2,11 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using microbank.Data;
using microbank.Data.Models;
using System.Collections.Generic;
using System.Linq;

namespace microbank.Pages.Account
namespace microbank.WebApp.Pages.Account
{
public class ListModel : PageModel
{
@@ -1,5 +1,5 @@
@page
@model ContactModel
@model microbank.WebApp.Pages.ContactModel
@{
ViewData["Title"] = "Contact";
}
@@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace microbank.Pages
namespace microbank.WebApp.Pages
{
public class ContactModel : PageModel
{
@@ -1,5 +1,5 @@
@page
@model ErrorModel
@model microbank.WebApp.Pages.ErrorModel
@{
ViewData["Title"] = "Error";
}
@@ -5,7 +5,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace microbank.Pages
namespace microbank.WebApp.Pages
{
public class ErrorModel : PageModel
{
@@ -0,0 +1,8 @@
@page
@model microbank.WebApp.Pages.IndexModel
@{
ViewData["Title"] = "Micro Bank";
}



@@ -5,7 +5,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace microbank.Pages
namespace microbank.WebApp.Pages
{
public class IndexModel : PageModel
{
File renamed without changes.
@@ -0,0 +1,3 @@
@using microbank.WebApp
@namespace microbank.WebApp.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
File renamed without changes.
File renamed without changes.
@@ -24,27 +24,27 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
services.AddMvc();

var connectionStringConfig = builder.Build();
var connectionString = connectionStringConfig.GetConnectionString("microbank_connection");
var connectionString = _getConnectionString();

_migrateDatabase(connectionString);

var injectedConnectionString = Environment.GetEnvironmentVariable("SQLSERVER_CONNECTION_STRING");

services.AddMvc();
services.AddDbContext<MicroBankContext>(options => options.UseSqlServer(connectionString));
}

private static void _migrateDatabase(string connectionString)
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlServer(connectionString);
using(var context = new MicroBankContext(optionsBuilder.Options)){
//context.Database.Migrate();
}

services.AddDbContext<MicroBankContext>(options => options.UseSqlServer(injectedConnectionString));
using (var context = new MicroBankContext(optionsBuilder.Options))
{
context.Database.Migrate();
}
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
@@ -60,5 +60,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)

app.UseMvc();
}

private string _getConnectionString(){
// Get connection string from injected env variable
// fallback to the connection string from appconfig
var injectedConnectionString = Environment.GetEnvironmentVariable("SQLSERVER_CONNECTION_STRING");

if(!string.IsNullOrWhiteSpace(injectedConnectionString))
return injectedConnectionString;

var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");

var connectionStringConfig = builder.Build();
var connectionString = connectionStringConfig.GetConnectionString("microbank_connection");

return connectionString;
}
}
}
@@ -1,15 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web" DefaultTargets="Publish">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PublishDir>$(OutDir)_PublishedWebsites\NetCoreWebApp\</PublishDir>
<PublishDir>$(OutDir)..\_PublishedWebsites\NetCoreWebApp\</PublishDir>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
</ItemGroup>
</Project>
<ItemGroup>
<ProjectReference Include="..\Data\Data.csproj" />
</ItemGroup>
</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.

0 comments on commit d32e952

Please sign in to comment.