diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Services/ICertificatesService.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Services/ICertificatesService.cs index 9e353920..88267de6 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Services/ICertificatesService.cs +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Business/Services/ICertificatesService.cs @@ -1,16 +1,18 @@ using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using O2NextGen.CertificateManagement.Business.Models; namespace O2NextGen.CertificateManagement.Business.Services { public interface ICertificatesService { - IReadOnlyCollection GetAll(); + Task> GetAllAsync(CancellationToken cancellationToken); - Certificate GetById(long id); + Task GetByIdAsync(long id, CancellationToken cancellationToken); - Certificate Update(Certificate certificate); + Task UpdateAsync(Certificate certificate, CancellationToken cancellationToken); - Certificate Add(Certificate certificate); + Task AddAsync(Certificate certificate, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/Services/InMemoryCertificatesService.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/Services/InMemoryCertificatesService.cs index 4e6061e0..acb8b028 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/Services/InMemoryCertificatesService.cs +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Impl/Services/InMemoryCertificatesService.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using O2NextGen.CertificateManagement.Business.Models; using O2NextGen.CertificateManagement.Business.Services; @@ -29,32 +31,36 @@ public InMemoryCertificatesService() #endregion #region Methods - public IReadOnlyCollection GetAll() + public async Task> GetAllAsync(CancellationToken cancellationToken) { - return Certificates.AsReadOnly(); + await Task.Delay(3000, cancellationToken); + return await Task.FromResult>(Certificates.AsReadOnly()); } - public Certificate GetById(long id) + public async Task GetByIdAsync(long id, CancellationToken cancellationToken) { - return Certificates.SingleOrDefault(g => g.Id == id); + await Task.Delay(3000, cancellationToken); + return await Task.FromResult(Certificates.SingleOrDefault(g => g.Id == id)); } - public Certificate Update(Certificate certificate) + public async Task UpdateAsync(Certificate certificate, CancellationToken cancellationToken) { + await Task.Delay(5000, cancellationToken); var toUpdate = Certificates.SingleOrDefault(g => g.Id == certificate.Id); if (toUpdate == null) return null; toUpdate.Name = certificate.Name; - return toUpdate; + return await Task.FromResult(toUpdate); } - public Certificate Add(Certificate certificate) + public async Task AddAsync(Certificate certificate, CancellationToken cancellationToken) { + await Task.Delay(3000, cancellationToken); certificate.Id = ++_currentId; Certificates.Add(certificate); - return certificate; + return await Task.FromResult(certificate); } #endregion } diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Controllers/CertificatesController.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Controllers/CertificatesController.cs index b48b8643..5dd0e8b1 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Controllers/CertificatesController.cs +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Web/Controllers/CertificatesController.cs @@ -1,6 +1,8 @@ +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using O2NextGen.CertificateManagement.Business.Services; -using O2NextGen.CertificateManagement.Web.Mappings; +using O2NextGen.CertificateManagement.Web.Mappings; using O2NextGen.CertificateManagement.Web.Models; namespace O2NextGen.CertificateManagement.Web.Controllers @@ -12,8 +14,6 @@ public class CertificatesController : Controller private readonly ICertificatesService _certificatesService; - - #endregion @@ -31,9 +31,9 @@ public CertificatesController(ICertificatesService certificatesService) [HttpGet] [Route("")] - public IActionResult Index() + public async Task Index() { - var models = _certificatesService.GetAll(); + var models = await _certificatesService.GetAllAsync(CancellationToken.None); if (models == null) return NotFound(); return View(models.ToViewModel()); @@ -41,9 +41,9 @@ public IActionResult Index() [HttpGet] [Route("{id}")] - public IActionResult Detail(long id) + public async Task Detail(long id, CancellationToken ct) { - var certificate = _certificatesService.GetById(id); + var certificate = await _certificatesService.GetByIdAsync(id, ct); if (certificate == null) return NotFound(); return View(certificate.ToViewModel()); @@ -52,9 +52,9 @@ public IActionResult Detail(long id) [HttpPost] [Route("id")] [ValidateAntiForgeryToken] - public IActionResult Edit(long id, CertificateViewModel model) + public async Task Edit(long id, CertificateViewModel model, CancellationToken ct) { - var certificate = _certificatesService.Update(model.ToModel()); + var certificate = await _certificatesService.UpdateAsync(model.ToModel(), ct); if (certificate == null) return NotFound(); certificate.Name = model.Name; @@ -71,9 +71,9 @@ public IActionResult Create() [HttpPost] [Route("")] - public IActionResult CreateReally(CertificateViewModel model) + public async Task CreateReally(CertificateViewModel model, CancellationToken ct) { - _certificatesService.Add(model.ToModel()); + await _certificatesService.AddAsync(model.ToModel(), ct); return RedirectToAction("Index"); }