VNS.Umbraco 3.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package VNS.Umbraco --version 3.0.2                
NuGet\Install-Package VNS.Umbraco -Version 3.0.2                
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="VNS.Umbraco" Version="3.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VNS.Umbraco --version 3.0.2                
#r "nuget: VNS.Umbraco, 3.0.2"                
#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.
// Install VNS.Umbraco as a Cake Addin
#addin nuget:?package=VNS.Umbraco&version=3.0.2

// Install VNS.Umbraco as a Cake Tool
#tool nuget:?package=VNS.Umbraco&version=3.0.2                

VNS Umbraco

Some diffrent helper tools for Umbraco Core

Installation

Use the package manager nuget to install.

dotnet add package VNS.Umbraco

Intro

First things first, with this package, we added a custom composer that enables direct URL acces to a template

public void Compose(IUmbracoBuilder builder) {
	builder.ContentFinders().Clear();
	builder.ContentFinders()
		.Append<ContentFinderByPageIdQuery>()
		.Append<ContentFinderByUrl>()
		.Append<ContentFinderByIdPath>()

		// Add the url and template one back in here
		.Append<ContentFinderByUrlAndTemplate>()

		.Append<ContentFinderByUrlAlias>()
		.Append<ContentFinderByRedirectUrl>();

	builder.Services.AddScoped<Helper>();
}

Init

Add this to the top of you template

// Using
@using VNS.Umbraco;

// For injection
@inject Helper _vns;

Util (Utility)

This contains a lot of diffrent small static methods to help you create simple code

// Get request method
string Util.ReqMethod;

// Is request method post
bool Util.IsPost;

// Get current url
string Util.GetCurrentUrl(bool includePath = true, bool includeQueryString = false);

// Request from form/querystring
string Util.Req(string name);

// Write to body
void Util.Write(object message);

// Redirect
void Util.Redirect(string url);

// Set content type
void Util.SetContentType(string contentType);

// Check if dynamic object contains a key
bool Util.ContainsKey(dynamic obj, string name);

// Session
void Util.SetSession(string key, object value);
T Util.GetSession<T>(string key);
void Util.RemoveSession(string key);
void Util.ClearSession();

// Cookie
void Util.SetCookie(string key, object value, DateTime? expires = null)
T Util.GetCookie<T>(string key);
void Util.DeleteCookie(string key);

// Render view as string
string Util.RenderViewAsString(Microsoft.AspNetCore.Html.IHtmlContent partial, System.Text.Encodings.Web.HtmlEncoder encoder);

// Files
IFormCollection Util.ReqFiles
IFormFile Util.ReqFile(string name);

// Posted body
System.IO.Stream Util.ReqBody();
string Util.ReqBodyAsString();

// Convert to XDocument
XDocument Util.Json2Xml(string json, string root = "");
XDocument Util.Obj2Xml(object obj, string root = "");

// Convert to JSON
string Util.Obj2Json(object obj);
string Util.Xml2Json(string xml);

// Convert to dynamic
T Util.Xml2Dynamic<T>(string xml);
T Util.Json2Dynamic<T>(string json);
T Util.Obj2Dynamic<T>(object obj);

// Convert stream
string Util.StreamToString(System.IO.Stream stream);

// Combine objects
object Util.CombineObj(object obj1, object obj2, object obj3 = null, object obj4 = null);

// Convert UnixTime to datetime
DateTime Util.DateFromUnixTime(long unixdate);

// Expose object
void Util.DrillObject(object obj);

// Clone object
T Util.CloneObj<T>(T obj);

Secy (Security)

This contains a lot of diffrent small static methods to help you create simple code

// Generate random password
string Secy.GeneratePassword(int passwordLength = 10);

// Hash
string Secy.Hash(string text, bool Use256 = false, bool Use512 = false);

// A2B
string Secy.A2B(string input);

// B2A
string Secy.B2A(string input);

// Encrypt Text
string Secy.EncryptText(string text, string secret = "");

// Decrypt Text
string Secy.DecryptText(string text, string secret = "");

// Generate JWT token
string Secy.GetToken(object payload, string serectKey = "", int expireAfterMinutes = 1440, int notValidBeforeMinutes = 0);

// Check if JWT token is valid
bool Secy.IsTokenValid(string token, string serectKey, out string message);

// Get token headers from JWT
dynamic Secy.GetTokenHeaders(string token);

// Get token payload from JWT
dynamic Secy.GetTokenPayload(string token);

Soap

// Init
var soap = new SOAP(string url);

// Get / Set properties
Dictionary<string, string> soap.Headers;

// Execute
string soap.Execute(string method, string payloadXml = "");

// Execute 
string rest.Execute(string url, string payload = "");

// Result status
int soap.StatusCode;
string soap.StatusDescription;
bool soap.IsSuccess;

Rest

// Init
var rest = new REST(string login = "", string password = "", string seperator = ":", string prefix = "Basic");

// Get / Set properties
string rest.ContentType;
string rest.Accept;
string rest.Method;
string rest.BaseUrl;
bool rest.KeepAlive;
Dictionary<string, string> rest.Headers;

// Execute 
string rest.Execute(string url, string payload = "");

// Result status
int rest.StatusCode;
string rest.StatusDescription;
bool rest.IsSuccess;

SQL

// Init
var sql = new SQL(string server, string database, string login, string password);

// Select data from SQL
var reader = sql.GetReader(string sql);

// Loop reader
while(reader.Read()){
	// Do stuff
}

// Close reader
reader.Close();

// Insert, Update, Delete etc.
void sql.Execute(string sql);

// Close sql
sql.Close();

Cookiebot

