From 342d985cc9321c6a4b0c2a82451c31f5880124ea Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Sun, 18 Feb 2024 23:04:45 +0100 Subject: [PATCH] Implemented ContactInformationPartial for Manage Page --- .../Account/Pages/Manage/Index.razor | 7 +- .../Partials/ContactInformationPartial.razor | 100 ++++++++++++++++++ Wave/Data/ApplicationUser.cs | 2 +- .../Account/Pages/Manage/Index.de-DE.resx | 33 ++++++ .../Account/Pages/Manage/Index.resx | 33 ++++++ 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 Wave/Components/Account/Pages/Manage/Partials/ContactInformationPartial.razor diff --git a/Wave/Components/Account/Pages/Manage/Index.razor b/Wave/Components/Account/Pages/Manage/Index.razor index bc998f3..41edf83 100644 --- a/Wave/Components/Account/Pages/Manage/Index.razor +++ b/Wave/Components/Account/Pages/Manage/Index.razor @@ -31,8 +31,13 @@ } + @if (User is not null) { + + } + + @if (User is not null) { - + } diff --git a/Wave/Components/Account/Pages/Manage/Partials/ContactInformationPartial.razor b/Wave/Components/Account/Pages/Manage/Partials/ContactInformationPartial.razor new file mode 100644 index 0000000..ee9cfb6 --- /dev/null +++ b/Wave/Components/Account/Pages/Manage/Partials/ContactInformationPartial.razor @@ -0,0 +1,100 @@ +@using Wave.Data +@using Microsoft.AspNetCore.Identity +@using System.ComponentModel.DataAnnotations +@using Microsoft.AspNetCore.Mvc +@using Wave.Utilities +@using System.ComponentModel + +@inject UserManager UserManager +@inject IStringLocalizer Localizer +@inject IMessageDisplay Message + + + + + + + + + + + + + + + + + + + + +@code { + [CascadingParameter] + public required HttpContext HttpContext { get; set; } + + [Parameter] + public required ApplicationUser User { get; set; } + + [SupplyParameterFromForm(FormName = "update-contact")] + private InputModel Model { get; set; } = new(); + + protected override void OnInitialized() { + if (HttpContext.Request.Method.ToLower() == "post") return; + Model.ContactEmail = User.ContactEmail; + Model.ContactPhone = User.ContactPhone; + Model.ContactPhoneBusiness = User.ContactPhoneBusiness; + Model.ContactWebsite = User.ContactWebsite; + } + + private async Task OnValidSubmit() { + try { + User.ContactEmail = Model.ContactEmail ?? ""; + User.ContactPhone = Model.ContactPhone ?? ""; + User.ContactPhoneBusiness = Model.ContactPhoneBusiness ?? ""; + User.ContactWebsite = Model.ContactWebsite ?? ""; + + await UserManager.UpdateAsync(User); + Message.ShowSuccess(Localizer["Contact_Success"]); + } catch { + Message.ShowSuccess(Localizer["Contact_Error"]); + } + } + + private sealed class InputModel { + private string? _contactEmail; + private string? _contactPhone; + private string? _contactPhoneBusiness; + private string? _contactWebsite; + + [MaxLength(128), EmailAddress] + public string? ContactEmail { + get => string.IsNullOrWhiteSpace(_contactEmail) ? null : _contactEmail; + set => _contactEmail = value; + } + + [MaxLength(64), Phone] + public string? ContactPhone { + get => string.IsNullOrWhiteSpace(_contactPhone) ? null : _contactPhone; + set => _contactPhone = value; + } + + [MaxLength(64), Phone] + public string? ContactPhoneBusiness { + get => string.IsNullOrWhiteSpace(_contactPhoneBusiness) ? null : _contactPhoneBusiness; + set => _contactPhoneBusiness = value; + } + + [MaxLength(128), Url] + public string? ContactWebsite { + get => string.IsNullOrWhiteSpace(_contactWebsite) ? null : _contactWebsite; + set => _contactWebsite = value; + } + } + +} diff --git a/Wave/Data/ApplicationUser.cs b/Wave/Data/ApplicationUser.cs index 11d9f07..c9be878 100644 --- a/Wave/Data/ApplicationUser.cs +++ b/Wave/Data/ApplicationUser.cs @@ -28,6 +28,6 @@ public class ApplicationUser : IdentityUser { public string ContactPhone { get; set; } = string.Empty; [MaxLength(64), Phone, PersonalData] public string ContactPhoneBusiness { get; set; } = string.Empty; - [MaxLength(128), Phone, PersonalData] + [MaxLength(128), Url, PersonalData] public string ContactWebsite { get; set; } = string.Empty; } \ No newline at end of file diff --git a/Wave/Resources/Components/Account/Pages/Manage/Index.de-DE.resx b/Wave/Resources/Components/Account/Pages/Manage/Index.de-DE.resx index 57f9c4f..b6f1b9a 100644 --- a/Wave/Resources/Components/Account/Pages/Manage/Index.de-DE.resx +++ b/Wave/Resources/Components/Account/Pages/Manage/Index.de-DE.resx @@ -168,4 +168,37 @@ Ich koche seit dem jungen Alter von 7... Profil Öffnen + + Kontaktinformation + + + Fehler beim aktuallisieren der Kontaktinformationen + + + Öffentliche E-Mail + + + anna.muster@example.de + + + Kontaktinformationen aktuallisiert + + + Webseite + + + https://example.de + + + Telefon Geschäftlich + + + Telefon + + + +49 555 5555 555 + + + +49 555 5555 555 + \ No newline at end of file diff --git a/Wave/Resources/Components/Account/Pages/Manage/Index.resx b/Wave/Resources/Components/Account/Pages/Manage/Index.resx index c1ebfac..1240b57 100644 --- a/Wave/Resources/Components/Account/Pages/Manage/Index.resx +++ b/Wave/Resources/Components/Account/Pages/Manage/Index.resx @@ -168,4 +168,37 @@ I started cooking at the young age of 7... Go to Profile + + Contact Information + + + Public Email + + + john.doe@example.com + + + Phone + + + +55 555 5555 555 + + + Business Phone + + + +55 555 5555 555 + + + Website + + + https://example.com + + + Updated contact information + + + Error updated contact information + \ No newline at end of file