-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rpjengaard
committed
Jan 25, 2018
1 parent
b5a8a86
commit 779f76d
Showing
12 changed files
with
1,115 additions
and
11 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
src/Skybrud.UmbracoEssentials/Extensions/Udi/UdiExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Umbraco.Core.Models; | ||
using Umbraco.Web; | ||
using Skybrud.Essentials.Strings.Extensions; | ||
|
||
namespace Skybrud.UmbracoEssentials.Extensions.Udi | ||
{ | ||
public static class UdiExtensions | ||
{ | ||
/// <summary> | ||
/// Find node in Umbraco and return the guid of the node | ||
/// </summary> | ||
/// <param name="nodeId"></param> | ||
/// <returns></returns> | ||
public static Guid? GetGuid(this int nodeId) | ||
{ | ||
IPublishedContent node = UmbracoContext.Current.ContentCache.GetById(nodeId); | ||
|
||
if (node == null) return (Guid?)null; | ||
|
||
return node.GetKey(); | ||
} | ||
|
||
/// <summary> | ||
/// Find node in Umbraco and returns the guid-string (w. - removed) | ||
/// </summary> | ||
/// <param name="nodeId"></param> | ||
/// <returns></returns> | ||
public static string GetGuidStringExamine(this int nodeId) | ||
{ | ||
Guid? g = GetGuid(nodeId); | ||
|
||
if (g == null) return string.Empty; | ||
|
||
return g.ToString().Replace("-", ""); | ||
} | ||
|
||
/// <summary> | ||
/// Find nodes in Umbraco and returns the guid-strings (w. - removed) | ||
/// </summary> | ||
/// <param name="nodeIds">int[]</param> | ||
/// <returns></returns> | ||
public static string GetGuidsStringExamine(this int[] nodeIds) | ||
{ | ||
List<string> guids = new List<string>(); | ||
|
||
foreach (int i in nodeIds) | ||
{ | ||
Guid? g = GetGuid(i); | ||
|
||
if (g == null) continue; | ||
|
||
guids.Add(g.ToString().Replace("-", "")); | ||
} | ||
|
||
return String.Join(" ", guids.ToArray()); | ||
} | ||
|
||
/// <summary> | ||
/// Find nodes in Umbraco and returns the guid-strings (w. - removed) | ||
/// </summary> | ||
/// <param name="nodeIds">string</param> | ||
/// <returns></returns> | ||
public static string GetGuidsStringExamine(this string nodeIds) | ||
{ | ||
return nodeIds.ToInt32Array().GetGuidsStringExamine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters