ilm.scp.common.lib
1.0.2
dotnet add package ilm.scp.common.lib --version 1.0.2
NuGet\Install-Package ilm.scp.common.lib -Version 1.0.2
<PackageReference Include="ilm.scp.common.lib" Version="1.0.2" />
<PackageVersion Include="ilm.scp.common.lib" Version="1.0.2" />
<PackageReference Include="ilm.scp.common.lib" />
paket add ilm.scp.common.lib --version 1.0.2
#r "nuget: ilm.scp.common.lib, 1.0.2"
#:package ilm.scp.common.lib@1.0.2
#addin nuget:?package=ilm.scp.common.lib&version=1.0.2
#tool nuget:?package=ilm.scp.common.lib&version=1.0.2
SCP Nuget Library
The SCP nuget library contains models, interfaces, helpers, controllers and authorisation for use with ilm Software software development
Models
HttpClientInfo
The HttpClientInfo can be used to store information about the remote client (remote user) and can be used for auditing purposes.
public class HttpClientInfo
{
public string UserId { get; set; } = string.Empty;
public string Username { get; set; } = string.Empty;
public string OrganisationId { get; set; } = string.Empty;
public string LocalIpAddress { get; set; } = string.Empty;
public string RemoteIPAddress { get; set; } = string.Empty;
public string ClientMachine { get; set; } = string.Empty;
}
IdList
The IdList is a list of Guids that can be used to do multiple deletes in EF Core.
public class IdList
{
public List<Guid> Ids { get; set; }
}
MapLngLat
The MapLngLat model is used to store map positions.
public class MapLngLat
{
public MapLngLat() { }
public MapLngLat(float lat, float lng)
{
Lat = lat;
Lng = lng;
}
public float Lat { get; set; } = 0f;
public float Lng { get; set; } = 0f;
}
Interfaces
IAudit
IAudit can be used to enforce auditing withing models
public interface IAudit
{
Guid AuditId { get; set; }
DateTime AuditDate { get; set; }
string AuditIdentityId { get; set; }
string AuditUsername { get; set; }
string AuditMachine { get; set; }
[MaxLength(39)]
string AuditLocalIpAddress { get; set; }
string AuditRemoteIpAddress { get; set; }
string AuditAction { get; set; }
}
IEntity
IEntity is used to enforce a standard structure to objects. When used with EF Core this is useful to make sure all objects are related to an organisation and have the correct standard properties
public interface IEntity
{
#region " Entity base "
Guid Id { get; set; }
Guid OrganisationId { get; set; }
bool IsDeleted { get; set; }
DateTime DateCreated { get; set; }
DateTime LastModified { get; set; }
#endregion
}
IFluentModel
Used in EF Core to create models with custom attributes
public interface IFluentModel
{
ModelBuilder Build(ModelBuilder modelBuilder);
ModelBuilder BuildAudit(ModelBuilder modelBuilder);
}
ISeeder
Used in the latest EF Core (version 9 and later) seeding
public interface ISeeder
{
void Seed(DbContext context, DateTime timestamp);
Task SeedAsync(DbContext context, DateTime timestamp, CancellationToken cancellationToken);
}
IUtilities
Used in the Utilities helper
public interface IUtilities
{
List<Guid> ConvertNullableGuidList(IEnumerable<Guid?> guidList);
IEnumerable<Guid?> ConvertStringToNullableGuidList(string guidList);
IEnumerable<Guid?> ConvertGuidListToNullableGuidList(IEnumerable<Guid> guidList);
}
BaseController
Inherits from ControllerBase for use to extend api controllers with additional functionality
public string OrganisationId
Gets the current organisation id from the list of claims for the authenticated user
public Guid OrganisationIdGuid
Gets the current organisation id from the list of claims for the authenticated user
public string UserId
Gets the current user id from the list of claims for the authenticated user
public string Username
Returns the username for the context of the current controller
public HttpClientInfo ClientInfo
Returns an HttpClientInfo model populated using info from the context of the current controller
Helpers
Useful classes that provide various functionality
HttpHeler
public async Task<T?> Add(HttpContext http, string url, JsonContent body)
Adds an object of type T using the body and url specified
public async Task<bool> Delete(HttpContext http, string url, JsonContent body)
Deletes an object using the body and url specified
public async Task<string> GetJson(HttpContext http, string url)
Gets a json response for a specified url
public async Task<T?> Get(HttpContext http, string url)
Gets an object of type T using the url specified
public async Task<bool> ExecuteGet(HttpContext http, string url)
Executes a get for a specified url that returns a boolean
public async Task<bool> ExecutePost(HttpContext http, string url)
Executes a post for a specified url that returns a boolean
public async Task<IEnumerable<T>?> GetList(HttpContext http, string url)
Gets a list of objects of type T using the specified url
public async Task<IEnumerable<T>?> PostWithBody(HttpContext http, string url, JsonContent body)
Posts a body using a specified url and returns a list of type T
public async Task<bool> PostWithBodyReturnSuccess(HttpContext http, string url, JsonContent body)
Posts a body using a specified url and returns a success boolean
public async Task<bool> PatchReturnSuccess(HttpContext http, string url)
Patches using a specified url and returns a boolean
public async Task<bool> PatchWithBodyReturnSuccess(HttpContext http, string url, JsonContent body)
Patches using a body and specified url and returns a boolean
public async Task<int> GetListCount(HttpContext http, string url)
Gets a count (integer) of items in a list using a specified url
public async Task<bool> Update(HttpContext http, string url, JsonContent body)
Updates an object using a specified body and url and returns a success boolean
public async Task<bool> Update(HttpContext http, string url)
Updates an object using just a specified url and returns a success boolean
Utilities
public List<Guid> ConvertNullableGuidList(IEnumerable<Guid?> guidList)
Converts a list of nullable guids to a standard (non-nullable) list of guids
public IEnumerable<Guid?> ConvertStringToNullableGuidList(string guidList)
Converts a string containing a comma separated list of guids to a list of nullable guids
public IEnumerable<Guid?> ConvertGuidListToNullableGuidList(IEnumerable<Guid> guidList)
Converts a list of guids to a list of nullable guids
Authorisation
AccessSitesRequirement
public class AccessSitesRequirement : IAuthorizationRequirement
{
string[] _acceptedScopes;
public AccessSitesRequirement(params string[] acceptedScopes)
{
_acceptedScopes = acceptedScopes;
}
public string[] AcceptedScopes { get; set; } = new string[0];
}
CanAccessSitesHandler
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AccessSitesRequirement requirement) { var authFilterContext = context.Resource as AuthorizationFilterContext;
if (authFilterContext == null)
{
return Task.CompletedTask;
}
if (!context.User.Claims.Any(x => x.Type == ClaimConstants.Scope)
&& !context.User.Claims.Any(y => y.Type == ClaimConstants.Scp))
{
return Task.CompletedTask;
}
Claim? scopeClaim = context?.User?.FindFirst(ClaimConstants.Scp);
if (scopeClaim == null)
{
scopeClaim = context?.User?.FindFirst(ClaimConstants.Scope);
}
if (scopeClaim != null && scopeClaim.Value.Split(' ').Intersect(requirement.AcceptedScopes).Any())
{
context?.Succeed(requirement);
}
return Task.CompletedTask;
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.EntityFrameworkCore (>= 9.0.8)
- Microsoft.Identity.Web (>= 3.14.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.