-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
447ca67
commit d5d2c6d
Showing
69 changed files
with
2,032 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.421 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D91A73C3-8F0A-4EC1-B398-A8FD87C3C3A2}" | ||
ProjectSection(SolutionItems) = preProject | ||
Resourcesforarticle.txt = Resourcesforarticle.txt | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAPIDocker", "DataAPIDocker\DataAPIDocker.csproj", "{9FCF1516-5034-4253-8CEB-B4289B932436}" | ||
EndProject | ||
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{D3C94C80-A42C-4533-A2AF-B4BCD87201EF}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9FCF1516-5034-4253-8CEB-B4289B932436}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9FCF1516-5034-4253-8CEB-B4289B932436}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9FCF1516-5034-4253-8CEB-B4289B932436}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9FCF1516-5034-4253-8CEB-B4289B932436}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D3C94C80-A42C-4533-A2AF-B4BCD87201EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D3C94C80-A42C-4533-A2AF-B4BCD87201EF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D3C94C80-A42C-4533-A2AF-B4BCD87201EF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D3C94C80-A42C-4533-A2AF-B4BCD87201EF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {8A015CF4-824E-4190-B064-6ACB2AA63585} | ||
EndGlobalSection | ||
EndGlobal |
106 changes: 106 additions & 0 deletions
106
DataAPI_LocalDB_AzureSQL/DataAPIDocker/Controllers/MagazinesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using DataAPIDocker; | ||
using DataAPIDocker.Models; | ||
|
||
namespace DataAPIDocker.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class MagazinesController : ControllerBase | ||
{ | ||
private readonly MagContext _context; | ||
|
||
public MagazinesController(MagContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// GET: api/Magazines | ||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<Magazine>>> GetMagazine() | ||
{ | ||
return await _context.Magazine.ToListAsync(); | ||
} | ||
|
||
// GET: api/Magazines/5 | ||
[HttpGet("{id}")] | ||
public async Task<ActionResult<Magazine>> GetMagazine(int id) | ||
{ | ||
var magazine = await _context.Magazine.FindAsync(id); | ||
|
||
if (magazine == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return magazine; | ||
} | ||
|
||
// PUT: api/Magazines/5 | ||
[HttpPut("{id}")] | ||
public async Task<IActionResult> PutMagazine(int id, Magazine magazine) | ||
{ | ||
if (id != magazine.MagazineId) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
_context.Entry(magazine).State = EntityState.Modified; | ||
|
||
try | ||
{ | ||
await _context.SaveChangesAsync(); | ||
} | ||
catch (DbUpdateConcurrencyException) | ||
{ | ||
if (!MagazineExists(id)) | ||
{ | ||
return NotFound(); | ||
} | ||
else | ||
{ | ||
throw; | ||
} | ||
} | ||
|
||
return NoContent(); | ||
} | ||
|
||
// POST: api/Magazines | ||
[HttpPost] | ||
public async Task<ActionResult<Magazine>> PostMagazine(Magazine magazine) | ||
{ | ||
_context.Magazine.Add(magazine); | ||
await _context.SaveChangesAsync(); | ||
|
||
return CreatedAtAction("GetMagazine", new { id = magazine.MagazineId }, magazine); | ||
} | ||
|
||
// DELETE: api/Magazines/5 | ||
[HttpDelete("{id}")] | ||
public async Task<ActionResult<Magazine>> DeleteMagazine(int id) | ||
{ | ||
var magazine = await _context.Magazine.FindAsync(id); | ||
if (magazine == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
_context.Magazine.Remove(magazine); | ||
await _context.SaveChangesAsync(); | ||
|
||
return magazine; | ||
} | ||
|
||
private bool MagazineExists(int id) | ||
{ | ||
return _context.Magazine.Any(e => e.MagazineId == id); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
DataAPI_LocalDB_AzureSQL/DataAPIDocker/Controllers/ValuesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace DataAPIDocker.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ValuesController : ControllerBase | ||
{ | ||
// GET api/values | ||
[HttpGet] | ||
public ActionResult<IEnumerable<string>> Get() | ||
{ | ||
return new string[] { "value1", "value2" }; | ||
} | ||
|
||
// GET api/values/5 | ||
[HttpGet("{id}")] | ||
public ActionResult<string> Get(int id) | ||
{ | ||
return "value"; | ||
} | ||
|
||
// POST api/values | ||
[HttpPost] | ||
public void Post([FromBody] string value) | ||
{ | ||
} | ||
|
||
// PUT api/values/5 | ||
[HttpPut("{id}")] | ||
public void Put(int id, [FromBody] string value) | ||
{ | ||
} | ||
|
||
// DELETE api/values/5 | ||
[HttpDelete("{id}")] | ||
public void Delete(int id) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using DataApiDocker; | ||
|
||
namespace DataAPIDocker.Models | ||
{ | ||
public class MagContext : DbContext | ||
{ | ||
public MagContext (DbContextOptions<MagContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Magazine> Magazine { get; set; } | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Magazine>().HasData | ||
( | ||
new Magazine { MagazineId = 1, Name = "BASTA! Magazine" }, | ||
new Magazine { MagazineId = 2, Name = "Docker Magazine" }, | ||
new Magazine { MagazineId = 3, Name = "EFCore Magazine" } | ||
); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
DataAPI_LocalDB_AzureSQL/DataAPIDocker/DataAPIDocker.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.2105168" /> | ||
</ItemGroup> | ||
|
||
</Project> |
13 changes: 13 additions & 0 deletions
13
DataAPI_LocalDB_AzureSQL/DataAPIDocker/DataAPIDocker.csproj.user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ActiveDebugProfile>DataAPIDocker</ActiveDebugProfile> | ||
<NameOfLastUsedPublishProfile>DataAPI20190226031432</NameOfLastUsedPublishProfile> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base | ||
ENV ConnectionStrings__MagsConnectionMssql="Server=tcp:msdnmaglerman.database.windows.net,1433;Initial Catalog=DP0419Mags;Persist Security Info=False;User ID=ENVID;Password=ENVPW;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" | ||
WORKDIR /app | ||
EXPOSE 80 | ||
FROM microsoft/dotnet:2.2-sdk AS build | ||
WORKDIR /src | ||
COPY ["DataAPIDocker/DataAPIDocker.csproj", "DataAPIDocker/"] | ||
RUN dotnet restore "DataAPIDocker/DataAPIDocker.csproj" | ||
COPY . . | ||
WORKDIR "/src/DataAPIDocker" | ||
RUN dotnet build "DataAPIDocker.csproj" -c Release -o /app | ||
|
||
FROM build AS publish | ||
RUN dotnet publish "DataAPIDocker.csproj" -c Release -o /app | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app . | ||
ENTRYPOINT ["dotnet", "DataAPIDocker.dll"] |
31 changes: 31 additions & 0 deletions
31
DataAPI_LocalDB_AzureSQL/DataAPIDocker/ExtensionMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
|
||
namespace DataAPIDocker | ||
{ | ||
public static class ExtensionMethods | ||
{ | ||
public static IWebHost MigrateDatabase<T>(this IWebHost webHost) where T : DbContext | ||
{ | ||
using (var scope = webHost.Services.CreateScope()) | ||
{ | ||
var services = scope.ServiceProvider; | ||
try | ||
{ | ||
var db = services.GetRequiredService<T>(); | ||
db.Database.Migrate(); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
var logger = services.GetRequiredService<ILogger<Program>>(); | ||
logger.LogError(ex, "An error occurred while migrating the database."); | ||
} | ||
} | ||
return webHost; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace DataAPIDocker | ||
|
||
{ | ||
public class Magazine | ||
{ | ||
public int MagazineId { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
DataAPI_LocalDB_AzureSQL/DataAPIDocker/Migrations/20190225192831_initSqlAz.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.