PortiaNet.Helper
1.0.2
See the version list below for details.
dotnet add package PortiaNet.Helper --version 1.0.2
NuGet\Install-Package PortiaNet.Helper -Version 1.0.2
<PackageReference Include="PortiaNet.Helper" Version="1.0.2" />
paket add PortiaNet.Helper --version 1.0.2
#r "nuget: PortiaNet.Helper, 1.0.2"
// Install PortiaNet.Helper as a Cake Addin #addin nuget:?package=PortiaNet.Helper&version=1.0.2 // Install PortiaNet.Helper as a Cake Tool #tool nuget:?package=PortiaNet.Helper&version=1.0.2
PortiaNet.Helper
This tool is a .Net class library to provide some functionalities and helper methods in MVC projects. Helpers are as the following:
MasterData
This part contains some master information which doesn't change too much. Currently, the following list of the masters are included:
- Continent
- Country
- Currency
- Language
How To Use
You can simply call:
var continents = Continent.GetAll();
// Or
var countries = Country.GetAll();
Security Helper
This helper provides the functionality to inject the encription and decription functions to any class. It gets the Enc/Dec key in the configuration provides the encryption and decryption using AES128 algorythm.
How To Use
- Configure DI
using PortiaNet.Helper.SecurityHelper
public void ConfigureServices(IConfiguration configuration, IServiceCollection services)
{
...
services.AddEncryptionDecryptionHelper(f =>
{
f.Key = 'Enc/Dec Key'; // The key length must be 32 chars
});
...
}
- Inject the class
public class AnyService
{
private readonly EncryptionDecryptionHelper _encDecHelper;
// Inject the EncryptionDecryptionHelper class
public AnyService(EncryptionDecryptionHelper encDecHelper)
{
_encDecHelper = encDecHelper;
}
public void DoSomethingSpecial()
{
// Data encryption
string? encryptedData = _encDecHelper.EncryptString("data");
// Data decryption
string? decryptedData = _encDecHelper.DecryptString(encryptedData);
}
}
ExtensionMethods.cs
This class contains some of the frequently used static methods. The namespace of this class is System
, then it will be available everywhere by default.
string GetControllerName(this string value)
// var controllerName = nameof(HomeController).GetControllerName();
string GetEnumDescription(this Enum value)
// var enumDescription = Gender.Male.GetEnumDescription();
string GetDisplayName(this Enum enumValue)
// var enumDisplayName = Gender.Male.GetDisplayName();
IDictionary<int, String> GetEnumValueNames(Type type)
// var enumWithNames = GetEnumValueNames(typeof(Gender));
string GetDisplayGroup(this Enum value)
// var enumGroupName = Gender.Male.GetDisplayGroup();
Pagination.cs
The Pagination class containes a base class to keep the main pagination information like TotalRecords Count
, FilteredRecords Count
, PageSize
, PageIndex
, and CurrentPageRecordsCount
, and a derived generic class to keep the fetched and peged information in a list.
There is another static helper class inside this file to decrease the pagination headache and mistakes. It gets the IQueryable<K>
as the data source, and filtering , sorting, and mapping functionalities as the input parameter, then returns a PaginationModel<T>
as the result.
public Task<PaginationModel<StateViewModel>> GetStatesAsync(string filter, string? countryId, int pageIndex = 1, int pageSize = 10000)
=> PaginationHelper.GetPaginationAsync(_context.States.Include(f => f.Country)
.Where(f => !f.IsDeleted && !f.Country.IsDeleted),
query =>
{
if (!string.IsNullOrEmpty(filter))
query = query.Where(f => f.Name.Contains(filter) ||
f.RefNo.Contains(filter));
if (!string.IsNullOrEmpty(countryId))
query = query.Where(f => f.CountryId == countryId);
return query;
},
sort =>
{
return sort.OrderBy(f => f.Name);
},
mapping =>
{
return mapping.Select(f => new StateViewModel
{
Id = f.Id,
Name = f.Name,
RefNo = f.RefNo,
Country = f.Country?.Name,
CountryId = f.CountryId,
IsGovernorate = f.IsGovernorate
}).ToList();
},
pageSize,
pageIndex);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.