Skip to content

Instantly share code, notes, and snippets.

View martyncoup's full-sized avatar
🎯
APIs!

Martyn Coupland martyncoup

🎯
APIs!
View GitHub Profile
@martyncoup
martyncoup / RoleAssignment.cs
Last active April 6, 2021 10:17
Get roles from database and assign to claims principal
// Get role assignments
var oid = context.Principal.FindFirstValue("http://schemas.microsoft.com/identity/claims/objectidentifier");
var roleData = dbContext.RoleMaps.Where(w => w.ObjectId == oid).Join(dbContext.Roles, map => map.RoleId,
role => role.Id, (map, role) => new {RoleName = role.Name}).ToList();
// Assign roles to claims, loop for multiple roles
if (roleData.Count != 0)
{
List<Claim> claims = new List<Claim>();
foreach (var role in roleData)
@martyncoup
martyncoup / Timezones.cs
Created November 20, 2020 22:20
Generate List of Timezones without a Database
namespace GitHub.Gist
{
public class SampleClass
{
public List<SelectListItem> Timezones { get; } = new List<SelectListItem>(TimeZoneInfo.GetSystemTimeZones().Select(tz => new SelectListItem()
{
Text = tz.DisplayName,
Value = tz.Id
}).ToList());
}