diff --git a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor index a4c3e1c..b2d9e70 100644 --- a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor +++ b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor @@ -10,6 +10,11 @@
+ @if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador)) + { + + } + @Prospect.Name Profil öffnen diff --git a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs index 3ceea76..d9ee829 100644 --- a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs +++ b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs @@ -9,6 +9,8 @@ namespace FoodsharingSiegen.Server.Controls [Parameter] public Prospect? Prospect { get; set; } [Parameter] public AddInteractionModal InteractionModal { get; set; } = null!; + + [Parameter] public AddProspectModal ProspectModal { get; set; } = null!; [Parameter] public EventCallback RemoveInteraction { get; set; } diff --git a/FoodsharingSiegen.Server/Data/Service/ProspectService.cs b/FoodsharingSiegen.Server/Data/Service/ProspectService.cs index 79e1c45..613ae85 100644 --- a/FoodsharingSiegen.Server/Data/Service/ProspectService.cs +++ b/FoodsharingSiegen.Server/Data/Service/ProspectService.cs @@ -55,21 +55,6 @@ namespace FoodsharingSiegen.Server.Data.Service #endregion - public async Task RemoveInteraction(Guid interactionId) - { - try - { - Context.Interactions.Remove(new Interaction { Id = interactionId }); - await Context.SaveChangesAsync(); - - return new OperationResult(); - } - catch (Exception e) - { - return new OperationResult(e); - } - } - #region Public Method AddProspectAsync /// @@ -122,5 +107,60 @@ namespace FoodsharingSiegen.Server.Data.Service } #endregion + + #region Public Method RemoveInteraction + + /// + /// Removes the interaction using the specified interaction id (a. beging, 11.04.2022) + /// + /// The interaction id + /// A task containing the operation result + public async Task RemoveInteraction(Guid interactionId) + { + try + { + Context.Interactions.Remove(new Interaction { Id = interactionId }); + await Context.SaveChangesAsync(); + + return new OperationResult(); + } + catch (Exception e) + { + return new OperationResult(e); + } + } + + #endregion + + #region Public Method UpdateAsync + + /// + /// Updates the prospect (a. beging, 11.04.2022) + /// + /// The prospect + /// A task containing the operation result + public async Task UpdateAsync(Prospect prospect) + { + try + { + var entityProspect = await Context.Prospects.FirstOrDefaultAsync(x => x.Id == prospect.Id); + if (entityProspect == null) return new OperationResult(new Exception("Prospect not found")); + + entityProspect.Memo = prospect.Memo; + entityProspect.Name = prospect.Name; + entityProspect.FsId = prospect.FsId; + + var saveR = await Context.SaveChangesAsync(); + + if(saveR < 1) return new OperationResult(new Exception("Fehler beim speichern")); + return new OperationResult(); + } + catch (Exception e) + { + return new OperationResult(e); + } + } + + #endregion } } \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Dialogs/AddProspectModal.razor b/FoodsharingSiegen.Server/Dialogs/AddProspectModal.razor index 59e08db..aae5413 100644 --- a/FoodsharingSiegen.Server/Dialogs/AddProspectModal.razor +++ b/FoodsharingSiegen.Server/Dialogs/AddProspectModal.razor @@ -4,17 +4,40 @@ private Prospect Prospect { get; set; } = new(); + private string Header { get; set; } + + private string SaveButtonText { get; set; } + + private bool IsUpdateMode { get; set; } + [Parameter] public EventCallback OnAdd { get; set; } + + [Parameter] public EventCallback OnUpdate { get; set; } public async Task Show() { Prospect = new(); + Header = "Neuling hinzufügen"; + SaveButtonText = "Hinzufügen"; + await ModalReference.Show(); + } + + public async Task Show(Prospect prospect) + { + Prospect = prospect; + IsUpdateMode = true; + Header = $"{Prospect.Name} bearbeiten"; + SaveButtonText = "Speichern"; await ModalReference.Show(); } - private async Task AddProspect() + private async Task SaveClick() { - await OnAdd.InvokeAsync(Prospect); + if (IsUpdateMode) + await OnUpdate.InvokeAsync(Prospect); + else + await OnAdd.InvokeAsync(Prospect); + await ModalReference.Hide(); } } @@ -23,7 +46,7 @@ - Neuling hinzufügen + @Header @@ -38,7 +61,7 @@ - + \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/Prospects.razor b/FoodsharingSiegen.Server/Pages/Prospects.razor index 7d834a8..0f844ac 100644 --- a/FoodsharingSiegen.Server/Pages/Prospects.razor +++ b/FoodsharingSiegen.Server/Pages/Prospects.razor @@ -28,7 +28,7 @@

