diff --git a/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.gitignore b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.gitignore new file mode 100644 index 00000000..bcdff6b0 --- /dev/null +++ b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/projectSettingsUpdater.xml +/.idea.O2NextGen.CGen.iml +/modules.xml +/contentModel.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.name b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.name new file mode 100644 index 00000000..0f7c9d3c --- /dev/null +++ b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/.name @@ -0,0 +1 @@ +O2NextGen.CGen \ No newline at end of file diff --git a/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/encodings.xml b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/indexLayout.xml b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/vcs.xml b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/vcs.xml new file mode 100644 index 00000000..c2365ab1 --- /dev/null +++ b/src/Services/c-gen/.idea/.idea.O2NextGen.CGen/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CGen.sln b/src/Services/c-gen/O2NextGen.CGen.sln new file mode 100644 index 00000000..683b9695 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CGen.sln @@ -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 diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Models/Certificate.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Models/Certificate.cs new file mode 100644 index 00000000..01fd4850 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Models/Certificate.cs @@ -0,0 +1,8 @@ +namespace O2NextGen.CertificateManagement.Business.Models +{ + public class Certificate + { + public long Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Business/O2NextGen.CertificateManagement.Business.csproj b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/O2NextGen.CertificateManagement.Business.csproj new file mode 100644 index 00000000..56768ce6 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/O2NextGen.CertificateManagement.Business.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp2.1 + + + + + + + + + diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Services/ICertificatesService.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Services/ICertificatesService.cs new file mode 100644 index 00000000..9e353920 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Services/ICertificatesService.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using O2NextGen.CertificateManagement.Business.Models; + +namespace O2NextGen.CertificateManagement.Business.Services +{ + public interface ICertificatesService + { + IReadOnlyCollection GetAll(); + + Certificate GetById(long id); + + Certificate Update(Certificate certificate); + + Certificate Add(Certificate certificate); + } +} \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/O2NextGen.CertificateManagement.Impl.csproj b/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/O2NextGen.CertificateManagement.Impl.csproj new file mode 100644 index 00000000..8ae43b76 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/O2NextGen.CertificateManagement.Impl.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/Services/InMemoryCertificatesService.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/Services/InMemoryCertificatesService.cs new file mode 100644 index 00000000..4e6061e0 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/Services/InMemoryCertificatesService.cs @@ -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 Certificates = new List() + { + new Certificate() + { + Id = 1, Name = "First" + } + }; + private long _currentId; + + #endregion + + #region Ctors + + public InMemoryCertificatesService() + { + _currentId = Certificates.Count(); + } + #endregion + + #region Methods + public IReadOnlyCollection 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 + } +} \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Controllers/CertificatesController.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Controllers/CertificatesController.cs new file mode 100644 index 00000000..b48b8643 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Controllers/CertificatesController.cs @@ -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 + } +} \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Mappings/CertificateMappings.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Mappings/CertificateMappings.cs new file mode 100644 index 00000000..be9f8dfa --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Mappings/CertificateMappings.cs @@ -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 ToViewModel( + this IReadOnlyCollection models) + { + if (models.Count == 0) + { + return Array.Empty(); + } + + var subscription = new CertificateViewModel[models.Count]; + var i = 0; + foreach (var model in models) + { + subscription[i] = ToViewModel(model); + ++i; + } + + return new ReadOnlyCollection(subscription); + } + } +} \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Models/CertificateViewModel.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Models/CertificateViewModel.cs new file mode 100644 index 00000000..aa93cab7 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Models/CertificateViewModel.cs @@ -0,0 +1,8 @@ +namespace O2NextGen.CertificateManagement.Web.Models +{ + public class CertificateViewModel + { + public long Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/O2NextGen.CertificateManagement.Web.csproj b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/O2NextGen.CertificateManagement.Web.csproj new file mode 100644 index 00000000..6a042cde --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/O2NextGen.CertificateManagement.Web.csproj @@ -0,0 +1,22 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + + + + diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Program.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Program.cs new file mode 100644 index 00000000..39abb3ce --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace O2NextGen.CertificateManagement.Web +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("################# Starting Application #################"); + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Properties/launchSettings.json b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Properties/launchSettings.json new file mode 100644 index 00000000..f9858d76 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "O2NextGen.CertificateManagement.Web": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Startup.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Startup.cs new file mode 100644 index 00000000..9ef77ab3 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Startup.cs @@ -0,0 +1,42 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using O2NextGen.CertificateManagement.Business.Services; +using O2NextGen.CertificateManagement.Impl.Services; + +namespace O2NextGen.CertificateManagement.Web +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + + services.AddSingleton(); + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseStaticFiles(); + + app.Use(async (context, next) => + { + context.Response.OnStarting(() => + { + context.Response.Headers.Add("X-Power-By", "O2NextGen: C-Gen"); + return Task.CompletedTask; + }); + + await next.Invoke(); + }); + + app.UseMvc(); + } + } +} \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Create.cshtml b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Create.cshtml new file mode 100644 index 00000000..ea0630c9 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Create.cshtml @@ -0,0 +1,7 @@ +@model CertificateViewModel + +
+ + + +
diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Detail.cshtml b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Detail.cshtml new file mode 100644 index 00000000..6f2ec2a8 --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Detail.cshtml @@ -0,0 +1,7 @@ +@model CertificateViewModel + +
+ + + +
diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Index.cshtml b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Index.cshtml new file mode 100644 index 00000000..da3ae7da --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/Certificates/Index.cshtml @@ -0,0 +1,10 @@ +@model IEnumerable + +@foreach (var certificate in Model) +{ +
  • + @certificate.Id @certificate.Name | Edit +
  • +} + +Create \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/_ViewImports.cshtml b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/_ViewImports.cshtml new file mode 100644 index 00000000..8020032e --- /dev/null +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Views/_ViewImports.cshtml @@ -0,0 +1,2 @@ +@using O2NextGen.CertificateManagement.Web.Models +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file