Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/Services/c-gen/O2NextGen.CGen.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

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}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EA540B06-8A73-49C7-A799-49423B316458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA540B06-8A73-49C7-A799-49423B316458}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA540B06-8A73-49C7-A799-49423B316458}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA540B06-8A73-49C7-A799-49423B316458}.Release|Any CPU.Build.0 = Release|Any CPU
{C6E0B2A5-6349-4C1D-8E14-82249AF8F58A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6E0B2A5-6349-4C1D-8E14-82249AF8F58A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6E0B2A5-6349-4C1D-8E14-82249AF8F58A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6E0B2A5-6349-4C1D-8E14-82249AF8F58A}.Release|Any CPU.Build.0 = Release|Any CPU
{01805439-2954-49CE-93D2-5EB06B82146C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6DFC9F0-3FA7-492B-ACE9-3EFBF3477712}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace O2NextGen.CertificateManagement.Business.Models
{
public class Certificate
{
public long Id { get; set; }
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<None Remove="Services\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using O2NextGen.CertificateManagement.Business.Models;

namespace O2NextGen.CertificateManagement.Business.Services
{
public interface ICertificatesService
{
IReadOnlyCollection<Certificate> GetAll();

Certificate GetById(long id);

Certificate Update(Certificate certificate);

Certificate Add(Certificate certificate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<None Remove="Services\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\O2NextGen.CertificateManagement.Business\O2NextGen.CertificateManagement.Business.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Linq;
using O2NextGen.CertificateManagement.Business.Models;
using O2NextGen.CertificateManagement.Business.Services;

namespace O2NextGen.CertificateManagement.Impl.Services
{
public class InMemoryCertificatesService : ICertificatesService
{
#region Fields

private static readonly List<Certificate> Certificates = new List<Certificate>()
{
new Certificate()
{
Id = 1, Name = "First"
}
};
private long _currentId;

#endregion

#region Ctors

public InMemoryCertificatesService()
{
_currentId = Certificates.Count();
}
#endregion

#region Methods
public IReadOnlyCollection<Certificate> GetAll()
{
return Certificates.AsReadOnly();
}

public Certificate GetById(long id)
{
return Certificates.SingleOrDefault(g => g.Id == id);
}

public Certificate Update(Certificate certificate)
{
var toUpdate = Certificates.SingleOrDefault(g => g.Id == certificate.Id);
if (toUpdate == null)
return null;

toUpdate.Name = certificate.Name;

return toUpdate;
}

public Certificate Add(Certificate certificate)
{
certificate.Id = ++_currentId;
Certificates.Add(certificate);
return certificate;
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Microsoft.AspNetCore.Mvc;
using O2NextGen.CertificateManagement.Business.Services;
using O2NextGen.CertificateManagement.Web.Mappings;
using O2NextGen.CertificateManagement.Web.Models;

namespace O2NextGen.CertificateManagement.Web.Controllers
{
[Route("certificates")]
public class CertificatesController : Controller
{
#region Fields

private readonly ICertificatesService _certificatesService;



#endregion


#region Ctors

public CertificatesController(ICertificatesService certificatesService)
{
_certificatesService = certificatesService;
}

#endregion


#region Methods

[HttpGet]
[Route("")]
public IActionResult Index()
{
var models = _certificatesService.GetAll();
if (models == null)
return NotFound();
return View(models.ToViewModel());
}

[HttpGet]
[Route("{id}")]
public IActionResult Detail(long id)
{
var certificate = _certificatesService.GetById(id);
if (certificate == null)
return NotFound();
return View(certificate.ToViewModel());
}

[HttpPost]
[Route("id")]
[ValidateAntiForgeryToken]
public IActionResult Edit(long id, CertificateViewModel model)
{
var certificate = _certificatesService.Update(model.ToModel());
if (certificate == null)
return NotFound();
certificate.Name = model.Name;

return RedirectToAction("Index");
}

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

[HttpPost]
[Route("")]
public IActionResult CreateReally(CertificateViewModel model)
{
_certificatesService.Add(model.ToModel());
return RedirectToAction("Index");
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using O2NextGen.CertificateManagement.Business.Models;
using O2NextGen.CertificateManagement.Web.Models;

namespace O2NextGen.CertificateManagement.Web.Mappings
{
public static class CertificateMappings
{
public static CertificateViewModel ToViewModel(this Certificate model)
{
if (model == null)
return null;

var viewModel = new CertificateViewModel();

//Bindings
viewModel.Id = model.Id;
viewModel.Name = model.Name;

return viewModel;
}

public static Certificate ToModel(this CertificateViewModel viewModel)
{
if (viewModel == null)
return null;

var model = new Certificate();

//Bindings
model.Id = viewModel.Id;
model.Name = viewModel.Name;

return model;
}

public static IReadOnlyCollection<CertificateViewModel> ToViewModel(
this IReadOnlyCollection<Certificate> models)
{
if (models.Count == 0)
{
return Array.Empty<CertificateViewModel>();
}

var subscription = new CertificateViewModel[models.Count];
var i = 0;
foreach (var model in models)
{
subscription[i] = ToViewModel(model);
++i;
}

return new ReadOnlyCollection<CertificateViewModel>(subscription);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace O2NextGen.CertificateManagement.Web.Models
{
public class CertificateViewModel
{
public long Id { get; set; }
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

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

</Project>
Loading