VNS.Umbraco 3.0.7

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

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

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>();
}

Init

Add this to the top of you template

// Using
@using VNS.Umbraco;

// For injection
@inject VNS.Umbraco.Helper _vns;

Util (Utility)

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

// Get httpcontext
HttpContext ctx;

// Get appsettings (Will load from appsettings.json)
IConfigurationRoot AppSettings;

// Get connectionstring (Will return connectionstring named umbracoDbDSN)
string ConnectionString;

// Get smtp (Will return from Umbraco:CMS:Global:Smtp)
IConfigurationSection Smtp;

// 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 - Default is set to: application/json
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);

// Udi
Udi GetUdi(this IPublishedContent content);

// 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);
bool SaveFile(IFormFile file, string path);

// 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);

// Send email (Will use smtp settings from appsettings, add from object and look for name parameter in smtp selection to use as from name if fromName parameter not set)
bool SendEmail(System.Net.Mail.MailMessage mailMessage, string fromName = "");

// 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 = "");

// 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.Content.Create(string name, int parent, string contentTypeAlias, Dictionary<string, object> keyValues = null);

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

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

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

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

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

// Delete node
void _vns.Content.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)

// Get Types
IEnumerable<IMemberType> GetAllMembertypes(params int[] ids);

// Get Roles
IEnumerable<IMemberGroup> GetAllRoles();
IEnumerable<string> GetAllRoles(int memberid);

// 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 77 11/15/2024
13.5.1 100 9/30/2024
13.5.0 114 9/13/2024
13.4.0 114 6/21/2024
13.3.2 90 6/10/2024
13.0.0 101 5/30/2024
4.0.3 93 5/2/2024
4.0.2 133 2/8/2024
4.0.1 108 1/17/2024
4.0.0 167 12/14/2023
3.0.23 119 1/17/2024
3.0.22 131 12/13/2023
3.0.21 143 11/7/2023
3.0.20 143 10/26/2023
3.0.19 137 10/4/2023
3.0.18 119 9/21/2023
3.0.17 156 9/1/2023
3.0.16 141 8/15/2023
3.0.15 150 7/14/2023
3.0.14 170 6/30/2023
3.0.13 161 5/26/2023
3.0.12 202 4/12/2023
3.0.11 205 3/28/2023
3.0.10 252 2/24/2023
3.0.8 290 2/9/2023
3.0.7 284 1/31/2023
3.0.6 316 1/31/2023
3.0.5 281 1/25/2023
3.0.4 303 1/25/2023
3.0.3 291 1/18/2023
3.0.2 298 12/14/2022
3.0.1 294 12/14/2022
3.0.0 296 12/6/2022
2.0.17 382 10/28/2022
2.0.16 398 10/24/2022
2.0.15 596 9/13/2022
2.0.14 550 9/13/2022
2.0.13 465 7/11/2022
2.0.12 477 7/11/2022
2.0.11 496 7/10/2022
2.0.10 463 7/10/2022
2.0.9 528 7/10/2022
2.0.8 499 7/10/2022
2.0.7 477 7/2/2022
2.0.5 463 6/30/2022
2.0.4 465 6/30/2022
2.0.3 459 6/29/2022
2.0.2 492 6/29/2022
2.0.1 460 6/29/2022
1.0.23 469 7/2/2022
1.0.20 496 6/29/2022
1.0.19 469 6/29/2022
1.0.17 489 6/2/2022
1.0.16 514 5/11/2022
1.0.15 514 5/10/2022
1.0.14 498 5/10/2022
1.0.13 497 5/9/2022
1.0.12 469 5/9/2022
1.0.11 514 5/9/2022
1.0.10 532 5/9/2022
1.0.9 533 5/9/2022
1.0.8 564 4/30/2022