// Init
var cookiebot = new Cookiebot(string cookieName = "CookieConsent", string preferencesName = "preferences", string statisticsName = "statistics", string marketingName = "marketing");

// Properties
bool cookiebot.Necessary;
bool cookiebot.Statistics;
bool cookiebot.Marketing;
bool cookiebot.Preferences;

Log

Injection is required

_vns.Log.Trace(string message, Exception ex = null);
_vns.Log.Debug(string message, Exception ex = null);
_vns.Log.Info(string message, Exception ex = null);
_vns.Log.Warning(string message, Exception ex = null);
_vns.Log.Error(string message, Exception ex = null);
_vns.Log.Fatal(string message, Exception ex = null);

Content

Injection is required

// Create a node
IContent _vns.Cont.Create(string name, int parent, string contentTypeAlias, Dictionary<string, object> keyValues = null);

// Get a node
IContent _vns.Cont.Get(int id);

// Copy node
void _vns.Cont.Copy(IContent content, int parentId);

// Move node
void _vns.Cont.Move(IContent content, int parentId);

// Save node
void _vns.Cont.Save(IContent content);

// Save and publish node
void _vns.Cont.SaveAndPublish(IContent content);

// Delete node
void _vns.Cont.Delete(int id);

Member

Injection is required


// Properties for current member
bool _vns.Member.IsLoggedIn;
int Id;
string Username;
string Name;
string Email;
string Comments;
DateTime? LastLoginDate;

// SignOut
void _vns.Member.SignOut();

// Validate
bool _vns.Member.Validate(string userName, string password);

// Create member
IdentityResult _vns.Member.Create(string name, string email, string password, bool isApproved = true);
IdentityResult _vns.Member.Create(string name, string email, string userName, string password, bool isApproved, string memberTypeAlias = "Member");

// IdentityResult properties
bool result.Succeeded;
IEnumerable<T> Errors;

// Login
SignInResult Login(string userName, string password) ;

// SignInResult properties
bool result.IsLockedOut;
bool result.IsNotAllowed;
bool result.RequiresTwoFactor;

// Lock / Unlock
void _vns.Member.Lock(IMember member);
void _vns.Member.Unlock(IMember member);

// Exists
bool _vns.Member.Exists(string userName);
bool _vns.Member.EmailExists(string email);

// Get a member
IMember _vns.Member.Get(); // Will return current loggedin member
IMember _vns.Member.Get(int id);
IMember _vns.Member.Get(Guid key);
IMember _vns.Member.Get(string userName);
IMember _vns.Member.GetByEmail(string email);

// Get multiple members
IEnumerable<IMember> _vns.Member.GetAllMembers(params int[] ids);
IEnumerable<IMember> _vns.Member.GetMembersByMemberType(string memberTypeid)

// Generate password
string _vns.Member.GeneratePassword();

// Reset password
string _vns.Member.ResetPassword(string email);

// Change password
IdentityResult _vns.Member.ChangePassword(string oldPassword, string newPassword);

// IdentityResult properties
bool result.Succeeded;
IEnumerable<T> Errors;

// Save member
void _vns.Member.Save(IMember member);

// Delete member
void _vns.Member.Delete(int id);
void _vns.Member.Delete(string userName);
void _vns.Member.Delete(IMember member);

License

MIT

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
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
13.5.2 96 11/15/2024
13.5.1 107 9/30/2024
13.5.0 123 9/13/2024
13.4.0 123 6/21/2024
13.3.2 97 6/10/2024
13.0.0 108 5/30/2024
4.0.3 98 5/2/2024
4.0.2 141 2/8/2024
4.0.1 112 1/17/2024
4.0.0 171 12/14/2023
3.0.23 123 1/17/2024
3.0.22 135 12/13/2023
3.0.21 147 11/7/2023
3.0.20 147 10/26/2023
3.0.19 141 10/4/2023
3.0.18 123 9/21/2023
3.0.17 160 9/1/2023
3.0.16 145 8/15/2023
3.0.15 154 7/14/2023
3.0.14 174 6/30/2023
3.0.13 165 5/26/2023
3.0.12 206 4/12/2023
3.0.11 209 3/28/2023
3.0.10 256 2/24/2023
3.0.8 294 2/9/2023
3.0.7 288 1/31/2023
3.0.6 322 1/31/2023
3.0.5 285 1/25/2023
3.0.4 307 1/25/2023
3.0.3 295 1/18/2023
3.0.2 302 12/14/2022
3.0.1 298 12/14/2022
3.0.0 300 12/6/2022
2.0.17 388 10/28/2022
2.0.16 402 10/24/2022
2.0.15 600 9/13/2022
2.0.14 554 9/13/2022
2.0.13 471 7/11/2022
2.0.12 483 7/11/2022
2.0.11 502 7/10/2022
2.0.10 469 7/10/2022
2.0.9 534 7/10/2022
2.0.8 505 7/10/2022
2.0.7 483 7/2/2022
2.0.5 469 6/30/2022
2.0.4 471 6/30/2022
2.0.3 465 6/29/2022
2.0.2 498 6/29/2022
2.0.1 466 6/29/2022
1.0.23 475 7/2/2022
1.0.20 502 6/29/2022
1.0.19 475 6/29/2022
1.0.17 495 6/2/2022
1.0.16 520 5/11/2022
1.0.15 520 5/10/2022
1.0.14 504 5/10/2022
1.0.13 503 5/9/2022
1.0.12 475 5/9/2022
1.0.11 522 5/9/2022
1.0.10 538 5/9/2022
1.0.9 541 5/9/2022
1.0.8 570 4/30/2022