From 45325e339c4b70c3ece6ee21c2b121b891e63405 Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Mon, 23 May 2022 18:07:05 +0200 Subject: [PATCH] =?UTF-8?q?Code=20Cleanup=20und=20Passwort=20=C3=A4ndern?= =?UTF-8?q?=20im=20Profil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FoodsharingSiegen.Server/Data/FsContext.cs | 7 +- FoodsharingSiegen.Server/Pages/Profile.razor | 7 +- .../Pages/Profile.razor.cs | 29 ++++- FoodsharingSiegen.Server/Pages/Users.razor.cs | 113 +++++++----------- 4 files changed, 81 insertions(+), 75 deletions(-) diff --git a/FoodsharingSiegen.Server/Data/FsContext.cs b/FoodsharingSiegen.Server/Data/FsContext.cs index b3147f2..e7db816 100644 --- a/FoodsharingSiegen.Server/Data/FsContext.cs +++ b/FoodsharingSiegen.Server/Data/FsContext.cs @@ -41,7 +41,7 @@ namespace FoodsharingSiegen.Server.Data /// The options (ab) public FsContext(DbContextOptions options) : base(options) { - // Database.EnsureCreated(); + Database.EnsureCreated(); } #endregion @@ -57,6 +57,11 @@ namespace FoodsharingSiegen.Server.Data return ChangeTracker.Entries().Any(e => e.State is EntityState.Added or EntityState.Modified or EntityState.Deleted); } + public class AndresTestException : Exception + { + + } + #endregion } } \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/Profile.razor b/FoodsharingSiegen.Server/Pages/Profile.razor index 761a868..37c3d0a 100644 --- a/FoodsharingSiegen.Server/Pages/Profile.razor +++ b/FoodsharingSiegen.Server/Pages/Profile.razor @@ -1,5 +1,6 @@ @page "/profile" +@using FoodsharingSiegen.Server.Dialogs @using FoodsharingSiegen.Server.BaseClasses @inherits FsBase @@ -31,6 +32,8 @@

Sicherheit

- + - \ No newline at end of file + + + \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/Profile.razor.cs b/FoodsharingSiegen.Server/Pages/Profile.razor.cs index b80afb7..1881d46 100644 --- a/FoodsharingSiegen.Server/Pages/Profile.razor.cs +++ b/FoodsharingSiegen.Server/Pages/Profile.razor.cs @@ -1,6 +1,7 @@ using Blazorise; using FoodsharingSiegen.Contracts.Entity; using FoodsharingSiegen.Server.Data.Service; +using FoodsharingSiegen.Server.Dialogs; using Microsoft.AspNetCore.Components; namespace FoodsharingSiegen.Server.Pages @@ -11,16 +12,25 @@ namespace FoodsharingSiegen.Server.Pages public partial class Profile { #region Dependencies (Injected) - + + #region Dependencies (Injected) + /// /// Gets or sets the value of the user service (ab) /// [Inject] public UserService? UserService { get; set; } - + + #endregion + #endregion #region Private Properties + /// + /// Gets or sets the value of the password modal (ab) + /// + private SetPasswordModal? PasswordModal { get; set; } + /// /// Gets or sets the value of the user (ab) /// @@ -73,6 +83,21 @@ namespace FoodsharingSiegen.Server.Pages #endregion + #region Private Method OnPasswordSet + + /// + /// Ons the password set using the specified arg (a. beging, 23.05.2022) + /// + /// The arg + private async Task OnPasswordSet(User arg) + { + var setPasswordR = await UserService?.SetPassword(arg)!; + if(setPasswordR.Success) + await Notification?.Success("Dein neues Passwort wurde gespeichert")!; + } + + #endregion + #region Private Method RemoveAccount /// diff --git a/FoodsharingSiegen.Server/Pages/Users.razor.cs b/FoodsharingSiegen.Server/Pages/Users.razor.cs index 1652fef..1c67231 100644 --- a/FoodsharingSiegen.Server/Pages/Users.razor.cs +++ b/FoodsharingSiegen.Server/Pages/Users.razor.cs @@ -12,41 +12,49 @@ namespace FoodsharingSiegen.Server.Pages public partial class Users { #region Dependencies (Injected) - + //////////////////////////////////////////////////////////////////////////////////////////////////// /// Gets or sets the user service. /// /// The user service. //////////////////////////////////////////////////////////////////////////////////////////////////// [Inject] public UserService UserService { get; set; } = null!; - - #endregion - - #region Public Properties - - /// - /// Gets or sets the value of the user data grid (ab) - /// - public DataGrid UserDataGrid { get; set; } + #endregion #region Private Properties + /// + /// Gets or sets the value of the password modal (ab) + /// + private SetPasswordModal PasswordModal { get; set; } + + /// + /// Gets or sets the value of the selected company texts (ab) + /// + private List SelectedCompanyTexts { get; set; } = new(); + + /// + /// Gets or sets the value of the selected user (ab) + /// + private User? SelectedUser { get; set; } + + /// + /// Gets or sets the value of the user data grid (ab) + /// + private DataGrid UserDataGrid { get; set; } + + /// + /// Gets the value of the user groups (ab) + /// + private IEnumerable UserGroups => Enum.GetValues(); + /// /// Gets or sets the value of the user list (ab) /// private List? UserList { get; set; } - public User? SelectedUser { get; set; } - - public IEnumerable UserGroups => Enum.GetValues(); - - public List Companies { get; set; } - public List SelectedCompanies { get; set; } - public List SelectedCompanyTexts { get; set; } = new(); - public SetPasswordModal PasswordModal { get; set; } - #endregion #region Override OnAfterRenderAsync @@ -65,35 +73,6 @@ namespace FoodsharingSiegen.Server.Pages #endregion - protected override void OnInitialized() - { - Companies = new List - { - new Company{Name = "Germany", ISO = "DE"}, - new Company{Name = "USA", ISO = "US"}, - new Company{Name = "England", ISO = "GB"}, - new Company{Name = "Austria", ISO = "AT"} - }; - - SelectedCompanies = new List {UserGroups.ElementAt(2)}; - - base.OnInitialized(); - } - - #region Private Method Chang - - /// - /// Changs the context (a. beging, 01.04.2022) - /// - /// The context - /// The type - private void Chang(CellEditContext context, UserType type) - { - context.Item.Type = type; - } - - #endregion - #region Private Method LoadUsers /// @@ -109,6 +88,21 @@ namespace FoodsharingSiegen.Server.Pages #endregion + #region Private Method OnPasswordSet + + /// + /// Ons the password set using the specified user (a. beging, 23.05.2022) + /// + /// The user + private async Task OnPasswordSet(User user) + { + var setPasswordR = await UserService?.SetPassword(user)!; + if(setPasswordR.Success) + await Notification?.Success("Passwort gespeichert")!; + } + + #endregion + #region Private Method RowInserted /// @@ -119,13 +113,9 @@ namespace FoodsharingSiegen.Server.Pages { var addUserR = await UserService.AddUserAsync(arg.Item); if (!addUserR.Success) - { - //Todo Error Toast [01.04.22 - Andre Beging] - } + await Notification?.Error($"Fehler beim Anlegen: {addUserR.ErrorMessage}")!; else - { await LoadUsers(); - } } #endregion @@ -144,22 +134,5 @@ namespace FoodsharingSiegen.Server.Pages } #endregion - - private async Task SelectedChanged(List arg) - { - - } - - private async Task OnPasswordSet(User user) - { - var result = await UserService.SetPassword(user); - } - } - - public class Company - { - public string Name { get; set; } - - public string ISO { get; set; } } } \ No newline at end of file