From cd22c2f21535c1cb74f9c4cc57634a7df7726d23 Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Tue, 31 May 2022 12:25:11 +0200 Subject: [PATCH] Customizable FS network url --- FoodsharingSiegen.Contracts/Entity/Enums.cs | 38 ++++ FoodsharingSiegen.Contracts/Entity/User.cs | 49 +++-- .../Helper/AttributeExtensions.cs | 43 ++++ .../Model/CustomValueAttribute.cs | 28 +++ .../Controls/ProspectContainer.razor | 2 +- .../Data/Service/UserService.cs | 1 + .../20220531100143_User-Network.Designer.cs | 198 ++++++++++++++++++ .../Migrations/20220531100143_User-Network.cs | 26 +++ .../Migrations/FsContextModelSnapshot.cs | 3 + FoodsharingSiegen.Server/Pages/Profile.razor | 24 ++- 10 files changed, 388 insertions(+), 24 deletions(-) create mode 100644 FoodsharingSiegen.Contracts/Helper/AttributeExtensions.cs create mode 100644 FoodsharingSiegen.Contracts/Model/CustomValueAttribute.cs create mode 100644 FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.Designer.cs create mode 100644 FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.cs diff --git a/FoodsharingSiegen.Contracts/Entity/Enums.cs b/FoodsharingSiegen.Contracts/Entity/Enums.cs index e283e20..af949e1 100644 --- a/FoodsharingSiegen.Contracts/Entity/Enums.cs +++ b/FoodsharingSiegen.Contracts/Entity/Enums.cs @@ -1,3 +1,5 @@ +using FoodsharingSiegen.Contracts.Model; + namespace FoodsharingSiegen.Contracts.Entity { /// @@ -118,6 +120,42 @@ namespace FoodsharingSiegen.Contracts.Entity Ambassador = 400 } + /// + /// The fs network type enum + /// + public enum FsNetworkType + { + /// + /// The germany fs network type + /// + [CustomValue("https://foodsharing.de")] + Germany = 0, + + /// + /// The germany beta fs network type + /// + [CustomValue("https://beta.foodsharing.de")] + GermanyBeta = 10, + + /// + /// The austria fs network type + /// + [CustomValue("https://foodsharing.at")] + Austria = 20, + + /// + /// The austria beta fs network type + /// + [CustomValue("https://beta.foodsharing.at")] + AustriaBeta = 30, + + /// + /// The switzerland fs network type + /// + [CustomValue("https://foodsharing.network")] + Switzerland = 40 + } + /// /// The interaction type enum /// diff --git a/FoodsharingSiegen.Contracts/Entity/User.cs b/FoodsharingSiegen.Contracts/Entity/User.cs index 36bab23..22633e0 100644 --- a/FoodsharingSiegen.Contracts/Entity/User.cs +++ b/FoodsharingSiegen.Contracts/Entity/User.cs @@ -4,36 +4,35 @@ using FoodsharingSiegen.Contracts.Helper; namespace FoodsharingSiegen.Contracts.Entity { - /// - /// The user class (a. beging, 06.04.2022) + /// The user class (a. beging, 06.04.2022) /// public class User { #region Public Properties /// - /// Gets or sets the value of the created (ab) + /// Gets or sets the value of the created (ab) /// public DateTime Created { get; set; } /// - /// Gets or sets the value of the encrypted password (ab) + /// Gets or sets the value of the encrypted password (ab) /// public string EncryptedPassword { get; set; } /// - /// Gets or sets the value of the force logout (ab) + /// Gets or sets the value of the force logout (ab) /// public bool ForceLogout { get; set; } /// - /// Gets or sets the value of the groups (ab) + /// Gets or sets the value of the groups (ab) /// public string Groups { get; set; } /// - /// Gets or sets the value of the groups list (ab) + /// Gets or sets the value of the groups list (ab) /// [NotMapped] public List GroupsList @@ -49,32 +48,44 @@ namespace FoodsharingSiegen.Contracts.Entity } /// - /// Gets or sets the value of the id (ab) + /// Gets or sets the value of the id (ab) /// - [Key] public Guid Id { get; set; } + [Key] + public Guid Id { get; set; } /// - /// Gets or sets the value of the interactions (ab) + /// Gets or sets the value of the interactions (ab) /// public IList Interactions { get; set; } /// - /// Gets or sets the value of the mail (ab) + /// Gets or sets the value of the mail (ab) /// public string Mail { get; set; } /// - /// Gets or sets the value of the memo (ab) + /// Gets or sets the value of the memo (ab) /// public string? Memo { get; set; } /// - /// Gets or sets the value of the name (ab) + /// Gets or sets the value of the name (ab) /// public string Name { get; set; } /// - /// Gets or sets the value of the password (ab) + /// Gets or sets the value of the network (ab) + /// + public FsNetworkType Network { get; set; } + + /// + /// Gets the value of the network link (ab) + /// + [NotMapped] + public string NetworkLink => Network.GetCustomValue(); + + /// + /// Gets or sets the value of the password (ab) /// [NotMapped] public string Password @@ -84,12 +95,12 @@ namespace FoodsharingSiegen.Contracts.Entity } /// - /// Gets or sets the value of the type (ab) + /// Gets or sets the value of the type (ab) /// public UserType Type { get; set; } /// - /// Gets or sets the value of the verified (ab) + /// Gets or sets the value of the verified (ab) /// public bool Verified { get; set; } @@ -98,11 +109,11 @@ namespace FoodsharingSiegen.Contracts.Entity #region Public Method Clone /// - /// Clones this instance (a. beging, 11.04.2022) + /// Clones this instance (a. beging, 11.04.2022) /// /// The user - public User Clone() => (User) MemberwiseClone(); + public User Clone() => (User)MemberwiseClone(); #endregion } -} +} \ No newline at end of file diff --git a/FoodsharingSiegen.Contracts/Helper/AttributeExtensions.cs b/FoodsharingSiegen.Contracts/Helper/AttributeExtensions.cs new file mode 100644 index 0000000..0d5c96e --- /dev/null +++ b/FoodsharingSiegen.Contracts/Helper/AttributeExtensions.cs @@ -0,0 +1,43 @@ +using FoodsharingSiegen.Contracts.Model; + +namespace FoodsharingSiegen.Contracts.Helper +{ + /// + /// The attribute extensions class (a. beging, 31.05.2022) + /// + public static class AttributeExtensions + { + #region Public Method GetCustomValue + + /// + /// Gets the custom value using the specified enum val (a. beging, 31.05.2022) + /// + /// The enum val + /// The string + public static string GetCustomValue(this Enum enumVal) + { + var attribute = enumVal.GetAttributeOfType(); + return attribute?.Value ?? string.Empty; + } + + #endregion + + #region Private Method GetAttributeOfType + + /// + /// Gets the attribute of type using the specified enum val (a. beging, 31.05.2022) + /// + /// The + /// The enum val + /// The + private static T? GetAttributeOfType(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 + } +} \ No newline at end of file diff --git a/FoodsharingSiegen.Contracts/Model/CustomValueAttribute.cs b/FoodsharingSiegen.Contracts/Model/CustomValueAttribute.cs new file mode 100644 index 0000000..cb684fb --- /dev/null +++ b/FoodsharingSiegen.Contracts/Model/CustomValueAttribute.cs @@ -0,0 +1,28 @@ +namespace FoodsharingSiegen.Contracts.Model +{ + /// + /// The custom value attribute class (a. beging, 31.05.2022) + /// + /// + public sealed class CustomValueAttribute : Attribute + { + #region Public Properties + + /// + /// Gets the value of the value (ab) + /// + public string Value { get; } + + #endregion + + #region Setup/Teardown + + /// + /// Initializes a new instance of the class + /// + /// The value (ab) + public CustomValueAttribute(string value) => Value = value; + + #endregion + } +} \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor index efb412c..0e60924 100644 --- a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor +++ b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor @@ -17,7 +17,7 @@ @Prospect.Name - Profil öffnen + Profil öffnen
@Prospect.Memo
diff --git a/FoodsharingSiegen.Server/Data/Service/UserService.cs b/FoodsharingSiegen.Server/Data/Service/UserService.cs index dae35b7..77e3939 100644 --- a/FoodsharingSiegen.Server/Data/Service/UserService.cs +++ b/FoodsharingSiegen.Server/Data/Service/UserService.cs @@ -138,6 +138,7 @@ namespace FoodsharingSiegen.Server.Data.Service entityUser.Type = user.Type; entityUser.Verified = user.Verified; entityUser.Groups = user.Groups; + entityUser.Network = user.Network; if (!Context.HasChanges()) return new OperationResult(new Exception("Nichts zum Speichern gefunden")); diff --git a/FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.Designer.cs b/FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.Designer.cs new file mode 100644 index 0000000..43c0e80 --- /dev/null +++ b/FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.Designer.cs @@ -0,0 +1,198 @@ +// +using System; +using FoodsharingSiegen.Server.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FoodsharingSiegen.Server.Migrations +{ + [DbContext(typeof(FsContext))] + [Migration("20220531100143_User-Network")] + partial class UserNetwork + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.1"); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Audit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("Data1") + .HasColumnType("TEXT"); + + b.Property("Data2") + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("UserID") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserID"); + + b.ToTable("Audits"); + }); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Interaction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Alert") + .HasColumnType("INTEGER"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("Info") + .HasColumnType("TEXT"); + + b.Property("NotNeeded") + .HasColumnType("INTEGER"); + + b.Property("ProspectID") + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("UserID") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ProspectID"); + + b.HasIndex("UserID"); + + b.ToTable("Interactions"); + }); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Prospect", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("FsId") + .HasColumnType("INTEGER"); + + b.Property("Memo") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Prospects"); + }); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("EncryptedPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ForceLogout") + .HasColumnType("INTEGER"); + + b.Property("Groups") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Mail") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Memo") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Network") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("Verified") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Audit", b => + { + b.HasOne("FoodsharingSiegen.Contracts.Entity.User", "User") + .WithMany() + .HasForeignKey("UserID"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Interaction", b => + { + b.HasOne("FoodsharingSiegen.Contracts.Entity.Prospect", "Prospect") + .WithMany("Interactions") + .HasForeignKey("ProspectID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FoodsharingSiegen.Contracts.Entity.User", "User") + .WithMany("Interactions") + .HasForeignKey("UserID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Prospect"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Prospect", b => + { + b.Navigation("Interactions"); + }); + + modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.User", b => + { + b.Navigation("Interactions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.cs b/FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.cs new file mode 100644 index 0000000..fc63b6c --- /dev/null +++ b/FoodsharingSiegen.Server/Migrations/20220531100143_User-Network.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FoodsharingSiegen.Server.Migrations +{ + public partial class UserNetwork : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Network", + table: "Users", + type: "INTEGER", + nullable: false, + defaultValue: 0); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Network", + table: "Users"); + } + } +} diff --git a/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs b/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs index d405483..297da56 100644 --- a/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs +++ b/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs @@ -139,6 +139,9 @@ namespace FoodsharingSiegen.Server.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("Network") + .HasColumnType("INTEGER"); + b.Property("Type") .HasColumnType("INTEGER"); diff --git a/FoodsharingSiegen.Server/Pages/Profile.razor b/FoodsharingSiegen.Server/Pages/Profile.razor index 73c56a3..d370db7 100644 --- a/FoodsharingSiegen.Server/Pages/Profile.razor +++ b/FoodsharingSiegen.Server/Pages/Profile.razor @@ -2,15 +2,17 @@ @using FoodsharingSiegen.Server.Dialogs @using FoodsharingSiegen.Server.BaseClasses +@using FoodsharingSiegen.Contracts.Entity +@using FoodsharingSiegen.Contracts.Helper @inherits FsBase Profil
- +

Mein Profil

- + @@ -33,9 +35,23 @@ -
- +
+

Allgemeines

+ +

+ Die ausgewählte URL wird zum Beispiel verwendet, um die Profile der Neulinge zu verlinken + +

+ + +

Sicherheit

+

Die Änderung deines Passworts ist sofort aktiv. Im Anschluss wirst du ausgeloggt und kannst dich neu einloggen.