Added endpoint and functionality for getting, retrieving and deleting bookmarks, and for adding and removing tags for a bookmark
This commit is contained in:
24
YABA.Common/Extensions/DictionaryExtensions.cs
Normal file
24
YABA.Common/Extensions/DictionaryExtensions.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YABA.Common.Extensions
|
||||
{
|
||||
public static class DictionaryExtensions
|
||||
{
|
||||
public static void AddRange<K, V>(this Dictionary<K, V> source, Dictionary<K, V> collection)
|
||||
{
|
||||
if (collection == null)
|
||||
{
|
||||
throw new ArgumentNullException("Collection is null");
|
||||
}
|
||||
|
||||
foreach (var item in collection)
|
||||
{
|
||||
if (!source.ContainsKey(item.Key))
|
||||
{
|
||||
source.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using YABA.Common.Attributes;
|
||||
@ -8,6 +9,13 @@ namespace YABA.Common.Extensions
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
private static readonly IEnumerable<CrudResultLookup> SuccessfulCrudStatuses = new List<CrudResultLookup>() {
|
||||
CrudResultLookup.CreateSucceeded,
|
||||
CrudResultLookup.UpdateSucceeded,
|
||||
CrudResultLookup.DeleteSucceeded,
|
||||
CrudResultLookup.RetrieveSuccessful
|
||||
};
|
||||
|
||||
public static TAttribute GetAttribute<TAttribute>(this Enum value) where TAttribute : Attribute
|
||||
{
|
||||
var enumType = value.GetType();
|
||||
@ -25,5 +33,8 @@ namespace YABA.Common.Extensions
|
||||
return claimLookup.GetAttribute<ClaimNameAttribute>().Name;
|
||||
}
|
||||
|
||||
public static bool IsCrudResultSuccessful(this CrudResultLookup importStatusLookup) => SuccessfulCrudStatuses.Contains(importStatusLookup);
|
||||
|
||||
public static bool IsCrudResultFailure(this CrudResultLookup importStatusLookup) => !SuccessfulCrudStatuses.Contains(importStatusLookup);
|
||||
}
|
||||
}
|
||||
|
||||
18
YABA.Common/Extensions/UserIdentityExtensions.cs
Normal file
18
YABA.Common/Extensions/UserIdentityExtensions.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
using YABA.Common.Lookups;
|
||||
|
||||
namespace YABA.Common.Extensions
|
||||
{
|
||||
public static class UserIdentityExtensions
|
||||
{
|
||||
public static string GetUserId(this IIdentity identity) => GetCustomClaim(identity, ClaimsLookup.UserId);
|
||||
public static string GetAuthProviderId(this IIdentity identity) => GetCustomClaim(identity, ClaimsLookup.AuthProviderId);
|
||||
|
||||
public static string GetCustomClaim(this IIdentity identity, ClaimsLookup claim)
|
||||
{
|
||||
var claimsIdentity = identity as ClaimsIdentity;
|
||||
return claimsIdentity.FindFirst(claim.GetClaimName())?.Value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user