Aktuell:

- +
} @@ -43,11 +43,11 @@

Abgeschlossen:

- +
} - + \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs index 0841531..1eef25b 100644 --- a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs +++ b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs @@ -1,4 +1,4 @@ -using Blazorise; +using Blazorise; using FoodsharingSiegen.Contracts.Entity; using FoodsharingSiegen.Server.Data.Service; using FoodsharingSiegen.Server.Dialogs; @@ -6,18 +6,60 @@ using Microsoft.AspNetCore.Components; namespace FoodsharingSiegen.Server.Pages { + /// + /// The prospects class (a. beging, 11.04.2022) + /// public partial class Prospects { + #region Dependencies (Injected) + + /// + /// Gets or sets the value of the message service (ab) + /// [Inject] IMessageService MessageService { get; set; } + + /// + /// Gets or sets the value of the prospect service (ab) + /// [Inject] public ProspectService ProspectService { get; set; } = null!; + + /// + /// Gets or sets the value of the user service (ab) + /// [Inject] public UserService UserService { get; set; } = null!; - - public List? ProspectList { get; set; } - - public AddProspectModal ProspectModal { get; set; } = null!; + + #endregion + + #region Public Properties + + /// + /// Gets or sets the value of the interaction modal (ab) + /// public AddInteractionModal InteractionModal { get; set; } + + /// + /// Gets or sets the value of the prospect list (ab) + /// + public List? ProspectList { get; set; } + + /// + /// Gets or sets the value of the prospect modal (ab) + /// + public AddProspectModal ProspectModal { get; set; } = null!; + + /// + /// Gets or sets the value of the users (ab) + /// public List? Users { get; set; } + #endregion + + #region Override OnAfterRenderAsync + + /// + /// Ons the after render using the specified first render (a. beging, 11.04.2022) + /// + /// The first render protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) @@ -28,6 +70,13 @@ namespace FoodsharingSiegen.Server.Pages await base.OnAfterRenderAsync(firstRender); } + #endregion + + #region Override OnInitializedAsync + + /// + /// Ons the initialized (a. beging, 11.04.2022) + /// protected override async Task OnInitializedAsync() { var getUsersR = await UserService.GetUsersAsync(); @@ -37,6 +86,13 @@ namespace FoodsharingSiegen.Server.Pages await base.OnInitializedAsync(); } + #endregion + + #region Private Method LoadProspects + + /// + /// Loads the prospects (a. beging, 11.04.2022) + /// private async Task LoadProspects() { var prospectsR = await ProspectService.GetProspectsAsync(); @@ -45,18 +101,56 @@ namespace FoodsharingSiegen.Server.Pages await InvokeAsync(StateHasChanged); } - private async Task OnAddProspect(Prospect arg) - { - var addProspectR = await ProspectService.AddProspectAsync(arg); - if (addProspectR.Success) await LoadProspects(); - } + #endregion + #region Private Method OnAddInteraction + + /// + /// Ons the add interaction using the specified arg (a. beging, 11.04.2022) + /// + /// The arg private async Task OnAddInteraction(Interaction arg) { await ProspectService.AddInteraction(arg); await LoadProspects(); } + #endregion + + #region Private Method OnAddProspect + + /// + /// Ons the add prospect using the specified arg (a. beging, 11.04.2022) + /// + /// The arg + private async Task OnAddProspect(Prospect arg) + { + var addProspectR = await ProspectService.AddProspectAsync(arg); + if (addProspectR.Success) await LoadProspects(); + } + + #endregion + + #region Private Method OnUpdateProspect + + /// + /// Ons the update prospect using the specified prospect (a. beging, 11.04.2022) + /// + /// The prospect + private async Task OnUpdateProspect(Prospect prospect) + { + var updateProspectR = await ProspectService.UpdateAsync(prospect); + if (updateProspectR.Success) await LoadProspects(); + } + + #endregion + + #region Private Method RemoveInteraction + + /// + /// Removes the interaction using the specified arg (a. beging, 11.04.2022) + /// + /// The arg private async Task RemoveInteraction(Guid arg) { var confirm = await MessageService.Confirm("Interaktion wirklich löschen?", "Bestätigen", o => { @@ -70,7 +164,8 @@ namespace FoodsharingSiegen.Server.Pages await ProspectService.RemoveInteraction(arg); await LoadProspects(); } - } + + #endregion } } \ No newline at end of file