ilm.scp.common.lib 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ilm.scp.common.lib --version 1.0.1
                    
NuGet\Install-Package ilm.scp.common.lib -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ilm.scp.common.lib" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ilm.scp.common.lib" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ilm.scp.common.lib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ilm.scp.common.lib --version 1.0.1
                    
#r "nuget: ilm.scp.common.lib, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ilm.scp.common.lib@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ilm.scp.common.lib&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ilm.scp.common.lib&version=1.0.1
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 66 9/28/2025
1.0.1 93 9/6/2025
1.0.0 89 9/6/2025