diff --git a/src/api/Areas/Admin/Controllers/OrganizationController.cs b/src/api/Areas/Admin/Controllers/OrganizationController.cs index 15b6ea39..452ac86e 100644 --- a/src/api/Areas/Admin/Controllers/OrganizationController.cs +++ b/src/api/Areas/Admin/Controllers/OrganizationController.cs @@ -62,7 +62,7 @@ public IActionResult Find() } /// - /// + /// Get the organization for the specified 'id'. /// /// /// @@ -81,7 +81,7 @@ public IActionResult GetForId(int id) } /// - /// + /// Add a new organization to the database. /// /// /// @@ -103,7 +103,7 @@ public IActionResult Add(OrganizationModel model) } /// - /// + /// Update the organization specified. /// /// /// @@ -126,7 +126,7 @@ public IActionResult Update(OrganizationModel model) } /// - /// + /// Delete the organization specified. /// /// /// diff --git a/src/api/Areas/Admin/Controllers/RoleController.cs b/src/api/Areas/Admin/Controllers/RoleController.cs index d0d4fd4a..3fa419ac 100644 --- a/src/api/Areas/Admin/Controllers/RoleController.cs +++ b/src/api/Areas/Admin/Controllers/RoleController.cs @@ -60,7 +60,7 @@ public IActionResult Find() } /// - /// + /// Get the role for the specified 'id'. /// /// /// @@ -79,7 +79,7 @@ public IActionResult GetForId(int id) } /// - /// + /// Add a new role to the database. /// /// /// @@ -97,7 +97,7 @@ public IActionResult Add(RoleModel model) } /// - /// + /// Update the role specified. /// /// /// @@ -115,7 +115,7 @@ public IActionResult Update(RoleModel model) } /// - /// + /// Delete the role specified. /// /// /// diff --git a/src/api/Areas/Admin/Controllers/TenantController.cs b/src/api/Areas/Admin/Controllers/TenantController.cs index 93bcf8ba..4efbcb89 100644 --- a/src/api/Areas/Admin/Controllers/TenantController.cs +++ b/src/api/Areas/Admin/Controllers/TenantController.cs @@ -60,7 +60,7 @@ public IActionResult Find() } /// - /// + /// Get the tenant for the specified 'id'. /// /// /// @@ -79,7 +79,7 @@ public IActionResult GetForId(int id) } /// - /// + /// Add a new tenant to the database. /// /// /// @@ -100,7 +100,7 @@ public IActionResult Add(TenantModel model) } /// - /// + /// Update the tenant specified. /// /// /// @@ -123,7 +123,7 @@ public IActionResult Update(TenantModel model) } /// - /// + /// Delete the tenant specified. /// /// /// diff --git a/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs b/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs index b60be823..7961114b 100644 --- a/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs +++ b/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs @@ -8,11 +8,11 @@ using HSB.DAL.Services; using HSB.Keycloak; using HSB.Keycloak.Extensions; -using HSB.Models; using Swashbuckle.AspNetCore.Annotations; +using HSB.Models.Dashboard; -namespace HSB.API.Areas.Hsb.Controllers; +namespace HSB.API.Areas.Dashboard.Controllers; /// /// FileSystemItemController class, provides endpoints for file system items. @@ -27,7 +27,6 @@ namespace HSB.API.Areas.Hsb.Controllers; public class FileSystemItemController : ControllerBase { #region Variables - private readonly ILogger _logger; private readonly IFileSystemItemService _fileSystemItemService; private readonly IFileSystemHistoryItemService _fileSystemHistoryItemService; private readonly IAuthorizationHelper _authorization; @@ -42,19 +41,16 @@ public class FileSystemItemController : ControllerBase /// /// /// - /// public FileSystemItemController( IFileSystemItemService fileSystemItemService, IFileSystemHistoryItemService fileSystemHistoryItemService, IAuthorizationHelper authorization, - IXlsExporter exporter, - ILogger logger) + IXlsExporter exporter) { _fileSystemItemService = fileSystemItemService; _fileSystemHistoryItemService = fileSystemHistoryItemService; _authorization = authorization; _exporter = exporter; - _logger = logger; } #endregion diff --git a/src/api/Areas/Dashboard/Controllers/OperatingSystemItemController.cs b/src/api/Areas/Dashboard/Controllers/OperatingSystemItemController.cs index 47e57201..35867c54 100644 --- a/src/api/Areas/Dashboard/Controllers/OperatingSystemItemController.cs +++ b/src/api/Areas/Dashboard/Controllers/OperatingSystemItemController.cs @@ -8,12 +8,13 @@ using HSB.DAL.Services; using HSB.Keycloak; using HSB.Keycloak.Extensions; -using HSB.Models; using Swashbuckle.AspNetCore.Annotations; using Microsoft.Extensions.Caching.Memory; +using HSB.Models.Dashboard; +using HSB.Models.Lists; -namespace HSB.API.Areas.Hsb.Controllers; +namespace HSB.API.Areas.Dashboard.Controllers; /// /// OperatingSystemItemController class, provides endpoints for operating system items. @@ -28,7 +29,6 @@ namespace HSB.API.Areas.Hsb.Controllers; public class OperatingSystemItemController : ControllerBase { #region Variables - private readonly ILogger _logger; private readonly IOperatingSystemItemService _service; private readonly IAuthorizationHelper _authorization; private readonly IXlsExporter _exporter; @@ -45,19 +45,16 @@ public class OperatingSystemItemController : ControllerBase /// /// /// - /// public OperatingSystemItemController( IOperatingSystemItemService service, IMemoryCache memoryCache, IAuthorizationHelper authorization, - IXlsExporter exporter, - ILogger logger) + IXlsExporter exporter) { _service = service; _memoryCache = memoryCache; _authorization = authorization; _exporter = exporter; - _logger = logger; } #endregion @@ -69,7 +66,7 @@ public OperatingSystemItemController( [HttpGet(Name = "GetOperatingSystemItems-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 60)] public IActionResult Find() { @@ -112,7 +109,7 @@ public IActionResult Find() [HttpGet("list", Name = "GetOperatingSystemItemLists-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 60)] public IActionResult FindList() { @@ -155,7 +152,7 @@ public IActionResult FindList() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(OperatingSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] public IActionResult GetForId(int id) { var isHSB = this.User.HasClientRole(ClientRole.HSB); @@ -190,7 +187,7 @@ public IActionResult GetForId(int id) [Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] public IActionResult Export(string format, string name = "service-now") { if (format == "excel") diff --git a/src/api/Areas/Dashboard/Controllers/OrganizationController.cs b/src/api/Areas/Dashboard/Controllers/OrganizationController.cs index 131e0115..389a48a3 100644 --- a/src/api/Areas/Dashboard/Controllers/OrganizationController.cs +++ b/src/api/Areas/Dashboard/Controllers/OrganizationController.cs @@ -8,12 +8,12 @@ using HSB.DAL.Services; using HSB.Keycloak; using HSB.Keycloak.Extensions; -using HSB.Models; using Swashbuckle.AspNetCore.Annotations; -using Microsoft.Extensions.Caching.Memory; +using HSB.Models.Dashboard; +using HSB.Models.Lists; -namespace HSB.API.Areas.Hsb.Controllers; +namespace HSB.API.Areas.Dashboard.Controllers; /// /// OrganizationController class, provides endpoints for organizations. @@ -28,7 +28,6 @@ namespace HSB.API.Areas.Hsb.Controllers; public class OrganizationController : ControllerBase { #region Variables - private readonly ILogger _logger; private readonly IOrganizationService _service; private readonly IAuthorizationHelper _authorization; #endregion @@ -39,15 +38,12 @@ public class OrganizationController : ControllerBase /// /// /// - /// public OrganizationController( IOrganizationService service, - IAuthorizationHelper authorization, - ILogger logger) + IAuthorizationHelper authorization) { _service = service; _authorization = authorization; - _logger = logger; } #endregion @@ -60,7 +56,7 @@ public OrganizationController( [HttpGet(Name = "GetOrganizations-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Organization" })] + [SwaggerOperation(Tags = ["Organization"])] public IActionResult Find() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -93,7 +89,7 @@ public IActionResult Find() [HttpGet("list", Name = "GetOrganizationLists-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Organization" })] + [SwaggerOperation(Tags = ["Organization"])] public IActionResult FindList() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -126,7 +122,7 @@ public IActionResult FindList() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Organization" })] + [SwaggerOperation(Tags = ["Organization"])] public IActionResult GetForId(int id) { var isHSB = this.User.HasClientRole(ClientRole.HSB); diff --git a/src/api/Areas/Dashboard/Controllers/ServerItemController.cs b/src/api/Areas/Dashboard/Controllers/ServerItemController.cs index 57d5d020..33563080 100644 --- a/src/api/Areas/Dashboard/Controllers/ServerItemController.cs +++ b/src/api/Areas/Dashboard/Controllers/ServerItemController.cs @@ -8,12 +8,13 @@ using HSB.DAL.Services; using HSB.Keycloak; using HSB.Keycloak.Extensions; -using HSB.Models; using Swashbuckle.AspNetCore.Annotations; using Microsoft.Extensions.Caching.Memory; +using HSB.Models.Dashboard; +using HSB.Models.Lists; -namespace HSB.API.Areas.Hsb.Controllers; +namespace HSB.API.Areas.Dashboard.Controllers; /// /// ServerItemController class, provides endpoints for server items. @@ -28,7 +29,6 @@ namespace HSB.API.Areas.Hsb.Controllers; public class ServerItemController : ControllerBase { #region Variables - private readonly ILogger _logger; private readonly IServerItemService _serverItemService; private readonly IServerHistoryItemService _serverHistoryItemService; private readonly IAuthorizationHelper _authorization; @@ -47,21 +47,18 @@ public class ServerItemController : ControllerBase /// /// /// - /// public ServerItemController( IServerItemService serverItemService, IServerHistoryItemService serverHistoryItemService, IMemoryCache memoryCache, IAuthorizationHelper authorization, - IXlsExporter exporter, - ILogger logger) + IXlsExporter exporter) { _serverItemService = serverItemService; _serverHistoryItemService = serverHistoryItemService; _memoryCache = memoryCache; _authorization = authorization; _exporter = exporter; - _logger = logger; } #endregion @@ -115,7 +112,7 @@ public IActionResult Find() [HttpGet("list", Name = "GetServerItemLists-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult FindList() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -158,7 +155,7 @@ public IActionResult FindList() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(ServerItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult GetForId(string serviceNowKey, bool includeFileSystemItems = false) { var isHSB = this.User.HasClientRole(ClientRole.HSB); diff --git a/src/api/Areas/Dashboard/Controllers/TenantController.cs b/src/api/Areas/Dashboard/Controllers/TenantController.cs index 66a84cae..0752f8ad 100644 --- a/src/api/Areas/Dashboard/Controllers/TenantController.cs +++ b/src/api/Areas/Dashboard/Controllers/TenantController.cs @@ -8,12 +8,13 @@ using HSB.DAL.Services; using HSB.Keycloak; using HSB.Keycloak.Extensions; -using HSB.Models; using Swashbuckle.AspNetCore.Annotations; using Microsoft.Extensions.Caching.Memory; +using HSB.Models.Dashboard; +using HSB.Models.Lists; -namespace HSB.API.Areas.Hsb.Controllers; +namespace HSB.API.Areas.Dashboard.Controllers; /// /// TenantController class, provides endpoints for tenants. @@ -28,7 +29,6 @@ namespace HSB.API.Areas.Hsb.Controllers; public class TenantController : ControllerBase { #region Variables - private readonly ILogger _logger; private readonly ITenantService _tenantService; private readonly IAuthorizationHelper _authorization; private readonly IMemoryCache _memoryCache; @@ -43,17 +43,14 @@ public class TenantController : ControllerBase /// /// /// - /// public TenantController( ITenantService tenantService, IMemoryCache memoryCache, - IAuthorizationHelper authorization, - ILogger logger) + IAuthorizationHelper authorization) { _tenantService = tenantService; _memoryCache = memoryCache; _authorization = authorization; - _logger = logger; } #endregion @@ -65,8 +62,7 @@ public TenantController( [HttpGet(Name = "GetTenants-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Tenant" })] - // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 60)] + [SwaggerOperation(Tags = ["Tenant"])] public IActionResult Find() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -108,8 +104,7 @@ public IActionResult Find() [HttpGet("list", Name = "GetTenantLists-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Tenant" })] - // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 60)] + [SwaggerOperation(Tags = ["Tenant"])] public IActionResult FindList() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -151,7 +146,7 @@ public IActionResult FindList() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Tenant" })] + [SwaggerOperation(Tags = ["Tenant"])] public IActionResult GetForId(int id) { var isHSB = this.User.HasClientRole(ClientRole.HSB); diff --git a/src/api/Areas/Services/Controllers/DataSyncController.cs b/src/api/Areas/Services/Controllers/DataSyncController.cs index 4ebd51b8..16070365 100644 --- a/src/api/Areas/Services/Controllers/DataSyncController.cs +++ b/src/api/Areas/Services/Controllers/DataSyncController.cs @@ -22,7 +22,6 @@ namespace HSB.API.Areas.Services.Controllers; public class DataSyncController : ControllerBase { #region Variables - private readonly ILogger _logger; private readonly IDataSyncService _service; #endregion @@ -31,23 +30,21 @@ public class DataSyncController : ControllerBase /// Creates a new instance of a DataSyncController. /// /// - /// - public DataSyncController(IDataSyncService service, ILogger logger) + public DataSyncController(IDataSyncService service) { _service = service; - _logger = logger; } #endregion #region Endpoints /// - /// + /// Find all the data sync items. /// /// [HttpGet(Name = "FindDataSync-Services")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "DataSync" })] + [SwaggerOperation(Tags = ["DataSync"])] public IActionResult Find() { var entities = _service.Find(o => true); @@ -55,7 +52,7 @@ public IActionResult Find() } /// - /// + /// Get the data sync for the specified 'name'. /// /// /// @@ -63,7 +60,7 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(DataSyncModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "DataSync" })] + [SwaggerOperation(Tags = ["DataSync"])] public IActionResult GetForName(string name) { var entity = _service.Find((ds) => ds.Name == name).FirstOrDefault(); @@ -74,7 +71,7 @@ public IActionResult GetForName(string name) } /// - /// + /// Update the data sync item. /// /// /// @@ -82,7 +79,7 @@ public IActionResult GetForName(string name) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(DataSyncModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "DataSync" })] + [SwaggerOperation(Tags = ["DataSync"])] public IActionResult Update(DataSyncModel model) { var entity = model.ToEntity(); diff --git a/src/api/Areas/Services/Controllers/FileSystemItemController.cs b/src/api/Areas/Services/Controllers/FileSystemItemController.cs index 01039c9f..1c02906f 100644 --- a/src/api/Areas/Services/Controllers/FileSystemItemController.cs +++ b/src/api/Areas/Services/Controllers/FileSystemItemController.cs @@ -54,7 +54,7 @@ public FileSystemItemController( [HttpGet(Name = "FindFileSystemItems-Services")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult Find() { var fileSystemItems = _fileSystemItemService.Find(o => true); @@ -70,7 +70,7 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(FileSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult GetForId(string id) { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -97,7 +97,7 @@ public IActionResult GetForId(string id) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(FileSystemItemModel), (int)HttpStatusCode.Created)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult Add(FileSystemItemModel model) { var entity = model.ToEntity(); @@ -115,7 +115,7 @@ public IActionResult Add(FileSystemItemModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(FileSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult Update(FileSystemItemModel model) { var entity = model.ToEntity(); @@ -133,7 +133,7 @@ public IActionResult Update(FileSystemItemModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(FileSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult Delete(FileSystemItemModel model) { var entity = model.ToEntity(); @@ -151,7 +151,7 @@ public IActionResult Delete(FileSystemItemModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(FileSystemHistoryItemModel), (int)HttpStatusCode.Created)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult Add(FileSystemHistoryItemModel model) { var entity = model.ToEntity(); diff --git a/src/api/Areas/Services/Controllers/OperatingSystemItemController.cs b/src/api/Areas/Services/Controllers/OperatingSystemItemController.cs index f4ee3063..563d061f 100644 --- a/src/api/Areas/Services/Controllers/OperatingSystemItemController.cs +++ b/src/api/Areas/Services/Controllers/OperatingSystemItemController.cs @@ -41,13 +41,13 @@ public OperatingSystemItemController(IOperatingSystemItemService service, ILogge #region Endpoints /// - /// + /// Find all operating system items. /// /// [HttpGet(Name = "FindOperatingSystemItems-Services")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] public IActionResult Find() { var operatingSystemItems = _service.Find(o => true); @@ -55,7 +55,7 @@ public IActionResult Find() } /// - /// + /// Get the operating system item for the specified 'id'. /// /// /// @@ -63,7 +63,7 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(OperatingSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] public IActionResult GetForId(int id) { var entity = _service.FindForId(id); @@ -74,7 +74,7 @@ public IActionResult GetForId(int id) } /// - /// + /// Add or update the provided operating system item. /// /// /// @@ -83,7 +83,7 @@ public IActionResult GetForId(int id) [ProducesResponseType(typeof(OperatingSystemItemModel), (int)HttpStatusCode.Created)] [ProducesResponseType(typeof(OperatingSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] public IActionResult AddOrUpdate(OperatingSystemItemModel model) { var entity = model.ToEntity(); @@ -104,7 +104,7 @@ public IActionResult AddOrUpdate(OperatingSystemItemModel model) } /// - /// + /// Update the operating system item. /// /// /// @@ -112,7 +112,7 @@ public IActionResult AddOrUpdate(OperatingSystemItemModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(OperatingSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Operating System Item" })] + [SwaggerOperation(Tags = ["Operating System Item"])] public IActionResult Update(OperatingSystemItemModel model) { var entity = model.ToEntity(); diff --git a/src/api/Areas/Services/Controllers/OrganizationController.cs b/src/api/Areas/Services/Controllers/OrganizationController.cs index 0b68d100..dd5d6f92 100644 --- a/src/api/Areas/Services/Controllers/OrganizationController.cs +++ b/src/api/Areas/Services/Controllers/OrganizationController.cs @@ -41,7 +41,7 @@ public OrganizationController(IOrganizationService service, ILogger - /// + /// Get all organizations. /// /// [HttpGet(Name = "FindOrganizations-Services")] @@ -55,7 +55,7 @@ public IActionResult Find() } /// - /// + /// Get organization for the specified 'id'. /// /// /// @@ -63,7 +63,7 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Organization" })] + [SwaggerOperation(Tags = ["Organization"])] public IActionResult GetForId(int id) { var entity = _service.FindForId(id); @@ -74,7 +74,7 @@ public IActionResult GetForId(int id) } /// - /// + /// Add or update the provided organization. /// /// /// @@ -83,7 +83,7 @@ public IActionResult GetForId(int id) [ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.Created)] [ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Organization" })] + [SwaggerOperation(Tags = ["Organization"])] public IActionResult AddOrUpdate(OrganizationModel model) { var entity = model.ToEntity(); @@ -104,7 +104,7 @@ public IActionResult AddOrUpdate(OrganizationModel model) } /// - /// + /// Update the provided organization. /// /// /// @@ -112,7 +112,7 @@ public IActionResult AddOrUpdate(OrganizationModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Organization" })] + [SwaggerOperation(Tags = ["Organization"])] public IActionResult Update(OrganizationModel model) { var entity = model.ToEntity(); @@ -129,7 +129,7 @@ public IActionResult Update(OrganizationModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Organization" })] + [SwaggerOperation(Tags = ["Organization"])] public IActionResult Cleanup() { var organizations = _service.Cleanup(); diff --git a/src/api/Areas/Services/Controllers/ServerItemController.cs b/src/api/Areas/Services/Controllers/ServerItemController.cs index 421714c6..10c32b5c 100644 --- a/src/api/Areas/Services/Controllers/ServerItemController.cs +++ b/src/api/Areas/Services/Controllers/ServerItemController.cs @@ -48,13 +48,13 @@ public ServerItemController( #region Endpoints /// - /// + /// Get all the server items for the specified query filter. /// /// [HttpGet(Name = "FindServerItems-Services")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult Find() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -66,7 +66,7 @@ public IActionResult Find() } /// - /// + /// Get the server item for the specified 'id'. /// /// /// @@ -74,7 +74,7 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(ServerItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult GetForId(string id) { var entity = _serverItemService.FindForId(id); @@ -85,7 +85,7 @@ public IActionResult GetForId(string id) } /// - /// + /// Add a new server item to the database. /// /// /// @@ -93,7 +93,7 @@ public IActionResult GetForId(string id) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(ServerItemModel), (int)HttpStatusCode.Created)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult Add(ServerItemModel model) { var entity = model.ToEntity(); @@ -103,7 +103,7 @@ public IActionResult Add(ServerItemModel model) } /// - /// + /// Update the provided server item. /// /// /// @@ -112,7 +112,7 @@ public IActionResult Add(ServerItemModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(ServerItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult Update(ServerItemModel model, bool updateTotals = false) { var entity = model.ToEntity(); @@ -122,7 +122,7 @@ public IActionResult Update(ServerItemModel model, bool updateTotals = false) } /// - /// + /// Delete the specified server item. /// /// /// @@ -130,7 +130,7 @@ public IActionResult Update(ServerItemModel model, bool updateTotals = false) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(ServerItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult Delete(ServerItemModel model) { _serverItemService.Remove(model.ToEntity()); @@ -139,7 +139,7 @@ public IActionResult Delete(ServerItemModel model) } /// - /// + /// Add the provided server item to the database. /// /// /// @@ -147,7 +147,7 @@ public IActionResult Delete(ServerItemModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(ServerHistoryItemModel), (int)HttpStatusCode.Created)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult Add(ServerHistoryItemModel model) { var entity = model.ToEntity(); diff --git a/src/api/Areas/Services/Controllers/TenantController.cs b/src/api/Areas/Services/Controllers/TenantController.cs index 62810044..7730b210 100644 --- a/src/api/Areas/Services/Controllers/TenantController.cs +++ b/src/api/Areas/Services/Controllers/TenantController.cs @@ -41,13 +41,13 @@ public TenantController(ITenantService service, ILogger logger #region Endpoints /// - /// + /// Get all tenants. /// /// [HttpGet(Name = "FindTenants-Services")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Tenant" })] + [SwaggerOperation(Tags = ["Tenant"])] public IActionResult Find() { var tenants = _service.Find(o => true); @@ -55,7 +55,7 @@ public IActionResult Find() } /// - /// + /// Get the tenant for the specified 'id'. /// /// /// @@ -63,7 +63,7 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "Tenant" })] + [SwaggerOperation(Tags = ["Tenant"])] public IActionResult GetForId(int id) { var tenant = _service.FindForId(id); @@ -74,7 +74,7 @@ public IActionResult GetForId(int id) } /// - /// + /// Add the provided tenant to the database. /// /// /// @@ -82,7 +82,7 @@ public IActionResult GetForId(int id) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.Created)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Tenant" })] + [SwaggerOperation(Tags = ["Tenant"])] public IActionResult Add(TenantModel model) { var entity = model.ToEntity(); @@ -92,7 +92,7 @@ public IActionResult Add(TenantModel model) } /// - /// + /// Update the provided tenant in the database. /// /// /// @@ -100,7 +100,7 @@ public IActionResult Add(TenantModel model) [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Tenant" })] + [SwaggerOperation(Tags = ["Tenant"])] public IActionResult Update(TenantModel model) { var entity = model.ToEntity(); diff --git a/src/dashboard/package-lock.json b/src/dashboard/package-lock.json index 77ff9294..222400d6 100644 --- a/src/dashboard/package-lock.json +++ b/src/dashboard/package-lock.json @@ -15,6 +15,7 @@ "chart.js": "^4.4.3", "classnames": "^2.5.1", "cryptr": "^6.3.0", + "hsb-dashboard": "file:", "jsonwebtoken": "^9.0.2", "jwk-to-pem": "^2.0.5", "jws": "^4.0.0", @@ -3224,6 +3225,10 @@ "minimalistic-crypto-utils": "^1.0.1" } }, + "node_modules/hsb-dashboard": { + "resolved": "", + "link": true + }, "node_modules/ignore": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", diff --git a/src/dashboard/package.json b/src/dashboard/package.json index 3fce8ca6..c5d655e7 100644 --- a/src/dashboard/package.json +++ b/src/dashboard/package.json @@ -20,6 +20,7 @@ "chart.js": "^4.4.3", "classnames": "^2.5.1", "cryptr": "^6.3.0", + "hsb-dashboard": "file:", "jsonwebtoken": "^9.0.2", "jwk-to-pem": "^2.0.5", "jws": "^4.0.0", diff --git a/src/dashboard/src/hooks/api/useApiServerItems.ts b/src/dashboard/src/hooks/api/useApiServerItems.ts index de2c59fd..143a3f12 100644 --- a/src/dashboard/src/hooks/api/useApiServerItems.ts +++ b/src/dashboard/src/hooks/api/useApiServerItems.ts @@ -31,7 +31,7 @@ export const useApiServerItems = () => { }, history: async (filter: IServerHistoryItemFilter | undefined = {}): Promise => { return await dispatch(`/api/dashboard/server-items/history?${toQueryString(filter)}`, { - cache: 'force-cache', + cache: 'no-store', }); }, download: async ( diff --git a/src/dashboard/src/utils/dispatch.ts b/src/dashboard/src/utils/dispatch.ts index 060af169..48a11b58 100644 --- a/src/dashboard/src/utils/dispatch.ts +++ b/src/dashboard/src/utils/dispatch.ts @@ -6,7 +6,9 @@ export const dispatch = async ( ): Promise => { const response = await fetch(input, init); // If they are unauthenticated when making requests to the API then their token is expired. - if (response.status === 401) signOut(); + if (response.status === 401) { + signOut(); + } // Throw an error so that it bubbles out. if (!response.ok) { diff --git a/src/libs/dal/Services/IOperatingSystemItem.cs b/src/libs/dal/Services/IOperatingSystemItem.cs index ab50dc7b..57cbdf67 100644 --- a/src/libs/dal/Services/IOperatingSystemItem.cs +++ b/src/libs/dal/Services/IOperatingSystemItem.cs @@ -1,5 +1,5 @@ using HSB.Entities; -using HSB.Models; +using HSB.Models.Lists; namespace HSB.DAL.Services; diff --git a/src/libs/dal/Services/IOrganizationService.cs b/src/libs/dal/Services/IOrganizationService.cs index fd6c626e..9fcdcac8 100644 --- a/src/libs/dal/Services/IOrganizationService.cs +++ b/src/libs/dal/Services/IOrganizationService.cs @@ -1,5 +1,5 @@ using HSB.Entities; -using HSB.Models; +using HSB.Models.Lists; namespace HSB.DAL.Services; diff --git a/src/libs/dal/Services/IServerItemService.cs b/src/libs/dal/Services/IServerItemService.cs index 00d9bf85..c89d7460 100644 --- a/src/libs/dal/Services/IServerItemService.cs +++ b/src/libs/dal/Services/IServerItemService.cs @@ -1,6 +1,6 @@ using HSB.Entities; -using HSB.Models; using HSB.Models.Filters; +using HSB.Models.Lists; using Microsoft.EntityFrameworkCore.ChangeTracking; namespace HSB.DAL.Services; diff --git a/src/libs/dal/Services/ITenantService.cs b/src/libs/dal/Services/ITenantService.cs index cd7c2bdc..2bacb039 100644 --- a/src/libs/dal/Services/ITenantService.cs +++ b/src/libs/dal/Services/ITenantService.cs @@ -1,5 +1,5 @@ using HSB.Entities; -using HSB.Models; +using HSB.Models.Lists; namespace HSB.DAL.Services; diff --git a/src/libs/dal/Services/OperatingSystemItemService.cs b/src/libs/dal/Services/OperatingSystemItemService.cs index 4b09ca89..49ad5202 100644 --- a/src/libs/dal/Services/OperatingSystemItemService.cs +++ b/src/libs/dal/Services/OperatingSystemItemService.cs @@ -1,6 +1,7 @@ using System.Security.Claims; using HSB.DAL.Extensions; using HSB.Entities; +using HSB.Models.Lists; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; @@ -77,7 +78,7 @@ where userOrganizationQuery.Contains(si.OrganizationId) || userTenantQuery.Conta .ToArray(); } - public IEnumerable FindList( + public IEnumerable FindList( Models.Filters.OperatingSystemItemFilter filter) { var query = from osi in this.Context.OperatingSystemItems @@ -97,11 +98,11 @@ where userOrganizationQuery.Contains(si.OrganizationId) || userTenantQuery.Conta return query .AsNoTracking() .AsSingleQuery() - .Select(t => new Models.OperatingSystemItemListModel(t)) + .Select(t => new OperatingSystemItemListModel(t)) .ToArray(); } - public IEnumerable FindListForUser( + public IEnumerable FindListForUser( long userId, Models.Filters.OperatingSystemItemFilter filter) { @@ -136,7 +137,7 @@ where userOrganizationQuery.Contains(si.OrganizationId) || userTenantQuery.Conta return query .AsNoTracking() .AsSplitQuery() - .Select(t => new Models.OperatingSystemItemListModel(t)) + .Select(t => new OperatingSystemItemListModel(t)) .ToArray(); } #endregion diff --git a/src/libs/dal/Services/OrganizationService.cs b/src/libs/dal/Services/OrganizationService.cs index da55fc12..65fd92e3 100644 --- a/src/libs/dal/Services/OrganizationService.cs +++ b/src/libs/dal/Services/OrganizationService.cs @@ -5,6 +5,7 @@ using HSB.Entities; using HSB.DAL.Extensions; +using HSB.Models.Lists; namespace HSB.DAL.Services; @@ -90,7 +91,7 @@ where userOrganizationQuery.Contains(org.Id) || tenantOrganizationQuery.Contains .AsSplitQuery() .ToArray(); } - public IEnumerable FindList(Models.Filters.OrganizationFilter filter) + public IEnumerable FindList(Models.Filters.OrganizationFilter filter) { var query = from org in this.Context.Organizations select org; @@ -112,11 +113,11 @@ where userOrganizationQuery.Contains(org.Id) || tenantOrganizationQuery.Contains return query .AsNoTracking() .AsSingleQuery() - .Select(o => new Models.OrganizationListModel(o, true, false)) + .Select(o => new OrganizationListModel(o, true, false)) .ToArray(); } - public IEnumerable FindListForUser( + public IEnumerable FindListForUser( long userId, Models.Filters.OrganizationFilter filter) { @@ -150,7 +151,7 @@ where userOrganizationQuery.Contains(org.Id) || tenantOrganizationQuery.Contains return query .AsNoTracking() .AsSplitQuery() - .Select(o => new Models.OrganizationListModel(o, true, false)) + .Select(o => new OrganizationListModel(o, true, false)) .ToArray(); } diff --git a/src/libs/dal/Services/ServerItemService.cs b/src/libs/dal/Services/ServerItemService.cs index 2264ff73..c3ca188d 100644 --- a/src/libs/dal/Services/ServerItemService.cs +++ b/src/libs/dal/Services/ServerItemService.cs @@ -1,8 +1,8 @@ using System.Security.Claims; using HSB.DAL.Extensions; using HSB.Entities; -using HSB.Models; using HSB.Models.Filters; +using HSB.Models.Lists; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.Extensions.Logging; diff --git a/src/libs/dal/Services/TenantService.cs b/src/libs/dal/Services/TenantService.cs index c1aeff49..33544acb 100644 --- a/src/libs/dal/Services/TenantService.cs +++ b/src/libs/dal/Services/TenantService.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using HSB.DAL.Extensions; +using HSB.Models.Lists; namespace HSB.DAL.Services; @@ -102,7 +103,7 @@ where userTenantQuery.Contains(tenant.Id) || tenantOrganizationQuery.Contains(te .ToArray(); } - public IEnumerable FindList( + public IEnumerable FindList( Models.Filters.TenantFilter filter) { var query = from tenant in this.Context.Tenants @@ -125,11 +126,11 @@ where userTenantQuery.Contains(tenant.Id) || tenantOrganizationQuery.Contains(te return query .AsNoTracking() .AsSingleQuery() - .Select(t => new Models.TenantListModel(t, true)) + .Select(t => new TenantListModel(t, true)) .ToArray(); } - public IEnumerable FindListForUser( + public IEnumerable FindListForUser( long userId, Models.Filters.TenantFilter filter) { @@ -163,7 +164,7 @@ where userTenantQuery.Contains(tenant.Id) || tenantOrganizationQuery.Contains(te return query .AsNoTracking() .AsSplitQuery() - .Select(t => new Models.TenantListModel(t, true)) + .Select(t => new TenantListModel(t, true)) .ToArray(); } diff --git a/src/libs/models/Dashboard/FileSystemHistoryItemModel.cs b/src/libs/models/Dashboard/FileSystemHistoryItemModel.cs new file mode 100644 index 00000000..90736ab8 --- /dev/null +++ b/src/libs/models/Dashboard/FileSystemHistoryItemModel.cs @@ -0,0 +1,159 @@ +using System.Text.Json; +using HSB.Entities; + +namespace HSB.Models.Dashboard; + +public class FileSystemHistoryItemModel : AuditableModel +{ + #region Properties + public long Id { get; set; } + + #region ServiceNow Properties + public JsonDocument RawData { get; set; } = JsonDocument.Parse("{}"); + public JsonDocument RawDataCI { get; set; } = JsonDocument.Parse("{}"); + public string ServiceNowKey { get; set; } = ""; + public string ServerItemServiceNowKey { get; set; } = ""; + public string ClassName { get; set; } = ""; + public string Name { get; set; } = ""; + public int InstallStatus { get; set; } + public string Label { get; set; } = ""; + public string Category { get; set; } = ""; + public string Subcategory { get; set; } = ""; + public string StorageType { get; set; } = ""; + public string MediaType { get; set; } = ""; + public string VolumeId { get; set; } = ""; + public int Capacity { get; set; } + public float DiskSpace { get; set; } + public string Size { get; set; } = ""; + public long SizeBytes { get; set; } + public long? UsedSizeBytes { get; set; } + public int AvailableSpace { get; set; } + public string FreeSpace { get; set; } = ""; + public long FreeSpaceBytes { get; set; } + #endregion + #endregion + + #region Constructors + public FileSystemHistoryItemModel() { } + + public FileSystemHistoryItemModel(FileSystemHistoryItem entity) : base(entity) + { + this.Id = entity.Id; + + this.ServiceNowKey = entity.ServiceNowKey; + this.ServerItemServiceNowKey = entity.ServerItemServiceNowKey; + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Label = entity.Label; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.StorageType = entity.StorageType; + this.MediaType = entity.MediaType; + this.VolumeId = entity.VolumeId; + this.Capacity = entity.Capacity; + this.DiskSpace = entity.DiskSpace; + this.Size = entity.Size; + this.SizeBytes = entity.SizeBytes; + this.UsedSizeBytes = entity.UsedSizeBytes; + this.AvailableSpace = entity.AvailableSpace; + this.FreeSpace = entity.FreeSpace; + this.FreeSpaceBytes = entity.FreeSpaceBytes; + } + + public FileSystemHistoryItemModel(FileSystemHistoryItemSmall entity) : base(entity) + { + this.Id = entity.Id; + + this.ServiceNowKey = entity.ServiceNowKey; + this.ServerItemServiceNowKey = entity.ServerItemServiceNowKey; + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Label = entity.Label; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.StorageType = entity.StorageType; + this.MediaType = entity.MediaType; + this.VolumeId = entity.VolumeId; + this.Capacity = entity.Capacity; + this.DiskSpace = entity.DiskSpace; + this.Size = entity.Size; + this.SizeBytes = entity.SizeBytes; + this.UsedSizeBytes = entity.UsedSizeBytes; + this.AvailableSpace = entity.AvailableSpace; + this.FreeSpace = entity.FreeSpace; + this.FreeSpaceBytes = entity.FreeSpaceBytes; + } + + public FileSystemHistoryItemModel( + string ServerItemServiceNowKey, + ServiceNow.ResultModel fileSystemItemModel, + ServiceNow.ResultModel configurationItemModel) + { + if (fileSystemItemModel.Data == null) throw new InvalidOperationException("File System Item data cannot be null"); + if (configurationItemModel.Data == null) throw new InvalidOperationException("Configuration item data cannot be null"); + + this.ServiceNowKey = fileSystemItemModel.Data.Id; + this.ServerItemServiceNowKey = ServerItemServiceNowKey; + + this.ClassName = fileSystemItemModel.Data.ClassName ?? ""; + this.Name = fileSystemItemModel.Data.Name ?? ""; + this.InstallStatus = int.Parse(fileSystemItemModel.Data.InstallStatus ?? "0"); + this.Label = fileSystemItemModel.Data.Label ?? ""; + this.Category = fileSystemItemModel.Data.Category ?? ""; + this.Subcategory = fileSystemItemModel.Data.Subcategory ?? ""; + this.StorageType = fileSystemItemModel.Data.StorageType ?? ""; + this.MediaType = fileSystemItemModel.Data.MediaType ?? ""; + this.VolumeId = fileSystemItemModel.Data.VolumeId ?? ""; + this.Capacity = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.Capacity) ? Int32.Parse(fileSystemItemModel.Data.Capacity) : 0; + this.DiskSpace = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.DiskSpace) ? float.Parse(fileSystemItemModel.Data.DiskSpace) : 0; + this.Size = fileSystemItemModel.Data.Size ?? ""; + this.SizeBytes = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.SizeBytes) ? long.Parse(fileSystemItemModel.Data.SizeBytes) : 0; + this.UsedSizeBytes = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.UsedSizeBytes) ? long.Parse(fileSystemItemModel.Data.UsedSizeBytes) : null; + this.AvailableSpace = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.AvailableSpace) ? Int32.Parse(fileSystemItemModel.Data.AvailableSpace) : 0; + this.FreeSpace = fileSystemItemModel.Data.FreeSpace ?? ""; + this.FreeSpaceBytes = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.FreeSpaceBytes) ? long.Parse(fileSystemItemModel.Data.FreeSpaceBytes) : 0; + } + #endregion + + #region Methods + public FileSystemHistoryItem ToEntity() + { + return (FileSystemHistoryItem)this; + } + + public static explicit operator FileSystemHistoryItem(FileSystemHistoryItemModel model) + { + if (model.RawData == null) throw new InvalidOperationException("Property 'RawData' is required."); + + return new FileSystemHistoryItem(model.ServerItemServiceNowKey, model.RawData, model.RawDataCI) + { + Id = model.Id, + ServiceNowKey = model.ServiceNowKey, + ClassName = model.ClassName, + Name = model.Name, + InstallStatus = model.InstallStatus, + Label = model.Label, + Category = model.Category, + Subcategory = model.Subcategory, + StorageType = model.StorageType, + MediaType = model.MediaType, + VolumeId = model.VolumeId, + Capacity = model.Capacity, + DiskSpace = model.DiskSpace, + Size = model.Size, + SizeBytes = model.SizeBytes, + UsedSizeBytes = model.UsedSizeBytes, + AvailableSpace = model.AvailableSpace, + FreeSpace = model.FreeSpace, + FreeSpaceBytes = model.FreeSpaceBytes, + CreatedOn = model.CreatedOn, + CreatedBy = model.CreatedBy, + UpdatedOn = model.UpdatedOn, + UpdatedBy = model.UpdatedBy, + Version = model.Version, + }; + } + #endregion +} diff --git a/src/libs/models/Dashboard/FileSystemItemModel.cs b/src/libs/models/Dashboard/FileSystemItemModel.cs new file mode 100644 index 00000000..50990494 --- /dev/null +++ b/src/libs/models/Dashboard/FileSystemItemModel.cs @@ -0,0 +1,130 @@ +using System.Text.Json; +using HSB.Entities; + +namespace HSB.Models.Dashboard; + +public class FileSystemItemModel : AuditableModel +{ + #region Properties + public string ServiceNowKey { get; set; } = ""; + public string ServerItemServiceNowKey { get; set; } = ""; + + #region ServiceNow Properties + public JsonDocument RawData { get; set; } = JsonDocument.Parse("{}"); + public JsonDocument RawDataCI { get; set; } = JsonDocument.Parse("{}"); + public string ClassName { get; set; } = ""; + public string Name { get; set; } = ""; + public int InstallStatus { get; set; } + public string Label { get; set; } = ""; + public string Category { get; set; } = ""; + public string Subcategory { get; set; } = ""; + public string StorageType { get; set; } = ""; + public string MediaType { get; set; } = ""; + public string VolumeId { get; set; } = ""; + public int Capacity { get; set; } + public float DiskSpace { get; set; } + public string Size { get; set; } = ""; + public long SizeBytes { get; set; } + public long? UsedSizeBytes { get; set; } + public int AvailableSpace { get; set; } + public string FreeSpace { get; set; } = ""; + public long FreeSpaceBytes { get; set; } + #endregion + #endregion + + #region Constructors + public FileSystemItemModel() { } + + public FileSystemItemModel(FileSystemItem entity) : base(entity) + { + this.ServiceNowKey = entity.ServiceNowKey; + this.ServerItemServiceNowKey = entity.ServerItemServiceNowKey; + + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Label = entity.Label; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.StorageType = entity.StorageType; + this.MediaType = entity.MediaType; + this.VolumeId = entity.VolumeId; + this.Capacity = entity.Capacity; + this.DiskSpace = entity.DiskSpace; + this.Size = entity.Size; + this.SizeBytes = entity.SizeBytes; + this.UsedSizeBytes = entity.UsedSizeBytes; + this.AvailableSpace = entity.AvailableSpace; + this.FreeSpace = entity.FreeSpace; + this.FreeSpaceBytes = entity.FreeSpaceBytes; + } + + public FileSystemItemModel(string serverItemServiceNowKey + , ServiceNow.ResultModel fileSystemItemModel + , ServiceNow.ResultModel configurationItemModel) + { + if (fileSystemItemModel.Data == null) throw new InvalidOperationException("File System Item data cannot be null"); + if (configurationItemModel.Data == null) throw new InvalidOperationException("Configuration item data cannot be null"); + + this.ServiceNowKey = fileSystemItemModel.Data.Id; + this.ServerItemServiceNowKey = serverItemServiceNowKey; + + this.ClassName = fileSystemItemModel.Data.ClassName ?? ""; + this.Name = fileSystemItemModel.Data.Name ?? ""; + this.InstallStatus = int.Parse(fileSystemItemModel.Data.InstallStatus ?? "0"); + this.Label = fileSystemItemModel.Data.Label ?? ""; + this.Category = fileSystemItemModel.Data.Category ?? ""; + this.Subcategory = fileSystemItemModel.Data.Subcategory ?? ""; + this.StorageType = fileSystemItemModel.Data.StorageType ?? ""; + this.MediaType = fileSystemItemModel.Data.MediaType ?? ""; + this.VolumeId = fileSystemItemModel.Data.VolumeId ?? ""; + this.Capacity = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.Capacity) ? Int32.Parse(fileSystemItemModel.Data.Capacity) : 0; + this.DiskSpace = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.DiskSpace) ? float.Parse(fileSystemItemModel.Data.DiskSpace) : 0; + this.Size = fileSystemItemModel.Data.Size ?? ""; + this.SizeBytes = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.SizeBytes) ? long.Parse(fileSystemItemModel.Data.SizeBytes) : 0; + this.UsedSizeBytes = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.UsedSizeBytes) ? long.Parse(fileSystemItemModel.Data.UsedSizeBytes) : null; + this.AvailableSpace = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.AvailableSpace) ? Int32.Parse(fileSystemItemModel.Data.AvailableSpace) : 0; + this.FreeSpace = fileSystemItemModel.Data.FreeSpace ?? ""; + this.FreeSpaceBytes = !String.IsNullOrWhiteSpace(fileSystemItemModel.Data.FreeSpaceBytes) ? long.Parse(fileSystemItemModel.Data.FreeSpaceBytes) : 0; + } + #endregion + + #region Methods + public FileSystemItem ToEntity() + { + return (FileSystemItem)this; + } + + public static explicit operator FileSystemItem(FileSystemItemModel model) + { + if (model.RawData == null) throw new InvalidOperationException("Property 'RawData' is required."); + + return new FileSystemItem(model.ServerItemServiceNowKey, model.RawData, model.RawDataCI) + { + ServiceNowKey = model.ServiceNowKey, + ClassName = model.ClassName, + Name = model.Name, + InstallStatus = model.InstallStatus, + Label = model.Label, + Category = model.Category, + Subcategory = model.Subcategory, + StorageType = model.StorageType, + MediaType = model.MediaType, + VolumeId = model.VolumeId, + Capacity = model.Capacity, + DiskSpace = model.DiskSpace, + Size = model.Size, + SizeBytes = model.SizeBytes, + UsedSizeBytes = model.UsedSizeBytes, + AvailableSpace = model.AvailableSpace, + FreeSpace = model.FreeSpace, + FreeSpaceBytes = model.FreeSpaceBytes, + CreatedOn = model.CreatedOn, + CreatedBy = model.CreatedBy, + UpdatedOn = model.UpdatedOn, + UpdatedBy = model.UpdatedBy, + Version = model.Version, + }; + } + #endregion +} diff --git a/src/libs/models/Dashboard/OperatingSystemItemModel.cs b/src/libs/models/Dashboard/OperatingSystemItemModel.cs new file mode 100644 index 00000000..3c8ba1cc --- /dev/null +++ b/src/libs/models/Dashboard/OperatingSystemItemModel.cs @@ -0,0 +1,58 @@ +using System.Text.Json; +using HSB.Entities; + +namespace HSB.Models.Dashboard; + +public class OperatingSystemItemModel : AuditableModel +{ + #region Properties + public int Id { get; set; } + public JsonDocument? RawData { get; set; } + + #region ServiceNow Properties + public string ServiceNowKey { get; set; } = ""; + public string Name { get; set; } = ""; + #endregion + #endregion + + #region Constructors + public OperatingSystemItemModel() { } + + public OperatingSystemItemModel(OperatingSystemItem entity) : base(entity) + { + this.Id = entity.Id; + this.ServiceNowKey = entity.ServiceNowKey; + this.Name = entity.Name; + } + + public OperatingSystemItemModel(ServiceNow.ResultModel model) + { + if (model.Data == null) throw new InvalidOperationException("Operating System data cannot be null"); + + this.ServiceNowKey = model.Data.Id; + this.Name = model.Data.Name ?? ""; + } + #endregion + + #region Methods + public OperatingSystemItem ToEntity() + { + return (OperatingSystemItem)this; + } + + public static explicit operator OperatingSystemItem(OperatingSystemItemModel model) + { + if (model.RawData == null) throw new InvalidOperationException("Property 'RawData' is required."); + + return new OperatingSystemItem(model.RawData) + { + Id = model.Id, + CreatedOn = model.CreatedOn, + CreatedBy = model.CreatedBy, + UpdatedOn = model.UpdatedOn, + UpdatedBy = model.UpdatedBy, + Version = model.Version, + }; + } + #endregion +} diff --git a/src/libs/models/Dashboard/OrganizationModel.cs b/src/libs/models/Dashboard/OrganizationModel.cs new file mode 100644 index 00000000..246e4543 --- /dev/null +++ b/src/libs/models/Dashboard/OrganizationModel.cs @@ -0,0 +1,77 @@ +using System.Text.Json; +using HSB.Entities; + +namespace HSB.Models.Dashboard; +public class OrganizationModel : SortableCodeAuditableModel +{ + #region Properties + public int? ParentId { get; set; } + public OrganizationModel? Parent { get; set; } + public JsonDocument? RawData { get; set; } + + /// + /// get/set - The ServiceNow tenant key. + /// + public string ServiceNowKey { get; set; } = ""; + public IEnumerable Children { get; set; } = Array.Empty(); + + public IEnumerable Tenants { get; set; } = Array.Empty(); + #endregion + + #region Constructors + public OrganizationModel() { } + + public OrganizationModel(Organization entity, bool includeTenants, bool includeChildren = false) : base(entity) + { + this.Id = entity.Id; + this.ParentId = entity.ParentId; + if (!includeChildren) this.Parent = entity.Parent != null ? new OrganizationModel(entity.Parent, false) : null; + if (includeChildren) this.Children = entity.Children.Select(c => new OrganizationModel(c, false)); + + if (includeTenants) + { + this.Tenants = entity.TenantsManyToMany.Any() ? entity.TenantsManyToMany.Where(t => t.Tenant != null).Select(t => new TenantModel(t.Tenant!, false)).ToArray() : this.Tenants; + this.Tenants = entity.Tenants.Any() ? entity.Tenants.Select(t => new TenantModel(t, false)).ToArray() : this.Tenants; + } + + this.ServiceNowKey = entity.ServiceNowKey; + } + + public OrganizationModel(ServiceNow.ResultModel model) + { + if (model.Data == null) throw new InvalidOperationException("Organization data cannot be null"); + + this.Name = model.Data.Name ?? ""; + this.Code = model.Data.OrganizationCode ?? Guid.NewGuid().ToString(); + this.ServiceNowKey = model.Data.Id; + } + #endregion + + #region Methods + public Organization ToEntity() + { + return (Organization)this; + } + + public static explicit operator Organization(OrganizationModel model) + { + if (model.RawData == null) throw new InvalidOperationException("Property 'RawData' is required."); + + var entity = new Organization(model.Name) + { + Id = model.Id, + Description = model.Description, + Code = model.Code, + ParentId = model.ParentId, + ServiceNowKey = model.ServiceNowKey, + RawData = model.RawData, + IsEnabled = model.IsEnabled, + SortOrder = model.SortOrder, + Version = model.Version, + }; + entity.TenantsManyToMany.AddRange(model.Tenants.Select(t => new TenantOrganization(t.Id, entity.Id))); + + return entity; + } + #endregion +} diff --git a/src/libs/models/Dashboard/ServerHistoryItemModel.cs b/src/libs/models/Dashboard/ServerHistoryItemModel.cs new file mode 100644 index 00000000..f19b733d --- /dev/null +++ b/src/libs/models/Dashboard/ServerHistoryItemModel.cs @@ -0,0 +1,157 @@ +using System.Text.Json; +using HSB.Entities; +using System.Text.Json.Serialization; + +namespace HSB.Models.Dashboard; + +public class ServerHistoryItemModel : AuditableModel +{ + #region Properties + public long Id { get; set; } + public int? TenantId { get; set; } + public TenantModel? Tenant { get; set; } + public int OrganizationId { get; set; } + public OrganizationModel? Organization { get; set; } + public int? OperatingSystemItemId { get; set; } + public OperatingSystemItemModel? OperatingSystem { get; set; } + + #region ServiceNow Properties + public JsonDocument RawData { get; set; } = JsonDocument.Parse("{}"); + public JsonDocument RawDataCI { get; set; } = JsonDocument.Parse("{}"); + public string ServiceNowKey { get; set; } = ""; + public string ClassName { get; set; } = ""; + public string Name { get; set; } = ""; + public int InstallStatus { get; set; } + public string Category { get; set; } = ""; + public string Subcategory { get; set; } = ""; + public string DnsDomain { get; set; } = ""; + public string Platform { get; set; } = ""; + + [JsonPropertyName("ipAddress")] + public string IPAddress { get; set; } = ""; + + [JsonPropertyName("fqdn")] + public string FQDN { get; set; } = ""; + public float? DiskSpace { get; set; } + #endregion + + #region ServiceNow File System Item Summary Properties + public float? Capacity { get; set; } + public float? AvailableSpace { get; set; } + #endregion + #endregion + + #region Constructors + public ServerHistoryItemModel() { } + + public ServerHistoryItemModel(ServerHistoryItem entity) : base(entity) + { + this.Id = entity.Id; + + this.TenantId = entity.TenantId; + this.OrganizationId = entity.OrganizationId; + this.OperatingSystemItemId = entity.OperatingSystemItemId; + + this.ServiceNowKey = entity.ServiceNowKey; + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.DnsDomain = entity.DnsDomain; + this.Platform = entity.Platform; + this.IPAddress = entity.IPAddress; + this.FQDN = entity.FQDN; + this.DiskSpace = entity.DiskSpace; + + this.Capacity = entity.Capacity; + this.AvailableSpace = entity.AvailableSpace; + } + + public ServerHistoryItemModel(ServerHistoryItemSmall entity) : base(entity) + { + this.Id = entity.Id; + + this.TenantId = entity.TenantId; + this.OrganizationId = entity.OrganizationId; + this.OperatingSystemItemId = entity.OperatingSystemItemId; + + this.ServiceNowKey = entity.ServiceNowKey; + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.DnsDomain = entity.DnsDomain; + this.Platform = entity.Platform; + this.IPAddress = entity.IPAddress; + this.FQDN = entity.FQDN; + this.DiskSpace = entity.DiskSpace; + + this.Capacity = entity.Capacity; + this.AvailableSpace = entity.AvailableSpace; + } + + public ServerHistoryItemModel( + int? tenantId, + int organizationId, + int? operatingSystemItemId, + ServiceNow.ResultModel serverModel, + ServiceNow.ResultModel ciModel) + { + if (serverModel.Data == null) throw new InvalidOperationException("Server data cannot be null"); + if (ciModel.Data == null) throw new InvalidOperationException("Configuration item data cannot be null"); + + this.TenantId = tenantId; + this.OrganizationId = organizationId; + this.OperatingSystemItemId = operatingSystemItemId; + + this.ServiceNowKey = serverModel.Data.Id; + this.ClassName = serverModel.Data.ClassName ?? ""; + this.Name = serverModel.Data.Name ?? ""; + this.InstallStatus = int.Parse(serverModel.Data.InstallStatus ?? "0"); + this.Category = serverModel.Data.Category ?? ""; + this.Subcategory = serverModel.Data.Subcategory ?? ""; + this.DnsDomain = serverModel.Data.DnsDomain ?? ""; + this.Platform = serverModel.Data.Platform ?? ""; + this.IPAddress = serverModel.Data.IPAddress ?? ""; + this.FQDN = serverModel.Data.FQDN ?? ""; + this.DiskSpace = !String.IsNullOrWhiteSpace(serverModel.Data.DiskSpace) ? float.Parse(serverModel.Data.DiskSpace) : null; + } + #endregion + + #region Methods + public ServerHistoryItem ToEntity() + { + return (ServerHistoryItem)this; + } + + public static explicit operator ServerHistoryItem(ServerHistoryItemModel model) + { + if (model.RawData == null) throw new InvalidOperationException("Property 'RawData' is required."); + + return new ServerHistoryItem(model.TenantId, model.OrganizationId, model.OperatingSystemItemId, model.RawData, model.RawDataCI) + { + Id = model.Id, + ServiceNowKey = model.ServiceNowKey, + ClassName = model.ClassName, + Name = model.Name, + InstallStatus = model.InstallStatus, + Category = model.Category, + Subcategory = model.Subcategory, + DnsDomain = model.DnsDomain, + Platform = model.Platform, + IPAddress = model.IPAddress, + FQDN = model.FQDN, + DiskSpace = model.DiskSpace, + Capacity = model.Capacity, + AvailableSpace = model.AvailableSpace, + CreatedOn = model.CreatedOn, + CreatedBy = model.CreatedBy, + UpdatedOn = model.UpdatedOn, + UpdatedBy = model.UpdatedBy, + Version = model.Version, + }; + } + #endregion +} diff --git a/src/libs/models/Dashboard/ServerItemModel.cs b/src/libs/models/Dashboard/ServerItemModel.cs new file mode 100644 index 00000000..aea9afae --- /dev/null +++ b/src/libs/models/Dashboard/ServerItemModel.cs @@ -0,0 +1,139 @@ +using System.Text.Json; +using HSB.Entities; +using System.Text.Json.Serialization; + +namespace HSB.Models.Dashboard; + +public class ServerItemModel : AuditableModel +{ + #region Properties + public string ServiceNowKey { get; set; } = ""; + public Guid? HistoryKey { get; set; } + + public int? TenantId { get; set; } + public TenantModel? Tenant { get; set; } + public int OrganizationId { get; set; } + public OrganizationModel? Organization { get; set; } + public int? OperatingSystemItemId { get; set; } + public OperatingSystemItemModel? OperatingSystem { get; set; } + + public IEnumerable FileSystemItems { get; set; } = Array.Empty(); + + #region ServiceNow Properties + public JsonDocument RawData { get; set; } = JsonDocument.Parse("{}"); + public JsonDocument RawDataCI { get; set; } = JsonDocument.Parse("{}"); + public string ClassName { get; set; } = ""; + public string Name { get; set; } = ""; + public int InstallStatus { get; set; } + public string Category { get; set; } = ""; + public string Subcategory { get; set; } = ""; + public string DnsDomain { get; set; } = ""; + public string Platform { get; set; } = ""; + + [JsonPropertyName("ipAddress")] + public string IPAddress { get; set; } = ""; + + [JsonPropertyName("fqdn")] + public string FQDN { get; set; } = ""; + public float? DiskSpace { get; set; } + #endregion + + #region ServiceNow File System Item Summary Properties + public float? Capacity { get; set; } + public float? AvailableSpace { get; set; } + #endregion + #endregion + + #region Constructors + public ServerItemModel() { } + + public ServerItemModel(ServerItem entity) : base(entity) + { + this.ServiceNowKey = entity.ServiceNowKey; + this.HistoryKey = entity.HistoryKey; + + this.TenantId = entity.TenantId; + this.OrganizationId = entity.OrganizationId; + this.OperatingSystemItemId = entity.OperatingSystemItemId; + + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.DnsDomain = entity.DnsDomain; + this.Platform = entity.Platform; + this.IPAddress = entity.IPAddress; + this.FQDN = entity.FQDN; + this.DiskSpace = entity.DiskSpace; + + this.Capacity = entity.Capacity; + this.AvailableSpace = entity.AvailableSpace; + + this.FileSystemItems = entity.FileSystemItems.Select(fsi => new FileSystemItemModel(fsi)).ToArray(); + } + + public ServerItemModel( + int? tenantId, + int organizationId, + int? operatingSystemItemId, + ServiceNow.ResultModel serverModel, + ServiceNow.ResultModel ciModel) + { + if (serverModel.Data == null) throw new InvalidOperationException("Server data cannot be null"); + if (ciModel.Data == null) throw new InvalidOperationException("Configuration item data cannot be null"); + + this.ServiceNowKey = serverModel.Data.Id; + + this.TenantId = tenantId; + this.OrganizationId = organizationId; + this.OperatingSystemItemId = operatingSystemItemId; + + this.ClassName = serverModel.Data.ClassName ?? ""; + this.Name = serverModel.Data.Name ?? ""; + this.InstallStatus = int.Parse(serverModel.Data.InstallStatus ?? "0"); + this.Category = serverModel.Data.Category ?? ""; + this.Subcategory = serverModel.Data.Subcategory ?? ""; + this.DnsDomain = serverModel.Data.DnsDomain ?? ""; + this.Platform = serverModel.Data.Platform ?? ""; + this.IPAddress = serverModel.Data.IPAddress ?? ""; + this.FQDN = serverModel.Data.FQDN ?? ""; + this.DiskSpace = !String.IsNullOrWhiteSpace(serverModel.Data.DiskSpace) ? float.Parse(serverModel.Data.DiskSpace) : null; + } + #endregion + + #region Methods + public ServerItem ToEntity() + { + return (ServerItem)this; + } + + public static explicit operator ServerItem(ServerItemModel model) + { + if (model.RawData == null) throw new InvalidOperationException("Property 'RawData' is required."); + + return new ServerItem(model.TenantId, model.OrganizationId, model.OperatingSystemItemId, model.RawData, model.RawDataCI) + { + ServiceNowKey = model.ServiceNowKey, + HistoryKey = model.HistoryKey, + ClassName = model.ClassName, + Name = model.Name, + InstallStatus = model.InstallStatus, + Category = model.Category, + Subcategory = model.Subcategory, + DnsDomain = model.DnsDomain, + Platform = model.Platform, + IPAddress = model.IPAddress, + FQDN = model.FQDN, + DiskSpace = model.DiskSpace, + Capacity = model.Capacity, + AvailableSpace = model.AvailableSpace, + CreatedOn = model.CreatedOn, + CreatedBy = model.CreatedBy, + UpdatedOn = model.UpdatedOn, + UpdatedBy = model.UpdatedBy, + Version = model.Version, + }; + } + #endregion +} diff --git a/src/libs/models/Dashboard/TenantModel.cs b/src/libs/models/Dashboard/TenantModel.cs new file mode 100644 index 00000000..73b81d6d --- /dev/null +++ b/src/libs/models/Dashboard/TenantModel.cs @@ -0,0 +1,76 @@ +using System.Text.Json; +using HSB.Entities; + +namespace HSB.Models.Dashboard; +public class TenantModel : SortableCodeAuditableModel +{ + #region Properties + public JsonDocument? RawData { get; set; } + + /// + /// get/set - The ServiceNow tenant key. + /// + public string ServiceNowKey { get; set; } = ""; + + /// + /// get/set - An array of organizations. + /// + public IEnumerable Organizations { get; set; } = Array.Empty(); + #endregion + + #region Constructors + public TenantModel() { } + + public TenantModel(Tenant entity, bool includeOrganizations) : base(entity) + { + this.Id = entity.Id; + + this.ServiceNowKey = entity.ServiceNowKey; + + if (includeOrganizations) + { + this.Organizations = entity.OrganizationsManyToMany.Any() ? entity.OrganizationsManyToMany.Where(o => o.Organization != null).Select(o => new OrganizationModel(o.Organization!, false)) : this.Organizations; + this.Organizations = entity.Organizations.Any() ? entity.Organizations.Select(o => new OrganizationModel(o, false)) : this.Organizations; + } + } + + public TenantModel(ServiceNow.ResultModel model, IEnumerable organizations) + { + if (model.Data == null) throw new InvalidOperationException("Tenant data cannot be null"); + + this.Name = model.Data.Name ?? model.Data.SysName ?? ""; + this.Code = model.Data.SysName ?? Guid.NewGuid().ToString(); + this.ServiceNowKey = model.Data.Id; + + this.Organizations = organizations; + } + #endregion + + #region Methods + public Tenant ToEntity() + { + return (Tenant)this; + } + + public static explicit operator Tenant(TenantModel model) + { + if (model.RawData == null) throw new InvalidOperationException("Property 'RawData' is required."); + + var tenant = new Tenant(model.Name) + { + Id = model.Id, + Description = model.Description, + Code = model.Code, + ServiceNowKey = model.ServiceNowKey, + RawData = model.RawData, + IsEnabled = model.IsEnabled, + SortOrder = model.SortOrder, + Version = model.Version, + }; + + tenant.OrganizationsManyToMany.AddRange(model.Organizations.Select(o => new TenantOrganization(model.Id, o.Id))); + + return tenant; + } + #endregion +} diff --git a/src/libs/models/Lists/FileSystemItemListModel.cs b/src/libs/models/Lists/FileSystemItemListModel.cs index 3ac8e467..9d2b60dd 100644 --- a/src/libs/models/Lists/FileSystemItemListModel.cs +++ b/src/libs/models/Lists/FileSystemItemListModel.cs @@ -1,6 +1,6 @@ using HSB.Entities; -namespace HSB.Models; +namespace HSB.Models.Lists; public class FileSystemItemListModel : AuditableModel { #region Properties diff --git a/src/libs/models/Lists/OperatingSystemItemListModel.cs b/src/libs/models/Lists/OperatingSystemItemListModel.cs index 77b7a188..8e415187 100644 --- a/src/libs/models/Lists/OperatingSystemItemListModel.cs +++ b/src/libs/models/Lists/OperatingSystemItemListModel.cs @@ -1,7 +1,7 @@ using HSB.Entities; using HSB.Core.Extensions; -namespace HSB.Models; +namespace HSB.Models.Lists; public class OperatingSystemItemListModel : AuditableModel { #region Properties diff --git a/src/libs/models/Lists/OrganizationListModel.cs b/src/libs/models/Lists/OrganizationListModel.cs index 40af8f64..2db6f9b6 100644 --- a/src/libs/models/Lists/OrganizationListModel.cs +++ b/src/libs/models/Lists/OrganizationListModel.cs @@ -1,6 +1,6 @@ using HSB.Entities; -namespace HSB.Models; +namespace HSB.Models.Lists; public class OrganizationListModel : SortableCodeAuditableModel { #region Properties diff --git a/src/libs/models/Lists/ServerItemListModel.cs b/src/libs/models/Lists/ServerItemListModel.cs index ca684255..63884616 100644 --- a/src/libs/models/Lists/ServerItemListModel.cs +++ b/src/libs/models/Lists/ServerItemListModel.cs @@ -1,7 +1,7 @@ using HSB.Entities; using System.Text.Json.Serialization; -namespace HSB.Models; +namespace HSB.Models.Lists; public class ServerItemListModel { #region Properties diff --git a/src/libs/models/Lists/TenantListModel.cs b/src/libs/models/Lists/TenantListModel.cs index 65edcdf4..e862a5e9 100644 --- a/src/libs/models/Lists/TenantListModel.cs +++ b/src/libs/models/Lists/TenantListModel.cs @@ -1,6 +1,6 @@ using HSB.Entities; -namespace HSB.Models; +namespace HSB.Models.Lists; public class TenantListModel : SortableCodeAuditableModel { #region Properties