Customizable FS network url

This commit is contained in:
Andre Beging
2022-05-31 12:25:11 +02:00
parent bba0a377b5
commit cd22c2f215
10 changed files with 388 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
using FoodsharingSiegen.Contracts.Model;
namespace FoodsharingSiegen.Contracts.Entity
{
/// <summary>
@@ -118,6 +120,42 @@ namespace FoodsharingSiegen.Contracts.Entity
Ambassador = 400
}
/// <summary>
/// The fs network type enum
/// </summary>
public enum FsNetworkType
{
/// <summary>
/// The germany fs network type
/// </summary>
[CustomValue("https://foodsharing.de")]
Germany = 0,
/// <summary>
/// The germany beta fs network type
/// </summary>
[CustomValue("https://beta.foodsharing.de")]
GermanyBeta = 10,
/// <summary>
/// The austria fs network type
/// </summary>
[CustomValue("https://foodsharing.at")]
Austria = 20,
/// <summary>
/// The austria beta fs network type
/// </summary>
[CustomValue("https://beta.foodsharing.at")]
AustriaBeta = 30,
/// <summary>
/// The switzerland fs network type
/// </summary>
[CustomValue("https://foodsharing.network")]
Switzerland = 40
}
/// <summary>
/// The interaction type enum
/// </summary>

View File

@@ -4,36 +4,35 @@ using FoodsharingSiegen.Contracts.Helper;
namespace FoodsharingSiegen.Contracts.Entity
{
/// <summary>
/// The user class (a. beging, 06.04.2022)
/// The user class (a. beging, 06.04.2022)
/// </summary>
public class User
{
#region Public Properties
/// <summary>
/// Gets or sets the value of the created (ab)
/// Gets or sets the value of the created (ab)
/// </summary>
public DateTime Created { get; set; }
/// <summary>
/// Gets or sets the value of the encrypted password (ab)
/// Gets or sets the value of the encrypted password (ab)
/// </summary>
public string EncryptedPassword { get; set; }
/// <summary>
/// Gets or sets the value of the force logout (ab)
/// Gets or sets the value of the force logout (ab)
/// </summary>
public bool ForceLogout { get; set; }
/// <summary>
/// Gets or sets the value of the groups (ab)
/// Gets or sets the value of the groups (ab)
/// </summary>
public string Groups { get; set; }
/// <summary>
/// Gets or sets the value of the groups list (ab)
/// Gets or sets the value of the groups list (ab)
/// </summary>
[NotMapped]
public List<UserGroup> GroupsList
@@ -49,32 +48,44 @@ namespace FoodsharingSiegen.Contracts.Entity
}
/// <summary>
/// Gets or sets the value of the id (ab)
/// Gets or sets the value of the id (ab)
/// </summary>
[Key] public Guid Id { get; set; }
[Key]
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the value of the interactions (ab)
/// Gets or sets the value of the interactions (ab)
/// </summary>
public IList<Interaction> Interactions { get; set; }
/// <summary>
/// Gets or sets the value of the mail (ab)
/// Gets or sets the value of the mail (ab)
/// </summary>
public string Mail { get; set; }
/// <summary>
/// Gets or sets the value of the memo (ab)
/// Gets or sets the value of the memo (ab)
/// </summary>
public string? Memo { get; set; }
/// <summary>
/// Gets or sets the value of the name (ab)
/// Gets or sets the value of the name (ab)
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the value of the password (ab)
/// Gets or sets the value of the network (ab)
/// </summary>
public FsNetworkType Network { get; set; }
/// <summary>
/// Gets the value of the network link (ab)
/// </summary>
[NotMapped]
public string NetworkLink => Network.GetCustomValue();
/// <summary>
/// Gets or sets the value of the password (ab)
/// </summary>
[NotMapped]
public string Password
@@ -84,12 +95,12 @@ namespace FoodsharingSiegen.Contracts.Entity
}
/// <summary>
/// Gets or sets the value of the type (ab)
/// Gets or sets the value of the type (ab)
/// </summary>
public UserType Type { get; set; }
/// <summary>
/// Gets or sets the value of the verified (ab)
/// Gets or sets the value of the verified (ab)
/// </summary>
public bool Verified { get; set; }
@@ -98,11 +109,11 @@ namespace FoodsharingSiegen.Contracts.Entity
#region Public Method Clone
/// <summary>
/// Clones this instance (a. beging, 11.04.2022)
/// Clones this instance (a. beging, 11.04.2022)
/// </summary>
/// <returns>The user</returns>
public User Clone() => (User) MemberwiseClone();
public User Clone() => (User)MemberwiseClone();
#endregion
}
}
}

View File

@@ -0,0 +1,43 @@
using FoodsharingSiegen.Contracts.Model;
namespace FoodsharingSiegen.Contracts.Helper
{
/// <summary>
/// The attribute extensions class (a. beging, 31.05.2022)
/// </summary>
public static class AttributeExtensions
{
#region Public Method GetCustomValue
/// <summary>
/// Gets the custom value using the specified enum val (a. beging, 31.05.2022)
/// </summary>
/// <param name="enumVal">The enum val</param>
/// <returns>The string</returns>
public static string GetCustomValue(this Enum enumVal)
{
var attribute = enumVal.GetAttributeOfType<CustomValueAttribute>();
return attribute?.Value ?? string.Empty;
}
#endregion
#region Private Method GetAttributeOfType
/// <summary>
/// Gets the attribute of type using the specified enum val (a. beging, 31.05.2022)
/// </summary>
/// <typeparam name="T">The </typeparam>
/// <param name="enumVal">The enum val</param>
/// <returns>The</returns>
private static T? GetAttributeOfType<T>(this Enum enumVal) where T : Attribute
{
var type = enumVal.GetType();
var memInfo = type.GetMember(enumVal.ToString());
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
return attributes.Length > 0 ? (T)attributes[0] : null;
}
#endregion
}
}

View File

@@ -0,0 +1,28 @@
namespace FoodsharingSiegen.Contracts.Model
{
/// <summary>
/// The custom value attribute class (a. beging, 31.05.2022)
/// </summary>
/// <seealso cref="Attribute" />
public sealed class CustomValueAttribute : Attribute
{
#region Public Properties
/// <summary>
/// Gets the value of the value (ab)
/// </summary>
public string Value { get; }
#endregion
#region Setup/Teardown
/// <summary>
/// Initializes a new instance of the <see cref="CustomValueAttribute" /> class
/// </summary>
/// <param name="value">The value (ab)</param>
public CustomValueAttribute(string value) => Value = value;
#endregion
}
}