Skip to content

Commit

Permalink
Merge branch 'LiveDevTeam:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
live-dev999 committed Oct 31, 2021
2 parents 082b7f8 + 285e69f commit 25b3043
Show file tree
Hide file tree
Showing 34 changed files with 483 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/ workflows/cgen-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x
dotnet-version: 2.2.x
- name: Restore dependencies
run: dotnet restore
working-directory: src/Services/c-gen
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/c-gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x
dotnet-version: 2.2.x
- name: Restore dependencies
run: dotnet restore
working-directory: src/Services/c-gen
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Url for download https://dotnet.microsoft.com/download/dotnet/2.1
* `test` Commits, that add missing tests or correcting existing tests
* `docs` Commits, that affect documentation only
* `build` Commits, that affect build components like build tool, ci pipeline, dependencies, project version, ...
* `ops` Commits, that affect operational components like infrastructure, deployment, backup, recovery, ...
* `devops` Commits, that affect operational components like infrastructure, deployment, backup, recovery, ...
* `chore` Miscellaneous commits e.g. modifying `.gitignore`

#### Subject
Expand Down
7 changes: 5 additions & 2 deletions src/Database/Prototype/prep-mac.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=your@Password" -e "MSSQL_PID=sql" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest up

# docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=your@Password" -e "MSSQL_PID=sql" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest up
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=your@Password" \
-p 1433:1433 --name sql1 -h sql1 \
-d \
mcr.microsoft.com/mssql/server:2017-latest
8 changes: 7 additions & 1 deletion src/Services/c-gen/O2NextGen.CGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.810.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O2NextGen.CertificateManagement.Web", "O2NextGen.CertificateManagement.Web\O2NextGen.CertificateManagement.Web.csproj", "{EA540B06-8A73-49C7-A799-49423B316458}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O2NextGen.CertificateManagement.Api", "O2NextGen.CertificateManagement.Api\O2NextGen.CertificateManagement.Api.csproj", "{EA540B06-8A73-49C7-A799-49423B316458}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O2NextGen.CertificateManagement.Business", "O2NextGen.CertificateManagement.Business\O2NextGen.CertificateManagement.Business.csproj", "{C6E0B2A5-6349-4C1D-8E14-82249AF8F58A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O2NextGen.CertificateManagement.Impl", "O2NextGen.CertificateManagement.Impl\O2NextGen.CertificateManagement.Impl.csproj", "{01805439-2954-49CE-93D2-5EB06B82146C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{12E83C2A-23C7-4E71-B137-AC56CE28F9E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O2NextGen.CertificateManagement.Data", "O2NextGen.CertificateManagement.Data\O2NextGen.CertificateManagement.Data.csproj", "{B8C8A05D-0D30-40FF-8BDD-B2FBA2ED7AB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,6 +31,10 @@ Global
{01805439-2954-49CE-93D2-5EB06B82146C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01805439-2954-49CE-93D2-5EB06B82146C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01805439-2954-49CE-93D2-5EB06B82146C}.Release|Any CPU.Build.0 = Release|Any CPU
{B8C8A05D-0D30-40FF-8BDD-B2FBA2ED7AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8C8A05D-0D30-40FF-8BDD-B2FBA2ED7AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8C8A05D-0D30-40FF-8BDD-B2FBA2ED7AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8C8A05D-0D30-40FF-8BDD-B2FBA2ED7AB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace O2NextGen.CertificateManagement.Web.Controllers
{
[Route("certificates")]
public class CertificatesController : Controller
public class CertificatesController : ControllerBase
{
#region Fields

Expand All @@ -31,52 +31,47 @@ public CertificatesController(ICertificatesService certificatesService)

[HttpGet]
[Route("")]
public async Task<IActionResult> Index()
public async Task<IActionResult> GetAllAsync()
{
var models = await _certificatesService.GetAllAsync(CancellationToken.None);
if (models == null)
return NotFound();
return View(models.ToViewModel());
return Ok(models.ToViewModel());
}

[HttpGet]
[Route("{id}")]
public async Task<IActionResult> Detail(long id, CancellationToken ct)
public async Task<IActionResult> GetByIdAsync(long id, CancellationToken ct)
{
var certificate = await _certificatesService.GetByIdAsync(id, ct);
if (certificate == null)
return NotFound();
return View(certificate.ToViewModel());
return Ok(certificate.ToViewModel());
}

[HttpPost]
[HttpPut]
[Route("id")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(long id, CertificateViewModel model, CancellationToken ct)
public async Task<IActionResult> UpdateAsync(long id, CertificateViewModel model, CancellationToken ct)
{
var certificate = await _certificatesService.UpdateAsync(model.ToModel(), ct);
if (certificate == null)
return NotFound();
certificate.Name = model.Name;

return RedirectToAction("Index");
}

[HttpGet]
[Route("create")]
public IActionResult Create()
{
return View();
return Ok(certificate.ToViewModel());
}

[HttpPost]
[HttpPut]
[Route("")]
public async Task<IActionResult> CreateReally(CertificateViewModel model, CancellationToken ct)
public async Task<IActionResult> AddAsync(CertificateViewModel model, CancellationToken ct)
{
await _certificatesService.AddAsync(model.ToModel(), ct);
return RedirectToAction("Index");
var certificate = await _certificatesService.AddAsync(model.ToModel(), ct);
return CreatedAtAction(nameof(GetByIdAsync), new {id = certificate.Id}, certificate);
}

#endregion

[HttpDelete]
[Route("id")]
public async Task<IActionResult> RemoveAsync(long id,CancellationToken ct)
{
await _certificatesService.RemoveAsync(id, ct);
return NoContent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.EntityFrameworkCore;

namespace O2NextGen.CertificateManagement.Web.Filters
{
public class ApiExceptionFilter: IExceptionFilter

{
public void OnException(ExceptionContext context)
{
if (context.ExceptionHandled is DbUpdateConcurrencyException)
{
context.Result =
new ConflictObjectResult(new {Message = "Entity was updated, please refresh your copy."});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using O2NextGen.CertificateManagement.Business.Services;
using O2NextGen.CertificateManagement.Impl.Services;
using O2NextGen.CertificateManagement.Web.Filters;

namespace O2NextGen.CertificateManagement.Web.IoC
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddRequiredMvcComponents(this IServiceCollection services)
{
services.AddTransient<ApiExceptionFilter>();

var mvcBuilder = services.AddMvcCore(options =>
{
options.Filters.Add<ApiExceptionFilter>();
} );
mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
mvcBuilder.AddJsonFormatters();
return services;
}

public static IServiceCollection AddBusiness(this IServiceCollection services)
{
// services.AddSingleton<ICertificatesService, InMemoryCertificatesService>();
// Include DataLayer
services.AddScoped<ICertificatesService, CertificatesService>();
//more business services...

return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>O2NextGen.CertificateManagement.Web</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,9 +15,17 @@

<ItemGroup>
<ProjectReference Include="..\O2NextGen.CertificateManagement.Business\O2NextGen.CertificateManagement.Business.csproj" />
<ProjectReference Include="..\O2NextGen.CertificateManagement.Data\O2NextGen.CertificateManagement.Data.csproj" />
<ProjectReference Include="..\O2NextGen.CertificateManagement.Impl\O2NextGen.CertificateManagement.Impl.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="Views\Certificates\Create.cshtml" />
<_ContentIncludedByDefault Remove="Views\Certificates\Detail.cshtml" />
<_ContentIncludedByDefault Remove="Views\Certificates\Index.cshtml" />
<_ContentIncludedByDefault Remove="Views\_ViewImports.cshtml" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions src/Services/c-gen/O2NextGen.CertificateManagement.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace O2NextGen.CertificateManagement.Web
{
public class Program
{
public static async Task Main(string[] args)
{
try
{
var host = CreateWebHostBuilder(args).Build();
Console.WriteLine("################# Starting Application #################");
await host.EnsureDbUpdate();
await host.RunAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using O2NextGen.CertificateManagement.Business.Services;
using O2NextGen.CertificateManagement.Impl.Services;
using O2NextGen.CertificateManagement.Data;
using O2NextGen.CertificateManagement.Web.IoC;

[assembly: ApiController]
namespace O2NextGen.CertificateManagement.Web
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddRequiredMvcComponents();
services.AddBusiness();
services.AddDbContext<CertificateManagementDbContext>(x =>
x.UseSqlServer("Server=localhost;Initial Catalog=O2NextGen.CertificateDb;Persist Security Info=False;User ID=sa;Password=your@Password;Connection Timeout=30;"));
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using O2NextGen.CertificateManagement.Data;

// ReSharper disable once CheckNamespace
namespace Microsoft.AspNetCore.Hosting
{
internal static class DatabaseExtensions
{
internal static async Task EnsureDbUpdate(this IWebHost host)
{
using (var scope = host.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<CertificateManagementDbContext>();
await context.Database.MigrateAsync();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace O2NextGen.CertificateManagement.Business.Services
{
public interface ICertificatesService
{
Task<IReadOnlyCollection<Certificate>> GetAllAsync(CancellationToken cancellationToken);
Task<IReadOnlyCollection<Certificate>> GetAllAsync(CancellationToken ct);

Task<Certificate> GetByIdAsync(long id, CancellationToken cancellationToken);
Task<Certificate> GetByIdAsync(long id, CancellationToken ct);

Task<Certificate> UpdateAsync(Certificate certificate, CancellationToken cancellationToken);
Task<Certificate> UpdateAsync(Certificate certificate, CancellationToken ct);

Task<Certificate> AddAsync(Certificate certificate, CancellationToken cancellationToken);
Task<Certificate> AddAsync(Certificate certificate, CancellationToken ct);

Task RemoveAsync(long id, CancellationToken ct);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using O2NextGen.CertificateManagement.Data.Entities;

namespace O2NextGen.CertificateManagement.Data
{
public class CertificateManagementDbContext : DbContext
{

#region Fields

public DbSet<CertificateEntity> Certificates { get; set; }

#endregion

#region Ctors

public CertificateManagementDbContext(DbContextOptions<CertificateManagementDbContext> options)
: base(options)
{
}

#endregion

#region Configure

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CertificateEntity>(ConfigureCertificateEntity);
}

private void ConfigureCertificateEntity(EntityTypeBuilder<CertificateEntity> builder)
{
builder.ToTable("Certificate");

builder.Property(ci => ci.Id)
.HasColumnType("bigint")
.ForSqlServerUseSequenceHiLo("certificate_hilo")
.IsRequired();
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace O2NextGen.CertificateManagement.Data.Entities
{
public class CertificateEntity
{
public long Id { get; set; }
public string Name { get; set; }
}
}
Loading

0 comments on commit 25b3043

Please sign in to comment.