Compare commits
21
Commits
@@ -0,0 +1,155 @@
|
|||||||
|
---
|
||||||
|
name: EinAb Interaction Edit
|
||||||
|
overview: Add edit mode for EinAb (Einführung) interactions by extending the existing InteractionDialog with an update path, a new ProspectService.UpdateInteraction method, and an edit button in InteractionRow — scoped to EinAb initially but designed for future interaction types.
|
||||||
|
todos:
|
||||||
|
- id: service-update
|
||||||
|
content: Add ProspectService.UpdateInteraction + AuditType.EditInteraction + AuditHelper case
|
||||||
|
status: completed
|
||||||
|
- id: dialog-edit-mode
|
||||||
|
content: Extend InteractionDialog with IsEditMode, IsEditable helper, and unified SaveAsync
|
||||||
|
status: completed
|
||||||
|
- id: row-edit-button
|
||||||
|
content: Add AllowEdit/EditClick to InteractionRow with pencil icon in item list
|
||||||
|
status: completed
|
||||||
|
- id: container-wire
|
||||||
|
content: Add EditInteraction handler in ProspectContainer and enable AllowEdit on EinAb row
|
||||||
|
status: completed
|
||||||
|
isProject: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# EinAb Interaction Edit Mode
|
||||||
|
|
||||||
|
## Current State
|
||||||
|
|
||||||
|
EinAb interactions ("Einführung") are multi-entry (minimum 3) and support date, business/person fields (`Info1`/`Info2`), and feedback (thumbs up/down/neutral). Users can **add** via [`InteractionDialog`](FoodsharingSiegen.Server/Dialogs/InteractionDialog.razor) and **remove** via the X icon in [`InteractionRow`](FoodsharingSiegen.Server/Controls/InteractionRow.razor). There is no update path at any layer.
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
subgraph current [Current Flow]
|
||||||
|
AddBtn["+ Button"] --> Dialog["InteractionDialog"]
|
||||||
|
Dialog --> AddSvc["ProspectService.AddInteraction"]
|
||||||
|
XBtn["X Button"] --> Confirm["ConfirmDialog"]
|
||||||
|
Confirm --> RemoveSvc["ProspectService.RemoveInteraction"]
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
## Target Flow
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
subgraph target [New Edit Flow]
|
||||||
|
EditBtn["Pencil Button"] --> EditDialog["InteractionDialog (edit mode)"]
|
||||||
|
EditDialog --> UpdateSvc["ProspectService.UpdateInteraction"]
|
||||||
|
end
|
||||||
|
AddBtn["+ Button"] --> AddDialog["InteractionDialog (add mode)"]
|
||||||
|
AddDialog --> AddSvc["ProspectService.AddInteraction"]
|
||||||
|
XBtn["X Button"] --> RemoveSvc["ProspectService.RemoveInteraction"]
|
||||||
|
```
|
||||||
|
|
||||||
|
Edit and remove will coexist. Only EinAb gets the edit button initially.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Service Layer — `UpdateInteraction`
|
||||||
|
|
||||||
|
**File:** [`FoodsharingSiegen.Server/Data/Service/ProspectService.cs`](FoodsharingSiegen.Server/Data/Service/ProspectService.cs)
|
||||||
|
|
||||||
|
Add `UpdateInteraction(Interaction interaction)` following the existing `UpdateAsync(Prospect)` pattern:
|
||||||
|
|
||||||
|
- Load tracked entity by `interaction.Id`; return error if not found
|
||||||
|
- Update editable fields only: `Date`, `Info1`, `Info2`, `Feedback`, `FeedbackInfo`, `Alert`
|
||||||
|
- Do **not** change: `Id`, `Created`, `UserID` (preserves original creator), `Type`, `ProspectID`, `NotNeeded`
|
||||||
|
- Set parent `Prospect.Modified = DateTime.UtcNow`
|
||||||
|
- Audit via new `AuditType.EditInteraction` (prospect name + interaction type as data)
|
||||||
|
- Detach entities after save (consistent with `AddInteraction`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Audit Support
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- [`FoodsharingSiegen.Contracts/Enums/AuditType.cs`](FoodsharingSiegen.Contracts/Enums/AuditType.cs) — add `EditInteraction = 160`
|
||||||
|
- [`FoodsharingSiegen.Server/Data/AuditHelper.cs`](FoodsharingSiegen.Server/Data/AuditHelper.cs) — add case: `"hat eine Interaktion bei {Data1} bearbeitet: {Data2}"`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. InteractionDialog — Add/Edit Mode
|
||||||
|
|
||||||
|
**Files:** [`InteractionDialog.razor.cs`](FoodsharingSiegen.Server/Dialogs/InteractionDialog.razor.cs), [`InteractionDialog.razor`](FoodsharingSiegen.Server/Dialogs/InteractionDialog.razor)
|
||||||
|
|
||||||
|
Follow the [`EditProspectDialog`](FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs) pattern (`IsUpdateMode` + conditional save):
|
||||||
|
|
||||||
|
- Add `IsEditMode` parameter and a static extensibility helper:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static bool IsEditable(InteractionType type) => type switch
|
||||||
|
{
|
||||||
|
InteractionType.EinAb => true,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
- Extend `InteractionDialogParameter` with optional `Interaction? ExistingInteraction = null`
|
||||||
|
- In `ShowAsync`: when `ExistingInteraction` is provided, pass it as the bound `Interaction` and set `IsEditMode = true`; otherwise keep current "new interaction" behavior
|
||||||
|
- Replace `AddInteractionAsync` with a unified `SaveAsync`:
|
||||||
|
- **Add mode:** `Interaction.UserID = CurrentUser.Id` → `ProspectService.AddInteraction`
|
||||||
|
- **Edit mode:** `ProspectService.UpdateInteraction`
|
||||||
|
- In the razor template, change OK button label: `"OK"` (add) / `"Speichern"` (edit) — same fields render in both modes (date, Betrieb, Mit wem, feedback)
|
||||||
|
|
||||||
|
**Header text** (in `ProspectContainer`): `"Einführung für {Name} bearbeiten"` for edit vs existing `"… eintragen"` for add.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. InteractionRow — Edit Button
|
||||||
|
|
||||||
|
**Files:** [`InteractionRow.razor`](FoodsharingSiegen.Server/Controls/InteractionRow.razor), [`InteractionRow.razor.cs`](FoodsharingSiegen.Server/Controls/InteractionRow.razor.cs)
|
||||||
|
|
||||||
|
- Add parameters:
|
||||||
|
- `bool AllowEdit { get; set; }` — controls visibility
|
||||||
|
- `Func<Guid, Task>? EditClick { get; set; }` — callback with interaction Id
|
||||||
|
- In the per-item loop (lines 46–66), show a pencil icon (`fa-solid fa-pen-to-square`) next to the existing X remove icon when `AllowEdit && AllowInteraction`
|
||||||
|
- Same visibility guard as remove: hidden when prospect is complete (unless Complete-type interaction)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. ProspectContainer — Wire Up Edit
|
||||||
|
|
||||||
|
**Files:** [`ProspectContainer.razor`](FoodsharingSiegen.Server/Controls/ProspectContainer.razor), [`ProspectContainer.razor.cs`](FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs)
|
||||||
|
|
||||||
|
- Add `EditInteraction(Guid interactionId)`:
|
||||||
|
- Look up interaction from `Prospect.Interactions`
|
||||||
|
- Guard: only proceed if `InteractionDialog.IsEditable(interaction.Type)`
|
||||||
|
- Open dialog with existing interaction and header `"Einführung für {Name} bearbeiten"`
|
||||||
|
- On success → `OnDataChanged()`
|
||||||
|
- On the EinAb `InteractionRow`, add:
|
||||||
|
- `AllowEdit="true"`
|
||||||
|
- `EditClick="@EditInteraction"`
|
||||||
|
|
||||||
|
Other interaction rows remain unchanged (no edit button).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Extensibility Notes
|
||||||
|
|
||||||
|
To enable edit for another type later:
|
||||||
|
1. Add the type to `InteractionDialog.IsEditable()`
|
||||||
|
2. Set `AllowEdit="true"` on that row in `ProspectContainer.razor`
|
||||||
|
3. Ensure field labels in `ShowAsync`'s type switch cover that type (already done for several types)
|
||||||
|
|
||||||
|
No separate edit dialog component is needed — the same form handles both modes.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Files Changed (summary)
|
||||||
|
|
||||||
|
| File | Change |
|
||||||
|
|------|--------|
|
||||||
|
| `ProspectService.cs` | New `UpdateInteraction` method |
|
||||||
|
| `AuditType.cs` | New `EditInteraction` enum value |
|
||||||
|
| `AuditHelper.cs` | New audit text case |
|
||||||
|
| `InteractionDialog.razor.cs` | Edit mode, `IsEditable`, unified save |
|
||||||
|
| `InteractionDialog.razor` | Conditional button label |
|
||||||
|
| `InteractionRow.razor` / `.cs` | Edit button + parameters |
|
||||||
|
| `ProspectContainer.razor` / `.cs` | `EditInteraction` handler, EinAb wiring |
|
||||||
|
|
||||||
|
No database migration required — all editable fields already exist on the `Interaction` entity.
|
||||||
@@ -23,6 +23,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
dotnet-version: "9.0.x"
|
dotnet-version: "9.0.x"
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: dotnet test
|
||||||
|
|
||||||
- name: Publish server project
|
- name: Publish server project
|
||||||
run: dotnet publish ./FoodsharingSiegen.Server/FoodsharingSiegen.Server.csproj -c Release -o ./Publish/Server
|
run: dotnet publish ./FoodsharingSiegen.Server/FoodsharingSiegen.Server.csproj -c Release -o ./Publish/Server
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
dotnet-version: "9.0.x"
|
dotnet-version: "9.0.x"
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: dotnet test
|
||||||
|
|
||||||
- name: Publish server project
|
- name: Publish server project
|
||||||
run: dotnet publish ./FoodsharingSiegen.Server/FoodsharingSiegen.Server.csproj -c Release -o ./Publish/Server
|
run: dotnet publish ./FoodsharingSiegen.Server/FoodsharingSiegen.Server.csproj -c Release -o ./Publish/Server
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
## Plan: Prospect list performance overhaul
|
||||||
|
|
||||||
|
The current bottleneck is not just data volume; it is the combination of loading every prospect and every nested interaction at once, then rendering all cards in the browser. In the current flow, each page loads the full list from `ProspectService.GetProspectsAsync`, includes all `Images` and `Interactions` plus each `User`, and then `ProspectGrid` renders every card through `Repeater` without virtualization. With hundreds of records, the UI does repeated LINQ work per card and hits a lot of DOM work in one render.
|
||||||
|
|
||||||
|
### Recommended approach
|
||||||
|
Use a two-part fix: reduce the server-side payload and virtualize the client-side rendering. The best gains will come from paginating or virtualizing the list, then trimming unnecessary nested load and repeated per-row calculations.
|
||||||
|
|
||||||
|
### Steps
|
||||||
|
1. Profile the bottleneck and cap the visible list size
|
||||||
|
- Confirm the prospect pages are loading all records at once because `GetProspectsAsync` currently does `ToListAsync()` without paging or limit.
|
||||||
|
- Add a page-size/virtualized flow so only the visible slice is fetched and rendered.
|
||||||
|
- This change must happen in the page and service layer before any UI refactor.
|
||||||
|
|
||||||
|
2. Reduce EF payload in `ProspectService.GetProspectsAsync`
|
||||||
|
- Update `FoodsharingSiegen.Server/Data/Service/ProspectService.cs` so it accepts pagination arguments (`skip`, `take`, optional filters) instead of returning the full unbounded list.
|
||||||
|
- Keep the query as `AsNoTracking()` but avoid eager-loading all `Images` and every `User` for every prospect when the page only needs a summary view.
|
||||||
|
- For the list pages, load only the subset needed for the grid and defer expensive image/user data until a detail action opens.
|
||||||
|
- Filter and sort should happen server-side when possible to avoid moving hundreds of full entities into memory and then filtering again in the browser.
|
||||||
|
|
||||||
|
3. Replace the full list render with virtualization
|
||||||
|
- Convert the repeated list in `FoodsharingSiegen.Server/Controls/ProspectGrid.razor` to a virtualized list or paged container, rather than rendering a full `<Repeater Items="@Prospects">` for all rows.
|
||||||
|
- Keep the visible cards only; the hidden rows should not be in the DOM.
|
||||||
|
- This removes the biggest DOM cost on pages with hundreds of entries.
|
||||||
|
|
||||||
|
4. Remove repeated per-row computation in the card components
|
||||||
|
- In `FoodsharingSiegen.Server/Controls/InteractionRow.razor.cs`, the properties `Interactions`, `Done`, `Alert`, `NotNeeded` recalculate on every render from a list of nested items. With hundreds of cards this becomes expensive.
|
||||||
|
- Replace repeated `Where()` chains with precomputed values from the loaded model or cached values at the prospect object level.
|
||||||
|
- In `FoodsharingSiegen.Contracts/Entity/Prospect.cs`, avoid deriving `Complete` from `Interactions.Any()` on every render when a summary value is already known in the data model.
|
||||||
|
- Keep the card logic free of repeated `ToList()` and `Any()` chains during render.
|
||||||
|
|
||||||
|
5. Tighten data shaping for each list page
|
||||||
|
- The onboarding, verification, archive, and done pages all load the same full set of entities and then apply client-side filters with `ApplyFilter` and `ApplySort` in `FoodsharingSiegen.Shared/Helper/FilterHelper.cs`.
|
||||||
|
- Move the expensive filtering/sorting to SQL or at least to the server-side query layer; reduce the list to a smaller result set before it reaches the UI.
|
||||||
|
- Keep `ProspectList.ApplyFilter` only as a fallback for small local slices, not as the primary path for large lists.
|
||||||
|
|
||||||
|
6. Verify the improvement with focused checks
|
||||||
|
- Measure page load time before and after with a realistic dataset of several hundred prospects.
|
||||||
|
- Validate that the list stays responsive during scrolling and interaction changes.
|
||||||
|
- Run the relevant .NET tests and render-check the prospect pages manually.
|
||||||
|
|
||||||
|
### Relevant files
|
||||||
|
- `FoodsharingSiegen.Server/Data/Service/ProspectService.cs` — main query and database fetch point.
|
||||||
|
- `FoodsharingSiegen.Server/Controls/ProspectGrid.razor` — full-list rendering path.
|
||||||
|
- `FoodsharingSiegen.Server/Controls/ProspectContainer.razor` — per-card DOM and nested component rendering.
|
||||||
|
- `FoodsharingSiegen.Server/Controls/InteractionRow.razor.cs` — repeated LINQ work in each row.
|
||||||
|
- `FoodsharingSiegen.Contracts/Entity/Prospect.cs` — computed values that trigger repeated work.
|
||||||
|
- `FoodsharingSiegen.Shared/Helper/FilterHelper.cs` — client-side list filtering/sorting on large sets.
|
||||||
|
- `FoodsharingSiegen.Server/Pages/Prospects.razor`, `FoodsharingSiegen.Server/Pages/ProspectsAll.razor`, `FoodsharingSiegen.Server/Pages/ProspectsVerify.razor`, `FoodsharingSiegen.Server/Pages/ProspectsDone.razor` — list page orchestration and data flow.
|
||||||
|
|
||||||
|
### Key decision
|
||||||
|
The highest-value fix is to stop returning and rendering all prospects at once. A virtualized/paged list with a trimmed query shape will provide the biggest speedup and should be the first implementation target.
|
||||||
|
|
||||||
|
### Optional follow-up improvements
|
||||||
|
- Precompute a lightweight summary model for the grid instead of the full `Prospect` entity.
|
||||||
|
- Add a server-side count query to support proper paging without loading every record.
|
||||||
|
- Consider splitting the list into “summary” and “detail” data so the main dashboard never loads full nested relationship graphs by default.
|
||||||
@@ -42,7 +42,12 @@ namespace FoodsharingSiegen.Contracts.Entity
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(Groups)) return new List<UserGroup>();
|
if (string.IsNullOrWhiteSpace(Groups)) return new List<UserGroup>();
|
||||||
var stringList = Groups.Split(",");
|
var stringList = Groups.Split(",");
|
||||||
var enumList = stringList.Where(x => !string.IsNullOrWhiteSpace(x)).Select(Enum.Parse<UserGroup>).ToList();
|
var enumList = stringList
|
||||||
|
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||||
|
.Select(x => Enum.TryParse<UserGroup>(x.Trim(), out var result) ? result : (UserGroup?)null)
|
||||||
|
.Where(x => x.HasValue)
|
||||||
|
.Select(x => x!.Value)
|
||||||
|
.ToList();
|
||||||
return enumList;
|
return enumList;
|
||||||
}
|
}
|
||||||
set => Groups = string.Join(",", value);
|
set => Groups = string.Join(",", value);
|
||||||
|
|||||||
@@ -62,7 +62,37 @@ namespace FoodsharingSiegen.Contracts.Enums
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The remove interaction audit type
|
/// The remove interaction audit type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
RemoveInteraction = 100
|
RemoveInteraction = 100,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The delete prospect images audit type
|
||||||
|
/// </summary>
|
||||||
|
DeleteProspectImages = 110,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The view prospect images audit type
|
||||||
|
/// </summary>
|
||||||
|
ViewProspectImages = 120,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The upload prospect image audit type
|
||||||
|
/// </summary>
|
||||||
|
UploadProspectImage = 130,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The request password reset audit type
|
||||||
|
/// </summary>
|
||||||
|
RequestPasswordReset = 140,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The change own password audit type
|
||||||
|
/// </summary>
|
||||||
|
ChangeOwnPassword = 150,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The edit interaction audit type
|
||||||
|
/// </summary>
|
||||||
|
EditInteraction = 160
|
||||||
|
|
||||||
#endregion Prospects
|
#endregion Prospects
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace FoodsharingSiegen.Contracts.Helper
|
|||||||
{
|
{
|
||||||
var type = enumVal.GetType();
|
var type = enumVal.GetType();
|
||||||
var memInfo = type.GetMember(enumVal.ToString());
|
var memInfo = type.GetMember(enumVal.ToString());
|
||||||
|
if (memInfo.Length == 0) return null;
|
||||||
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
|
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
|
||||||
return attributes.Length > 0 ? (T)attributes[0] : null;
|
return attributes.Length > 0 ? (T)attributes[0] : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,10 @@ namespace FoodsharingSiegen.Contracts.Model
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The get prospects parameter
|
/// The get prospects parameter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record GetProspectsParameter(List<InteractionType>? MustHaveInteractions = null, List<InteractionType>? CannotHaveInteractions = null, bool IncludeDeleted = false);
|
public record GetProspectsParameter(
|
||||||
|
List<InteractionType>? MustHaveInteractions = null,
|
||||||
|
List<InteractionType>? CannotHaveInteractions = null,
|
||||||
|
bool IncludeDeleted = false,
|
||||||
|
int Skip = 0,
|
||||||
|
int Take = 50);
|
||||||
}
|
}
|
||||||
@@ -251,6 +251,14 @@ namespace FoodsharingSiegen.Server.Auth
|
|||||||
user.ResetToken = resetToken;
|
user.ResetToken = resetToken;
|
||||||
user.ResetTokenExpiry = DateTime.UtcNow.AddMinutes(30);
|
user.ResetTokenExpiry = DateTime.UtcNow.AddMinutes(30);
|
||||||
|
|
||||||
|
Context.Audits?.Add(new Audit
|
||||||
|
{
|
||||||
|
Created = DateTime.Now,
|
||||||
|
Type = AuditType.RequestPasswordReset,
|
||||||
|
UserID = user.Id,
|
||||||
|
Data1 = user.Mail
|
||||||
|
});
|
||||||
|
|
||||||
await Context.SaveChangesAsync();
|
await Context.SaveChangesAsync();
|
||||||
|
|
||||||
var resetLink = $"{baseUri.TrimEnd('/')}/reset-password/{resetToken}";
|
var resetLink = $"{baseUri.TrimEnd('/')}/reset-password/{resetToken}";
|
||||||
|
|||||||
@@ -45,11 +45,29 @@ else
|
|||||||
|
|
||||||
@foreach (var interaction in Interactions)
|
@foreach (var interaction in Interactions)
|
||||||
{
|
{
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end align-items-center interaction-row-action-group">
|
||||||
@if ((Prospect is not { Complete: true } || interaction.Type == InteractionType.Complete) && AllowInteraction)
|
@if ((Prospect is not { Complete: true } || interaction.Type == InteractionType.Complete) && AllowInteraction)
|
||||||
{
|
{
|
||||||
<a style="display: inline-block;"" href=""><i class="fa-solid fa-square-xmark" @onclick="async () => { if (RemoveClick != null) await RemoveClick.Invoke(interaction.Id); }" @onclick:preventDefault></i></a>
|
<div class="d-flex align-items-center interaction-row-actions">
|
||||||
} else {
|
@if (AllowEdit)
|
||||||
|
{
|
||||||
|
<Button Size="Size.Small"
|
||||||
|
Class="interaction-row-action interaction-row-action-edit"
|
||||||
|
title="Eintrag bearbeiten"
|
||||||
|
Clicked="@(async () => { if (EditClick != null) await EditClick.Invoke(interaction.Id); })">
|
||||||
|
<i class="fa-solid fa-pen-to-square"></i>
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
<Button Size="Size.Small"
|
||||||
|
Class="interaction-row-action interaction-row-action-delete"
|
||||||
|
title="Eintrag löschen"
|
||||||
|
Clicked="@(async () => { if (RemoveClick != null) await RemoveClick.Invoke(interaction.Id); })">
|
||||||
|
<i class="fa-solid fa-square-xmark"></i>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
<span>•</span>
|
<span>•</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -62,6 +62,18 @@ namespace FoodsharingSiegen.Server.Controls
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<Guid, Task>? RemoveClick { get; set; }
|
public Func<Guid, Task>? RemoveClick { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether editing existing interactions is allowed.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public bool AllowEdit { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the callback invoked when an interaction is edited.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public Func<Guid, Task>? EditClick { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value of the type (ab)
|
/// Gets or sets the value of the type (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -85,7 +97,9 @@ namespace FoodsharingSiegen.Server.Controls
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the value of the interactions (ab)
|
/// Gets the value of the interactions (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Interaction> Interactions => Prospect?.Interactions.Where(x => x.Type == Type).ToList() ?? [];
|
private List<Interaction> Interactions => Prospect?.Interactions is null
|
||||||
|
? []
|
||||||
|
: [.. Prospect.Interactions.Where(x => x.Type == Type)];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the value of the not needed (ab)
|
/// Gets the value of the not needed (ab)
|
||||||
|
|||||||
@@ -1,4 +1,38 @@
|
|||||||
tr.done th {
|
.interaction-row-action-group {
|
||||||
|
gap: 0.25rem;
|
||||||
|
min-width: 2.7rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interaction-row-actions {
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interaction-row-action {
|
||||||
|
width: 1rem;
|
||||||
|
min-width: 1.25rem;
|
||||||
|
height: 1.25rem;
|
||||||
|
min-height: 1.25rem;
|
||||||
|
padding: 0;
|
||||||
|
display: inline-flex !important;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 0.7rem;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interaction-row-action i {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interaction-row-action-edit i {
|
||||||
|
color: #1f2f3a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interaction-row-action-delete i {
|
||||||
|
color: rgb(153, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
tr.done th {
|
||||||
color: #64ae24;
|
color: #64ae24;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,8 @@
|
|||||||
AllowInteraction="@(StateFilter == ProspectStateFilter.OnBoarding && CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))"
|
AllowInteraction="@(StateFilter == ProspectStateFilter.OnBoarding && CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))"
|
||||||
AddClick="AddInteraction"
|
AddClick="AddInteraction"
|
||||||
RemoveClick="@RemoveInteraction"
|
RemoveClick="@RemoveInteraction"
|
||||||
|
AllowEdit="true"
|
||||||
|
EditClick="@EditInteraction"
|
||||||
Multiple="true"
|
Multiple="true"
|
||||||
Minimum="3"
|
Minimum="3"
|
||||||
ButtonIconClass="fa-solid fa-plus"
|
ButtonIconClass="fa-solid fa-plus"
|
||||||
|
|||||||
@@ -43,12 +43,43 @@ namespace FoodsharingSiegen.Server.Controls
|
|||||||
{
|
{
|
||||||
var headerText = $"{type.Translate(AppSettings)} für {Prospect.Name} eintragen";
|
var headerText = $"{type.Translate(AppSettings)} für {Prospect.Name} eintragen";
|
||||||
|
|
||||||
await InteractionDialog.ShowAsync(ModalService, new(type, Prospect.Id, headerText, OnDataChanged));
|
Func<Task> onSuccess = async () =>
|
||||||
|
{
|
||||||
|
if (type == InteractionType.IdCheck && Prospect.Images != null && Prospect.Images.Count > 0)
|
||||||
|
{
|
||||||
|
await ConfirmDialog.ShowAsync(ModalService, "Personalausweisbilder löschen?", $"Möchtest du die Personalausweisbilder von {Prospect.Name} löschen? Diese werden für die weitere Bearbeitung nicht mehr benötigt und enthalten persönliche Daten.", async () =>
|
||||||
|
{
|
||||||
|
var result = await ProspectService.DeleteVerificationImagesAsync(Prospect.Id);
|
||||||
|
await OnDataChanged();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await OnDataChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
await InteractionDialog.ShowAsync(ModalService, new(type, Prospect.Id, headerText, onSuccess));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Private Method EditInteraction
|
||||||
|
|
||||||
|
private async Task EditInteraction(Guid interactionId)
|
||||||
|
{
|
||||||
|
if (Prospect == null || OnDataChanged == null) return;
|
||||||
|
|
||||||
|
var interaction = Prospect.Interactions.FirstOrDefault(x => x.Id == interactionId);
|
||||||
|
if (interaction == null || !InteractionDialog.IsEditable(interaction.Type)) return;
|
||||||
|
|
||||||
|
var headerText = $"{interaction.Type.Translate(AppSettings)} für {Prospect.Name} bearbeiten";
|
||||||
|
|
||||||
|
Func<Task> onSuccess = async () => await OnDataChanged();
|
||||||
|
|
||||||
|
await InteractionDialog.ShowAsync(ModalService, new(interaction.Type, Prospect.Id, headerText, onSuccess, interaction));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Private Method DeleteProspectAsync
|
#region Private Method DeleteProspectAsync
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
@using FoodsharingSiegen.Contracts.Enums
|
@using FoodsharingSiegen.Contracts.Enums
|
||||||
|
@using Microsoft.JSInterop
|
||||||
|
@implements IAsyncDisposable
|
||||||
|
@inject IJSRuntime JSRuntime
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
[Parameter] public List<Prospect>? Prospects { get; set; }
|
[Parameter] public List<Prospect>? Prospects { get; set; }
|
||||||
@@ -7,19 +10,95 @@
|
|||||||
|
|
||||||
[Parameter] public Func<Task>? OnDataChanged { get; set; }
|
[Parameter] public Func<Task>? OnDataChanged { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public EventCallback OnLoadMore { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public bool IsLoadingMore { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public bool HasMore { get; set; }
|
||||||
|
|
||||||
[Parameter] public string GridClass { get; set; } = string.Empty;
|
[Parameter] public string GridClass { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
private IJSObjectReference? _module;
|
||||||
|
private DotNetObjectReference<ProspectGrid>? _dotNetHelper;
|
||||||
|
private string _gridId = $"prospect-grid-{Guid.NewGuid():N}";
|
||||||
|
private bool _isJsBound;
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (_disposed || !firstRender || _isJsBound) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_dotNetHelper ??= DotNetObjectReference.Create(this);
|
||||||
|
_module ??= await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/prospect-grid.js");
|
||||||
|
await _module.InvokeVoidAsync("attachScrollLoader", _gridId, _dotNetHelper);
|
||||||
|
_isJsBound = true;
|
||||||
|
}
|
||||||
|
catch (JSDisconnectedException)
|
||||||
|
{
|
||||||
|
// Ignore browser disconnect during teardown.
|
||||||
|
}
|
||||||
|
catch (ObjectDisposedException)
|
||||||
|
{
|
||||||
|
// Ignore late render after the component is being torn down.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[JSInvokable]
|
||||||
|
public async Task OnScrollNearBottom()
|
||||||
|
{
|
||||||
|
if (OnLoadMore.HasDelegate && !IsLoadingMore && HasMore)
|
||||||
|
{
|
||||||
|
await OnLoadMore.InvokeAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
_disposed = true;
|
||||||
|
|
||||||
|
if (_module is not null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _module.InvokeVoidAsync("disposeScrollLoader", _gridId);
|
||||||
|
}
|
||||||
|
catch (JSDisconnectedException)
|
||||||
|
{
|
||||||
|
// ignored; the circuit is already disconnected
|
||||||
|
}
|
||||||
|
catch (ObjectDisposedException)
|
||||||
|
{
|
||||||
|
// ignored; the JS runtime is already disposed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_dotNetHelper?.Dispose();
|
||||||
|
_dotNetHelper = null;
|
||||||
|
_isJsBound = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
<h6>@(Prospects?.Count ?? 0) Ergebnisse</h6>
|
<h6>@(Prospects?.Count ?? 0) Ergebnisse</h6>
|
||||||
|
|
||||||
@if (Prospects?.Any() == true)
|
@if (Prospects?.Any() == true)
|
||||||
{
|
{
|
||||||
<div class="prospect-grid @GridClass">
|
<div id="@_gridId" class="prospect-grid @GridClass" style="max-height: calc(100vh - 250px); overflow-y: auto;">
|
||||||
<Repeater Items="@Prospects">
|
@foreach (var prospect in Prospects)
|
||||||
<ProspectContainer
|
{
|
||||||
Prospect="context"
|
<ProspectContainer @key="prospect.Id"
|
||||||
|
Prospect="prospect"
|
||||||
OnDataChanged="@OnDataChanged"
|
OnDataChanged="@OnDataChanged"
|
||||||
StateFilter="StateFilter"></ProspectContainer>
|
StateFilter="StateFilter"></ProspectContainer>
|
||||||
</Repeater>
|
}
|
||||||
|
|
||||||
|
@if (IsLoadingMore)
|
||||||
|
{
|
||||||
|
<div class="d-flex justify-content-center py-3 text-muted">
|
||||||
|
<span class="me-2"><i class="fa-solid fa-spinner fa-spin"></i></span>
|
||||||
|
Weitere laden...
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,18 @@ namespace FoodsharingSiegen.Server.Data
|
|||||||
return $"hat dem Neuling {audit.Data1} folgendes hinzugefügt: {audit.Data2}";
|
return $"hat dem Neuling {audit.Data1} folgendes hinzugefügt: {audit.Data2}";
|
||||||
case AuditType.RemoveInteraction:
|
case AuditType.RemoveInteraction:
|
||||||
return $"hat eine Interaktion bei {audit.Data1} gelöscht.";
|
return $"hat eine Interaktion bei {audit.Data1} gelöscht.";
|
||||||
|
case AuditType.EditInteraction:
|
||||||
|
return $"hat eine Interaktion bei {audit.Data1} bearbeitet: {audit.Data2}";
|
||||||
|
case AuditType.DeleteProspectImages:
|
||||||
|
return $"hat die Bilder von {audit.Data1} gelöscht.";
|
||||||
|
case AuditType.ViewProspectImages:
|
||||||
|
return $"hat die Bilder von {audit.Data1} angesehen.";
|
||||||
|
case AuditType.UploadProspectImage:
|
||||||
|
return $"hat ein Bild für {audit.Data1} hochgeladen.";
|
||||||
|
case AuditType.RequestPasswordReset:
|
||||||
|
return $"hat ein Passwort-Reset für {audit.Data1} angefordert.";
|
||||||
|
case AuditType.ChangeOwnPassword:
|
||||||
|
return $"hat das eigene Passwort geändert.";
|
||||||
case AuditType.None:
|
case AuditType.None:
|
||||||
default:
|
default:
|
||||||
return $"{audit.Data1}, {audit.Data2}";
|
return $"{audit.Data1}, {audit.Data2}";
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ namespace FoodsharingSiegen.Server.Data
|
|||||||
/// <param name="options">The options (ab)</param>
|
/// <param name="options">The options (ab)</param>
|
||||||
public FsContext(DbContextOptions<FsContext> options) : base(options)
|
public FsContext(DbContextOptions<FsContext> options) : base(options)
|
||||||
{
|
{
|
||||||
Database.Migrate();
|
if (Database.IsRelational())
|
||||||
|
{
|
||||||
|
Database.Migrate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
Data2 = data2
|
Data2 = data2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine(DateTime.Now.ToString() + " " + CurrentUser?.Name + " " + AuditHelper.CreateText(audit));
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
Context.Audits?.Add(audit);
|
Context.Audits?.Add(audit);
|
||||||
var saveR = await Context.SaveChangesAsync();
|
var saveR = await Context.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -61,29 +65,56 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Method Load
|
#region Public Method GetCount
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the count (a. beging, 23.05.2022)
|
/// Gets the total count (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count">The count</param>
|
|
||||||
/// <param name="type">The type</param>
|
/// <param name="type">The type</param>
|
||||||
/// <returns>A task containing an operation result of list audit</returns>
|
/// <returns>A task containing an operation result of count</returns>
|
||||||
public async Task<OperationResult<List<Audit>>> Load(int count, AuditType? type = null)
|
public async Task<OperationResult<int>> GetCount(AuditType? type = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.CompletedTask;
|
var query = Context.Audits?.AsQueryable();
|
||||||
|
|
||||||
var query = Context.Audits?.Include(x => x.User).OrderByDescending(x => x.Created).AsQueryable();
|
|
||||||
|
|
||||||
if (count > 0)
|
|
||||||
query = query?.Take(count);
|
|
||||||
|
|
||||||
if (type != null)
|
if (type != null)
|
||||||
query = query?.Where(x => x.Type == type);
|
query = query?.Where(x => x.Type == type);
|
||||||
|
|
||||||
var mat = query?.ToList();
|
if (query == null) return new(0);
|
||||||
|
|
||||||
|
var count = await query.CountAsync();
|
||||||
|
return new(count);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Method LoadPage
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the page of audits (ab)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="skip">The skip count</param>
|
||||||
|
/// <param name="take">The take count</param>
|
||||||
|
/// <param name="type">The type</param>
|
||||||
|
/// <returns>A task containing an operation result of list audit</returns>
|
||||||
|
public async Task<OperationResult<List<Audit>>> LoadPage(int skip, int take, AuditType? type = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var query = Context.Audits?.Include(x => x.User).OrderByDescending(x => x.Created).AsQueryable();
|
||||||
|
|
||||||
|
if (type != null)
|
||||||
|
query = query?.Where(x => x.Type == type);
|
||||||
|
|
||||||
|
query = query?.Skip(skip).Take(take);
|
||||||
|
|
||||||
|
var mat = await query!.ToListAsync();
|
||||||
|
|
||||||
if (mat != null) return new(mat);
|
if (mat != null) return new(mat);
|
||||||
|
|
||||||
|
|||||||
@@ -116,15 +116,21 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
.Include(x => x.Interactions.OrderBy(i => i.Date)).ThenInclude(x => x.User)
|
.Include(x => x.Interactions.OrderBy(i => i.Date)).ThenInclude(x => x.User)
|
||||||
.OrderBy(x => x.Name).AsQueryable();
|
.OrderBy(x => x.Name).AsQueryable();
|
||||||
|
|
||||||
if(parameter.MustHaveInteractions != null && parameter.MustHaveInteractions.Any())
|
if (parameter.MustHaveInteractions != null && parameter.MustHaveInteractions.Any())
|
||||||
prospectsQuery = prospectsQuery.Where(x => x.Interactions.Any(i => parameter.MustHaveInteractions.Contains(i.Type)));
|
prospectsQuery = prospectsQuery.Where(x => x.Interactions.Any(i => parameter.MustHaveInteractions.Contains(i.Type)));
|
||||||
|
|
||||||
if(parameter.CannotHaveInteractions != null && parameter.CannotHaveInteractions.Any())
|
if (parameter.CannotHaveInteractions != null && parameter.CannotHaveInteractions.Any())
|
||||||
prospectsQuery = prospectsQuery.Where(x => x.Interactions.All(i => !parameter.CannotHaveInteractions.Contains(i.Type)));
|
prospectsQuery = prospectsQuery.Where(x => x.Interactions.All(i => !parameter.CannotHaveInteractions.Contains(i.Type)));
|
||||||
|
|
||||||
if (!parameter.IncludeDeleted)
|
if (!parameter.IncludeDeleted)
|
||||||
prospectsQuery = prospectsQuery.Where(x => x.RecordState != RecordState.Archived);
|
prospectsQuery = prospectsQuery.Where(x => x.RecordState != RecordState.Archived);
|
||||||
|
|
||||||
|
if (parameter.Skip > 0)
|
||||||
|
prospectsQuery = prospectsQuery.Skip(parameter.Skip);
|
||||||
|
|
||||||
|
if (parameter.Take > 0)
|
||||||
|
prospectsQuery = prospectsQuery.Take(parameter.Take);
|
||||||
|
|
||||||
var prospects = await prospectsQuery.ToListAsync();
|
var prospects = await prospectsQuery.ToListAsync();
|
||||||
|
|
||||||
return new(prospects);
|
return new(prospects);
|
||||||
@@ -174,6 +180,53 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Public Method UpdateInteraction
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates an existing interaction with the specified values.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="interaction">The interaction with updated values.</param>
|
||||||
|
/// <returns>A task containing an operation result of interaction.</returns>
|
||||||
|
public async Task<OperationResult<Interaction>> UpdateInteraction(Interaction interaction)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entityInteraction = await Context.Interactions!.FirstOrDefaultAsync(x => x.Id == interaction.Id);
|
||||||
|
if (entityInteraction == null) return new(new Exception("Interaction not found"));
|
||||||
|
|
||||||
|
entityInteraction.Date = interaction.Date;
|
||||||
|
entityInteraction.Info1 = interaction.Info1;
|
||||||
|
entityInteraction.Info2 = interaction.Info2;
|
||||||
|
entityInteraction.Feedback = interaction.Feedback;
|
||||||
|
entityInteraction.FeedbackInfo = interaction.FeedbackInfo;
|
||||||
|
entityInteraction.Alert = interaction.Alert;
|
||||||
|
|
||||||
|
var prospect = await Context.Prospects!.FirstOrDefaultAsync(x => x.Id == entityInteraction.ProspectID);
|
||||||
|
if (prospect != null)
|
||||||
|
{
|
||||||
|
prospect.Modified = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Context.SaveChangesAsync();
|
||||||
|
|
||||||
|
if (prospect != null)
|
||||||
|
{
|
||||||
|
await AuditService.Insert(AuditType.EditInteraction, prospect.Name, entityInteraction.Type.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Context.Entry(entityInteraction).State = EntityState.Detached;
|
||||||
|
if (prospect != null) Context.Entry(prospect).State = EntityState.Detached;
|
||||||
|
|
||||||
|
return new(entityInteraction);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Public Method UpdateAsync
|
#region Public Method UpdateAsync
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -290,6 +343,8 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
await Context.ProspectImages!.AddAsync(image);
|
await Context.ProspectImages!.AddAsync(image);
|
||||||
await Context.SaveChangesAsync();
|
await Context.SaveChangesAsync();
|
||||||
|
|
||||||
|
await AuditService.Insert(AuditType.UploadProspectImage, prospect.Name);
|
||||||
|
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -308,6 +363,16 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
.OrderBy(x => x.Created)
|
.OrderBy(x => x.Created)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
var prospectName = await Context.Prospects!
|
||||||
|
.Where(x => x.Id == prospectId)
|
||||||
|
.Select(x => x.Name)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(prospectName))
|
||||||
|
{
|
||||||
|
await AuditService.Insert(AuditType.ViewProspectImages, prospectName);
|
||||||
|
}
|
||||||
|
|
||||||
return new(images);
|
return new(images);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -329,6 +394,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
if (prospect != null)
|
if (prospect != null)
|
||||||
{
|
{
|
||||||
prospect.VerificationToken = null; // Clear token when images are deleted
|
prospect.VerificationToken = null; // Clear token when images are deleted
|
||||||
|
await AuditService.Insert(AuditType.DeleteProspectImages, prospect.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Context.SaveChangesAsync();
|
await Context.SaveChangesAsync();
|
||||||
|
|||||||
@@ -105,6 +105,13 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
var user = await Context.Users!.Include(x => x.Interactions).FirstOrDefaultAsync(x => x.Id == userId);
|
var user = await Context.Users!.Include(x => x.Interactions).FirstOrDefaultAsync(x => x.Id == userId);
|
||||||
if (user == null) return new(new Exception("User not found"));
|
if (user == null) return new(new Exception("User not found"));
|
||||||
|
|
||||||
|
if (user.Type == UserType.Admin)
|
||||||
|
{
|
||||||
|
var adminCount = await Context.Users!.CountAsync(x => x.Type == UserType.Admin && x.Id != userId);
|
||||||
|
if (adminCount == 0)
|
||||||
|
return new(new Exception("Der letzte Administrator kann nicht gelöscht werden."));
|
||||||
|
}
|
||||||
|
|
||||||
// Interaktionen vom aktuellen Nutzer übernehmen
|
// Interaktionen vom aktuellen Nutzer übernehmen
|
||||||
if(CurrentUser?.Id != null)
|
if(CurrentUser?.Id != null)
|
||||||
foreach (var userInteraction in user.Interactions)
|
foreach (var userInteraction in user.Interactions)
|
||||||
@@ -151,8 +158,14 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
|
|
||||||
if (saveR < 1) return new(new Exception("Fehler beim Speichern"));
|
if (saveR < 1) return new(new Exception("Fehler beim Speichern"));
|
||||||
|
|
||||||
var auditData = CurrentUser?.Id == user.Id ? "sich selbst" : user.Mail;
|
if (CurrentUser?.Id == user.Id)
|
||||||
await AuditService.Insert(AuditType.SetUserPassword, auditData);
|
{
|
||||||
|
await AuditService.Insert(AuditType.ChangeOwnPassword);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await AuditService.Insert(AuditType.SetUserPassword, user.Mail);
|
||||||
|
}
|
||||||
|
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
@@ -178,6 +191,13 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
var entityUser = await Context.Users!.FirstOrDefaultAsync(x => x.Id == user.Id);
|
var entityUser = await Context.Users!.FirstOrDefaultAsync(x => x.Id == user.Id);
|
||||||
if (entityUser == null) return new(new Exception("User not found"));
|
if (entityUser == null) return new(new Exception("User not found"));
|
||||||
|
|
||||||
|
if (entityUser.Type == UserType.Admin && user.Type != UserType.Admin)
|
||||||
|
{
|
||||||
|
var adminCount = await Context.Users!.CountAsync(x => x.Type == UserType.Admin && x.Id != user.Id);
|
||||||
|
if (adminCount == 0)
|
||||||
|
return new(new Exception("Der Typ des letzten Administrators kann nicht geändert werden."));
|
||||||
|
}
|
||||||
|
|
||||||
if (entityUser.Mail != user.Mail ||
|
if (entityUser.Mail != user.Mail ||
|
||||||
entityUser.Type != user.Type ||
|
entityUser.Type != user.Type ||
|
||||||
entityUser.Groups != user.Groups)
|
entityUser.Groups != user.Groups)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel>Foodsharing-ID</FieldLabel>
|
<FieldLabel>Foodsharing-ID</FieldLabel>
|
||||||
<NumericEdit TValue="int" @bind-Value="Prospect.FsId"></NumericEdit>
|
<NumericEdit TValue="int?" Value="@(Prospect.FsId == 0 ? (int?)null : Prospect.FsId)" ValueChanged="@((int? v) => Prospect.FsId = v ?? 0)"></NumericEdit>
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -82,23 +82,52 @@ namespace FoodsharingSiegen.Server.Dialogs
|
|||||||
|
|
||||||
#region Private Method SaveClick
|
#region Private Method SaveClick
|
||||||
|
|
||||||
|
private bool _isSaving;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the click (a. beging, 31.05.2022)
|
/// Saves the click (a. beging, 31.05.2022)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task SaveClick()
|
private async Task SaveClick()
|
||||||
{
|
{
|
||||||
if (IsUpdateMode)
|
if (_isSaving) return;
|
||||||
|
_isSaving = true;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var updateR = await ProspectService.UpdateAsync(Prospect);
|
if (IsUpdateMode)
|
||||||
if (updateR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
{
|
||||||
|
var updateR = await ProspectService.UpdateAsync(Prospect);
|
||||||
|
if (updateR.Success)
|
||||||
|
{
|
||||||
|
if (OnSuccess != null) await OnSuccess.Invoke();
|
||||||
|
await ModalService.Hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Notification.Error(updateR.Exception?.Message ?? "Unbekannter Fehler beim Speichern.", "Fehler");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var addR = await ProspectService.AddProspectAsync(Prospect);
|
||||||
|
if (addR.Success)
|
||||||
|
{
|
||||||
|
if (OnSuccess != null) await OnSuccess.Invoke();
|
||||||
|
await ModalService.Hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Notification.Error(addR.Exception?.Message ?? "Unbekannter Fehler beim Hinzufügen.", "Fehler");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var addR = await ProspectService.AddProspectAsync(Prospect);
|
await Notification.Error(ex.Message, "Systemfehler");
|
||||||
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isSaving = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ModalService.Hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -76,5 +76,5 @@
|
|||||||
|
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
<Button Color="Color.Secondary" Clicked="@ModalService.Hide">Abbrechen</Button>
|
<Button Color="Color.Secondary" Clicked="@ModalService.Hide">Abbrechen</Button>
|
||||||
<Button Color="Color.Primary" Clicked="@AddInteractionAsync" Class="ml-2">OK</Button>
|
<Button Color="Color.Primary" Clicked="@SaveAsync" Class="ml-2">@(IsEditMode ? "Speichern" : "OK")</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Blazorise;
|
using Blazorise;
|
||||||
|
using FoodsharingSiegen.Contracts;
|
||||||
using FoodsharingSiegen.Contracts.Entity;
|
using FoodsharingSiegen.Contracts.Entity;
|
||||||
using FoodsharingSiegen.Contracts.Enums;
|
using FoodsharingSiegen.Contracts.Enums;
|
||||||
using FoodsharingSiegen.Server.BaseClasses;
|
using FoodsharingSiegen.Server.BaseClasses;
|
||||||
@@ -7,7 +8,7 @@ using Microsoft.AspNetCore.Components;
|
|||||||
|
|
||||||
namespace FoodsharingSiegen.Server.Dialogs
|
namespace FoodsharingSiegen.Server.Dialogs
|
||||||
{
|
{
|
||||||
public record InteractionDialogParameter(InteractionType Type, Guid ProspectId, string HeaderText, Func<Task> OnSuccess);
|
public record InteractionDialogParameter(InteractionType Type, Guid ProspectId, string HeaderText, Func<Task> OnSuccess, Interaction? ExistingInteraction = null);
|
||||||
|
|
||||||
public partial class InteractionDialog : FsBase
|
public partial class InteractionDialog : FsBase
|
||||||
{
|
{
|
||||||
@@ -44,6 +45,19 @@ namespace FoodsharingSiegen.Server.Dialogs
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public bool ShowNotNeeded { get; set; }
|
public bool ShowNotNeeded { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool IsEditMode { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Method IsEditable
|
||||||
|
|
||||||
|
public static bool IsEditable(InteractionType type) => type switch
|
||||||
|
{
|
||||||
|
InteractionType.EinAb => true,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Method ShowAsync
|
#region Public Method ShowAsync
|
||||||
@@ -93,12 +107,29 @@ namespace FoodsharingSiegen.Server.Dialogs
|
|||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
|
|
||||||
var interaction = new Interaction
|
var isEditMode = parameter.ExistingInteraction != null;
|
||||||
{
|
var interaction = isEditMode
|
||||||
Type = parameter.Type,
|
? new Interaction
|
||||||
Date = DateTime.UtcNow,
|
{
|
||||||
ProspectID = parameter.ProspectId
|
Id = parameter.ExistingInteraction!.Id,
|
||||||
};
|
Type = parameter.ExistingInteraction.Type,
|
||||||
|
Date = parameter.ExistingInteraction.Date,
|
||||||
|
ProspectID = parameter.ExistingInteraction.ProspectID,
|
||||||
|
UserID = parameter.ExistingInteraction.UserID,
|
||||||
|
Info1 = parameter.ExistingInteraction.Info1,
|
||||||
|
Info2 = parameter.ExistingInteraction.Info2,
|
||||||
|
Feedback = parameter.ExistingInteraction.Feedback,
|
||||||
|
FeedbackInfo = parameter.ExistingInteraction.FeedbackInfo,
|
||||||
|
Alert = parameter.ExistingInteraction.Alert,
|
||||||
|
NotNeeded = parameter.ExistingInteraction.NotNeeded,
|
||||||
|
Created = parameter.ExistingInteraction.Created
|
||||||
|
}
|
||||||
|
: new Interaction
|
||||||
|
{
|
||||||
|
Type = parameter.Type,
|
||||||
|
Date = DateTime.UtcNow,
|
||||||
|
ProspectID = parameter.ProspectId
|
||||||
|
};
|
||||||
|
|
||||||
await modalService.Show<InteractionDialog>(parameter.HeaderText, p =>
|
await modalService.Show<InteractionDialog>(parameter.HeaderText, p =>
|
||||||
{
|
{
|
||||||
@@ -108,28 +139,41 @@ namespace FoodsharingSiegen.Server.Dialogs
|
|||||||
p.Add(nameof(Info2Name), info2Name);
|
p.Add(nameof(Info2Name), info2Name);
|
||||||
p.Add(nameof(ShowAlert), showAlert);
|
p.Add(nameof(ShowAlert), showAlert);
|
||||||
p.Add(nameof(ShowNotNeeded), showNotNeeded);
|
p.Add(nameof(ShowNotNeeded), showNotNeeded);
|
||||||
|
p.Add(nameof(IsEditMode), isEditMode);
|
||||||
p.Add(nameof(OnSuccess), parameter.OnSuccess);
|
p.Add(nameof(OnSuccess), parameter.OnSuccess);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Method AddInteractionAsync
|
#region Private Method SaveAsync
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new interaction for the current user using the ProspectService and hides the modal.
|
/// Saves the interaction (add or update) and hides the modal on success.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
private async Task SaveAsync()
|
||||||
/// A task representing the asynchronous operation.
|
|
||||||
/// </returns>
|
|
||||||
private async Task AddInteractionAsync()
|
|
||||||
{
|
{
|
||||||
Interaction.UserID = CurrentUser.Id;
|
OperationResult<Interaction> result;
|
||||||
|
|
||||||
var addR = await ProspectService.AddInteraction(Interaction);
|
if (IsEditMode)
|
||||||
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
{
|
||||||
|
result = await ProspectService.UpdateInteraction(Interaction);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Interaction.UserID = CurrentUser.Id;
|
||||||
|
result = await ProspectService.AddInteraction(Interaction);
|
||||||
|
}
|
||||||
|
|
||||||
await ModalService.Hide();
|
if (result.Success)
|
||||||
|
{
|
||||||
|
await ModalService.Hide();
|
||||||
|
if (OnSuccess != null) await OnSuccess.Invoke();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Notification.Error(result.Exception?.Message ?? "Unbekannter Fehler beim Speichern.", "Fehler");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ namespace FoodsharingSiegen.Server
|
|||||||
// Check if the directory exists
|
// Check if the directory exists
|
||||||
if (Directory.Exists(configDir))
|
if (Directory.Exists(configDir))
|
||||||
{
|
{
|
||||||
// Get all JSON files that start with "appsettings" in the directory and its subdirectories
|
// In local development, skip the template-only example config so a debug override
|
||||||
var configFiles = Directory.EnumerateFiles(configDir, "appsettings*.json", SearchOption.AllDirectories);
|
// such as ASPNETCORE_URLS can take effect without changing the container image setup.
|
||||||
|
var configFiles = Directory.EnumerateFiles(configDir, "appsettings*.json", SearchOption.AllDirectories)
|
||||||
|
.Where(file => !builder.Environment.IsDevelopment() || !Path.GetFileName(file).Equals("appsettings.example.json", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
// Add each file to the configuration
|
// Add each file to the configuration
|
||||||
foreach (var file in configFiles) builder.Configuration.AddJsonFile(file, true, true);
|
foreach (var file in configFiles) builder.Configuration.AddJsonFile(file, true, true);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
<DataGrid TItem="Audit"
|
<DataGrid TItem="Audit"
|
||||||
Data="@Audits"
|
Data="@Audits"
|
||||||
|
ReadData="@OnReadData"
|
||||||
|
TotalItems="@TotalAudits"
|
||||||
VirtualizeOptions="@(new() { DataGridHeight = "100%", DataGridMaxHeight = "100%"})"
|
VirtualizeOptions="@(new() { DataGridHeight = "100%", DataGridMaxHeight = "100%"})"
|
||||||
Virtualize="true"
|
Virtualize="true"
|
||||||
Responsive>
|
Responsive>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using Blazorise.DataGrid;
|
||||||
using FoodsharingSiegen.Contracts.Entity;
|
using FoodsharingSiegen.Contracts.Entity;
|
||||||
|
using FoodsharingSiegen.Contracts.Helper;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
@@ -26,16 +28,47 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Audit>? Audits { get; set; }
|
private List<Audit>? Audits { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the total audits (ab)
|
||||||
|
/// </summary>
|
||||||
|
private int TotalAudits { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Override InitializeDataAsync
|
#region Override InitializeDataAsync
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task InitializeDataAsync()
|
protected override Task InitializeDataAsync()
|
||||||
{
|
{
|
||||||
var loadR = await AuditService?.Load(100)!;
|
if (!CurrentUser.IsAdmin()) NavigationManager.NavigateTo("/");
|
||||||
if (loadR.Success)
|
return Task.CompletedTask;
|
||||||
Audits = loadR.Data;
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Method OnReadData
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when data is read (ab)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">The params</param>
|
||||||
|
private async Task OnReadData(DataGridReadDataEventArgs<Audit> e)
|
||||||
|
{
|
||||||
|
if (!CurrentUser.IsAdmin()) return;
|
||||||
|
|
||||||
|
var countLoad = await AuditService?.GetCount()!;
|
||||||
|
if (countLoad.Success)
|
||||||
|
TotalAudits = countLoad.Data;
|
||||||
|
|
||||||
|
// Default fallback if VirtualizeCount is not set, though Blazor shouldn't do this usually
|
||||||
|
var limit = e.VirtualizeCount > 0 ? e.VirtualizeCount : 50;
|
||||||
|
var offset = e.VirtualizeOffset;
|
||||||
|
|
||||||
|
var itemsLoad = await AuditService?.LoadPage(offset, limit)!;
|
||||||
|
if (itemsLoad.Success)
|
||||||
|
Audits = itemsLoad.Data;
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sourceRoot":"","sources":["AuditView.razor.scss"],"names":[],"mappings":"AAAA;EACE","file":"AuditView.razor.css"}
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
{
|
{
|
||||||
<div class="alert alert-success text-center">
|
<div class="alert alert-success text-center">
|
||||||
Wenn ein Benutzerkonto mit dieser E-Mail-Adresse existiert, wurde eine E-Mail mit weiteren Anweisungen versendet.
|
Wenn ein Benutzerkonto mit dieser E-Mail-Adresse existiert, wurde eine E-Mail mit weiteren Anweisungen versendet.
|
||||||
|
<br><br>
|
||||||
|
<small><b>Hinweis:</b> Bitte überprüfe auch deinen Spam-Ordner, falls du künftige E-Mails nicht im regulären Posteingang findest.</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center mt-4">
|
<div class="text-center mt-4">
|
||||||
<a href="/login" class="btn btn-outline-primary"><i class="fas fa-arrow-left mr-2"></i> Zurück zum Login</a>
|
<a href="/login" class="btn btn-outline-primary"><i class="fas fa-arrow-left mr-2"></i> Zurück zum Login</a>
|
||||||
|
|||||||
@@ -29,13 +29,25 @@
|
|||||||
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspects" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.OnBoarding" />
|
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspects" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.OnBoarding" />
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var filterList = ProspectList.ApplyFilter(Filter);
|
var filtered = ProspectList.ApplyFilter(Filter);
|
||||||
var sortList = filterList.ApplySort(CurrentSort);
|
var sortList = filtered.ApplySort(CurrentSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (IsLoadingProspects)
|
||||||
<ProspectGrid
|
{
|
||||||
Prospects="sortList"
|
<div class="d-flex justify-content-center align-items-center py-5 text-muted">
|
||||||
OnDataChanged="@LoadProspects"
|
<span class="me-2"><i class="fa-solid fa-spinner fa-spin"></i></span>
|
||||||
StateFilter="ProspectStateFilter.OnBoarding">
|
Lade Einarbeitungen...
|
||||||
</ProspectGrid>
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<ProspectGrid
|
||||||
|
Prospects="sortList"
|
||||||
|
OnDataChanged="@LoadProspects"
|
||||||
|
OnLoadMore="@LoadMoreProspects"
|
||||||
|
IsLoadingMore="IsLoadingMoreProspects"
|
||||||
|
HasMore="HasMoreProspects"
|
||||||
|
StateFilter="ProspectStateFilter.OnBoarding">
|
||||||
|
</ProspectGrid>
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using FoodsharingSiegen.Contracts.Entity;
|
|||||||
using FoodsharingSiegen.Contracts.Enums;
|
using FoodsharingSiegen.Contracts.Enums;
|
||||||
using FoodsharingSiegen.Contracts.Model;
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
|
using FoodsharingSiegen.Shared.Helper;
|
||||||
using FoodsharingSiegen.Server.Dialogs;
|
using FoodsharingSiegen.Server.Dialogs;
|
||||||
using FoodsharingSiegen.Server.Service;
|
using FoodsharingSiegen.Server.Service;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
@@ -34,7 +35,17 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value of the prospect list (ab)
|
/// Gets or sets the value of the prospect list (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Prospect>? ProspectList { get; set; }
|
private List<Prospect> ProspectList { get; set; } = [];
|
||||||
|
|
||||||
|
private bool IsLoadingProspects { get; set; }
|
||||||
|
|
||||||
|
private bool IsLoadingMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private bool HasMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private int CurrentPageSize { get; set; } = 50;
|
||||||
|
|
||||||
|
private int CurrentSkip { get; set; }
|
||||||
|
|
||||||
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
||||||
|
|
||||||
@@ -56,13 +67,24 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
|
|
||||||
#region Private Method CreateProspectAsync
|
#region Private Method CreateProspectAsync
|
||||||
|
|
||||||
|
private bool _isOpeningModal;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asynchronously creates a new prospect by displaying the AddProspectModal dialog and refreshing the prospect list.
|
/// Asynchronously creates a new prospect by displaying the AddProspectModal dialog and refreshing the prospect list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||||
private async Task CreateProspectAsync()
|
private async Task CreateProspectAsync()
|
||||||
{
|
{
|
||||||
await EditProspectDialog.ShowAsync(ModalService, LoadProspects);
|
if (_isOpeningModal) return;
|
||||||
|
_isOpeningModal = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await EditProspectDialog.ShowAsync(ModalService, LoadProspects);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isOpeningModal = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -78,6 +100,9 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
{
|
{
|
||||||
Filter = arg;
|
Filter = arg;
|
||||||
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
||||||
|
CurrentSkip = 0;
|
||||||
|
ProspectList = [];
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -87,17 +112,87 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the prospects (a. beging, 11.04.2022)
|
/// Loads the prospects (a. beging, 11.04.2022)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
private bool HasActiveFilter()
|
||||||
|
{
|
||||||
|
return !string.IsNullOrWhiteSpace(Filter.Text)
|
||||||
|
|| Filter.WithoutStepInBriefing
|
||||||
|
|| Filter.WithoutIdCheck
|
||||||
|
|| Filter.DeletedOnly
|
||||||
|
|| Filter.IdCheckPossible
|
||||||
|
|| Filter.NoActivity
|
||||||
|
|| Filter.RecentActivity;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task LoadProspects()
|
private async Task LoadProspects()
|
||||||
{
|
{
|
||||||
var parameter = new GetProspectsParameter
|
if (IsLoadingProspects || IsLoadingMoreProspects) return;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
CannotHaveInteractions = [InteractionType.Complete, InteractionType.Verify, InteractionType.ReleasedForVerification]
|
if (CurrentSkip == 0)
|
||||||
};
|
{
|
||||||
|
IsLoadingProspects = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsLoadingMoreProspects = true;
|
||||||
|
}
|
||||||
|
|
||||||
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
await InvokeAsync(StateHasChanged);
|
||||||
if (prospectsR.Success) ProspectList = prospectsR.Data;
|
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
while (true)
|
||||||
|
{
|
||||||
|
var parameter = new GetProspectsParameter
|
||||||
|
{
|
||||||
|
Skip = CurrentSkip,
|
||||||
|
Take = CurrentPageSize,
|
||||||
|
CannotHaveInteractions = [InteractionType.Complete, InteractionType.Verify, InteractionType.ReleasedForVerification]
|
||||||
|
};
|
||||||
|
|
||||||
|
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
||||||
|
if (!prospectsR.Success)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadedProspects = prospectsR.Data ?? [];
|
||||||
|
if (CurrentSkip == 0)
|
||||||
|
{
|
||||||
|
ProspectList = loadedProspects;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProspectList = [.. ProspectList, .. loadedProspects];
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentSkip += loadedProspects.Count;
|
||||||
|
HasMoreProspects = loadedProspects.Count == CurrentPageSize;
|
||||||
|
|
||||||
|
var filteredCount = ProspectList.ApplyFilter(Filter).Count;
|
||||||
|
if (!HasActiveFilter() || filteredCount > 0 || !HasMoreProspects || loadedProspects.Count == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await Notification.Error(ex.Message, "Fehler beim Laden");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoadingProspects = false;
|
||||||
|
IsLoadingMoreProspects = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadMoreProspects()
|
||||||
|
{
|
||||||
|
if (IsLoadingProspects || IsLoadingMoreProspects || !HasMoreProspects) return;
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -17,12 +17,25 @@
|
|||||||
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspectsAll" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.All" />
|
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspectsAll" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.All" />
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var filterList = ProspectList.ApplyFilter(Filter);
|
var filtered = ProspectList.ApplyFilter(Filter);
|
||||||
var sortList = filterList.ApplySort(CurrentSort);
|
var sortList = filtered.ApplySort(CurrentSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
<ProspectGrid
|
@if (IsLoadingProspects)
|
||||||
Prospects="sortList"
|
{
|
||||||
OnDataChanged="@LoadProspects"
|
<div class="d-flex justify-content-center align-items-center py-5 text-muted">
|
||||||
StateFilter="ProspectStateFilter.All">
|
<span class="me-2"><i class="fa-solid fa-spinner fa-spin"></i></span>
|
||||||
</ProspectGrid>
|
Lade Einarbeitungen...
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<ProspectGrid
|
||||||
|
Prospects="sortList"
|
||||||
|
OnDataChanged="@LoadProspects"
|
||||||
|
OnLoadMore="@LoadMoreProspects"
|
||||||
|
IsLoadingMore="IsLoadingMoreProspects"
|
||||||
|
HasMore="HasMoreProspects"
|
||||||
|
StateFilter="ProspectStateFilter.All">
|
||||||
|
</ProspectGrid>
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using FoodsharingSiegen.Contracts.Helper;
|
|||||||
using FoodsharingSiegen.Contracts.Model;
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
using FoodsharingSiegen.Server.Dialogs;
|
using FoodsharingSiegen.Server.Dialogs;
|
||||||
|
using FoodsharingSiegen.Shared.Helper;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace FoodsharingSiegen.Server.Pages
|
namespace FoodsharingSiegen.Server.Pages
|
||||||
@@ -37,7 +38,17 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value of the prospect list (ab)
|
/// Gets or sets the value of the prospect list (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Prospect>? ProspectList { get; set; }
|
private List<Prospect> ProspectList { get; set; } = [];
|
||||||
|
|
||||||
|
private bool IsLoadingProspects { get; set; }
|
||||||
|
|
||||||
|
private bool IsLoadingMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private bool HasMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private int CurrentPageSize { get; set; } = 50;
|
||||||
|
|
||||||
|
private int CurrentSkip { get; set; }
|
||||||
|
|
||||||
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
||||||
|
|
||||||
@@ -71,6 +82,9 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
{
|
{
|
||||||
Filter = arg;
|
Filter = arg;
|
||||||
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
||||||
|
CurrentSkip = 0;
|
||||||
|
ProspectList = [];
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -80,17 +94,83 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the prospects (a. beging, 11.04.2022)
|
/// Loads the prospects (a. beging, 11.04.2022)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
private bool HasActiveFilter()
|
||||||
|
{
|
||||||
|
return !string.IsNullOrWhiteSpace(Filter.Text)
|
||||||
|
|| Filter.WithoutStepInBriefing
|
||||||
|
|| Filter.WithoutIdCheck
|
||||||
|
|| Filter.DeletedOnly
|
||||||
|
|| Filter.IdCheckPossible
|
||||||
|
|| Filter.NoActivity
|
||||||
|
|| Filter.RecentActivity;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task LoadProspects()
|
private async Task LoadProspects()
|
||||||
{
|
{
|
||||||
var parameter = new GetProspectsParameter
|
if (IsLoadingProspects || IsLoadingMoreProspects) return;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
IncludeDeleted = true
|
if (CurrentSkip == 0)
|
||||||
};
|
{
|
||||||
|
IsLoadingProspects = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsLoadingMoreProspects = true;
|
||||||
|
}
|
||||||
|
|
||||||
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
await InvokeAsync(StateHasChanged);
|
||||||
if (prospectsR.Success) ProspectList = prospectsR.Data;
|
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
while (true)
|
||||||
|
{
|
||||||
|
var parameter = new GetProspectsParameter
|
||||||
|
{
|
||||||
|
Skip = CurrentSkip,
|
||||||
|
Take = CurrentPageSize,
|
||||||
|
IncludeDeleted = true
|
||||||
|
};
|
||||||
|
|
||||||
|
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
||||||
|
if (!prospectsR.Success)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadedProspects = prospectsR.Data ?? [];
|
||||||
|
if (CurrentSkip == 0)
|
||||||
|
{
|
||||||
|
ProspectList = loadedProspects;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProspectList = [.. ProspectList, .. loadedProspects];
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentSkip += loadedProspects.Count;
|
||||||
|
HasMoreProspects = loadedProspects.Count == CurrentPageSize;
|
||||||
|
|
||||||
|
var filteredCount = ProspectList.ApplyFilter(Filter).Count;
|
||||||
|
if (!HasActiveFilter() || filteredCount > 0 || !HasMoreProspects || loadedProspects.Count == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoadingProspects = false;
|
||||||
|
IsLoadingMoreProspects = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadMoreProspects()
|
||||||
|
{
|
||||||
|
if (IsLoadingProspects || IsLoadingMoreProspects || !HasMoreProspects) return;
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -16,12 +16,25 @@
|
|||||||
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspectsDone" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.Completed" />
|
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspectsDone" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.Completed" />
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var filterList = ProspectList.ApplyFilter(Filter);
|
var filtered = ProspectList.ApplyFilter(Filter);
|
||||||
var sortList = filterList.ApplySort(CurrentSort);
|
var sortList = filtered.ApplySort(CurrentSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
<ProspectGrid
|
@if (IsLoadingProspects)
|
||||||
Prospects="sortList"
|
{
|
||||||
OnDataChanged="@LoadProspects"
|
<div class="d-flex justify-content-center align-items-center py-5 text-muted">
|
||||||
StateFilter="ProspectStateFilter.Completed">
|
<span class="me-2"><i class="fa-solid fa-spinner fa-spin"></i></span>
|
||||||
</ProspectGrid>
|
Lade Einarbeitungen...
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<ProspectGrid
|
||||||
|
Prospects="sortList"
|
||||||
|
OnDataChanged="@LoadProspects"
|
||||||
|
OnLoadMore="@LoadMoreProspects"
|
||||||
|
IsLoadingMore="IsLoadingMoreProspects"
|
||||||
|
HasMore="HasMoreProspects"
|
||||||
|
StateFilter="ProspectStateFilter.Completed">
|
||||||
|
</ProspectGrid>
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using FoodsharingSiegen.Contracts.Entity;
|
|||||||
using FoodsharingSiegen.Contracts.Enums;
|
using FoodsharingSiegen.Contracts.Enums;
|
||||||
using FoodsharingSiegen.Contracts.Model;
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
|
using FoodsharingSiegen.Shared.Helper;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace FoodsharingSiegen.Server.Pages
|
namespace FoodsharingSiegen.Server.Pages
|
||||||
@@ -29,7 +30,17 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value of the prospect list (ab)
|
/// Gets or sets the value of the prospect list (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Prospect>? ProspectList { get; set; }
|
private List<Prospect> ProspectList { get; set; } = [];
|
||||||
|
|
||||||
|
private bool IsLoadingProspects { get; set; }
|
||||||
|
|
||||||
|
private bool IsLoadingMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private bool HasMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private int CurrentPageSize { get; set; } = 50;
|
||||||
|
|
||||||
|
private int CurrentSkip { get; set; }
|
||||||
|
|
||||||
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
||||||
|
|
||||||
@@ -60,6 +71,9 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
{
|
{
|
||||||
Filter = arg;
|
Filter = arg;
|
||||||
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
||||||
|
CurrentSkip = 0;
|
||||||
|
ProspectList = [];
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -69,13 +83,82 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the prospects (a. beging, 11.04.2022)
|
/// Loads the prospects (a. beging, 11.04.2022)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
private bool HasActiveFilter()
|
||||||
|
{
|
||||||
|
return !string.IsNullOrWhiteSpace(Filter.Text)
|
||||||
|
|| Filter.WithoutStepInBriefing
|
||||||
|
|| Filter.WithoutIdCheck
|
||||||
|
|| Filter.DeletedOnly
|
||||||
|
|| Filter.IdCheckPossible
|
||||||
|
|| Filter.NoActivity
|
||||||
|
|| Filter.RecentActivity;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task LoadProspects()
|
private async Task LoadProspects()
|
||||||
{
|
{
|
||||||
var parameter = new GetProspectsParameter { MustHaveInteractions = [InteractionType.Complete] };
|
if (IsLoadingProspects || IsLoadingMoreProspects) return;
|
||||||
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
|
||||||
if (prospectsR.Success) ProspectList = prospectsR.Data;
|
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
try
|
||||||
|
{
|
||||||
|
if (CurrentSkip == 0)
|
||||||
|
{
|
||||||
|
IsLoadingProspects = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsLoadingMoreProspects = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var parameter = new GetProspectsParameter
|
||||||
|
{
|
||||||
|
Skip = CurrentSkip,
|
||||||
|
Take = CurrentPageSize,
|
||||||
|
MustHaveInteractions = [InteractionType.Complete]
|
||||||
|
};
|
||||||
|
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
||||||
|
if (!prospectsR.Success)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadedProspects = prospectsR.Data ?? [];
|
||||||
|
if (CurrentSkip == 0)
|
||||||
|
{
|
||||||
|
ProspectList = loadedProspects;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProspectList = [.. ProspectList, .. loadedProspects];
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentSkip += loadedProspects.Count;
|
||||||
|
HasMoreProspects = loadedProspects.Count == CurrentPageSize;
|
||||||
|
|
||||||
|
var filteredCount = ProspectList.ApplyFilter(Filter).Count;
|
||||||
|
if (!HasActiveFilter() || filteredCount > 0 || !HasMoreProspects || loadedProspects.Count == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoadingProspects = false;
|
||||||
|
IsLoadingMoreProspects = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadMoreProspects()
|
||||||
|
{
|
||||||
|
if (IsLoadingProspects || IsLoadingMoreProspects || !HasMoreProspects) return;
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -16,13 +16,25 @@
|
|||||||
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspectsVerify" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.Verification" />
|
<ProspectSortControl @bind-CurrentSort="CurrentSort" StorageKey="@StorageKeys.SortProspectsVerify" OnSortChanged="StateHasChanged" Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.Verification" />
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var filterList = ProspectList.ApplyFilter(Filter);
|
var filtered = ProspectList.ApplyFilter(Filter);
|
||||||
var sortList = filterList.ApplySort(CurrentSort);
|
var sortList = filtered.ApplySort(CurrentSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (IsLoadingProspects)
|
||||||
<ProspectGrid
|
{
|
||||||
Prospects="sortList"
|
<div class="d-flex justify-content-center align-items-center py-5 text-muted">
|
||||||
OnDataChanged="@LoadProspects"
|
<span class="me-2"><i class="fa-solid fa-spinner fa-spin"></i></span>
|
||||||
StateFilter="ProspectStateFilter.Verification">
|
Lade Einarbeitungen...
|
||||||
</ProspectGrid>
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<ProspectGrid
|
||||||
|
Prospects="sortList"
|
||||||
|
OnDataChanged="@LoadProspects"
|
||||||
|
OnLoadMore="@LoadMoreProspects"
|
||||||
|
IsLoadingMore="IsLoadingMoreProspects"
|
||||||
|
HasMore="HasMoreProspects"
|
||||||
|
StateFilter="ProspectStateFilter.Verification">
|
||||||
|
</ProspectGrid>
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using FoodsharingSiegen.Contracts.Entity;
|
|||||||
using FoodsharingSiegen.Contracts.Enums;
|
using FoodsharingSiegen.Contracts.Enums;
|
||||||
using FoodsharingSiegen.Contracts.Model;
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
|
using FoodsharingSiegen.Shared.Helper;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace FoodsharingSiegen.Server.Pages
|
namespace FoodsharingSiegen.Server.Pages
|
||||||
@@ -35,7 +36,17 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value of the prospect list (ab)
|
/// Gets or sets the value of the prospect list (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Prospect>? ProspectList { get; set; }
|
private List<Prospect> ProspectList { get; set; } = [];
|
||||||
|
|
||||||
|
private bool IsLoadingProspects { get; set; }
|
||||||
|
|
||||||
|
private bool IsLoadingMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private bool HasMoreProspects { get; set; }
|
||||||
|
|
||||||
|
private int CurrentPageSize { get; set; } = 50;
|
||||||
|
|
||||||
|
private int CurrentSkip { get; set; }
|
||||||
|
|
||||||
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
||||||
|
|
||||||
@@ -67,6 +78,9 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
{
|
{
|
||||||
Filter = arg;
|
Filter = arg;
|
||||||
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
||||||
|
CurrentSkip = 0;
|
||||||
|
ProspectList = [];
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -76,17 +90,83 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the prospects (a. beging, 11.04.2022)
|
/// Loads the prospects (a. beging, 11.04.2022)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
private bool HasActiveFilter()
|
||||||
|
{
|
||||||
|
return !string.IsNullOrWhiteSpace(Filter.Text)
|
||||||
|
|| Filter.WithoutStepInBriefing
|
||||||
|
|| Filter.WithoutIdCheck
|
||||||
|
|| Filter.DeletedOnly
|
||||||
|
|| Filter.IdCheckPossible
|
||||||
|
|| Filter.NoActivity
|
||||||
|
|| Filter.RecentActivity;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task LoadProspects()
|
private async Task LoadProspects()
|
||||||
{
|
{
|
||||||
var parameter = new GetProspectsParameter
|
if (IsLoadingProspects || IsLoadingMoreProspects) return;
|
||||||
{
|
|
||||||
CannotHaveInteractions = [InteractionType.Complete],
|
|
||||||
MustHaveInteractions = [InteractionType.ReleasedForVerification]
|
|
||||||
};
|
|
||||||
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
|
||||||
if (prospectsR.Success) ProspectList = prospectsR.Data;
|
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
try
|
||||||
|
{
|
||||||
|
if (CurrentSkip == 0)
|
||||||
|
{
|
||||||
|
IsLoadingProspects = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsLoadingMoreProspects = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var parameter = new GetProspectsParameter
|
||||||
|
{
|
||||||
|
Skip = CurrentSkip,
|
||||||
|
Take = CurrentPageSize,
|
||||||
|
CannotHaveInteractions = [InteractionType.Complete],
|
||||||
|
MustHaveInteractions = [InteractionType.ReleasedForVerification]
|
||||||
|
};
|
||||||
|
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
||||||
|
if (!prospectsR.Success)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadedProspects = prospectsR.Data ?? [];
|
||||||
|
if (CurrentSkip == 0)
|
||||||
|
{
|
||||||
|
ProspectList = loadedProspects;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProspectList = [.. ProspectList, .. loadedProspects];
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentSkip += loadedProspects.Count;
|
||||||
|
HasMoreProspects = loadedProspects.Count == CurrentPageSize;
|
||||||
|
|
||||||
|
var filteredCount = ProspectList.ApplyFilter(Filter).Count;
|
||||||
|
if (!HasActiveFilter() || filteredCount > 0 || !HasMoreProspects || loadedProspects.Count == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoadingProspects = false;
|
||||||
|
IsLoadingMoreProspects = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadMoreProspects()
|
||||||
|
{
|
||||||
|
if (IsLoadingProspects || IsLoadingMoreProspects || !HasMoreProspects) return;
|
||||||
|
await LoadProspects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -55,13 +55,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
<CardFooter Class="d-flex justify-content-between">
|
<CardFooter Class="d-flex justify-content-between">
|
||||||
<div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<Button Color="Color.Primary" Size="Size.Small" Clicked="() => EditUser(user)"><Icon Name="IconName.Edit" /></Button>
|
<Button Color="Color.Primary" Size="Size.Small" Clicked="() => EditUser(user)"><Icon Name="IconName.Edit" /></Button>
|
||||||
<Button Color="Color.Info" Size="Size.Small" Clicked="() => SetPassword(user)"><i class="fa-solid fa-key"></i></Button>
|
<Button Color="Color.Info" Size="Size.Small" Clicked="() => SetPassword(user)"><i class="fa-solid fa-key"></i></Button>
|
||||||
<Button Color="Color.Secondary" Size="Size.Small" Clicked="() => SendPasswordSetupMail(user)"><Icon Name="IconName.Mail" /></Button>
|
<Button Color="Color.Secondary" Size="Size.Small" Clicked="() => SendPasswordSetupMail(user)"><Icon Name="IconName.Mail" /></Button>
|
||||||
<Button Color="Color.Danger" Size="Size.Small" Clicked="() => RemoveUserAsync(user)"><Icon Name="IconName.Delete" /></Button>
|
@if (!(user.Type == UserType.Admin && SortedUsers.Count(x => x.Type == UserType.Admin) <= 1))
|
||||||
|
{
|
||||||
|
<Button Color="Color.Danger" Size="Size.Small" Clicked="() => RemoveUserAsync(user)"><Icon Name="IconName.Delete" /></Button>
|
||||||
|
}
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
}
|
}
|
||||||
@@ -105,12 +105,16 @@
|
|||||||
</Field>
|
</Field>
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel>Typ</FieldLabel>
|
<FieldLabel>Typ</FieldLabel>
|
||||||
<Select TValue="UserType" SelectedValue="EditModel.Type" SelectedValueChanged="@(v => EditModel.Type = v)">
|
<Select TValue="UserType" SelectedValue="EditModel.Type" SelectedValueChanged="@(v => EditModel.Type = v)" Disabled="@IsLastAdmin">
|
||||||
@foreach (var enumValue in Enum.GetValues<UserType>())
|
@foreach (var enumValue in Enum.GetValues<UserType>())
|
||||||
{
|
{
|
||||||
<SelectItem TValue="UserType" Value="enumValue">@enumValue</SelectItem>
|
<SelectItem TValue="UserType" Value="enumValue">@enumValue</SelectItem>
|
||||||
}
|
}
|
||||||
</Select>
|
</Select>
|
||||||
|
@if (IsLastAdmin)
|
||||||
|
{
|
||||||
|
<small class="text-danger mt-1 d-block">Das ist der letzte Administrator-Account. Der Typ kann nicht geändert werden.</small>
|
||||||
|
}
|
||||||
</Field>
|
</Field>
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel>Gruppen</FieldLabel>
|
<FieldLabel>Gruppen</FieldLabel>
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private bool IsEditing { get; set; }
|
private bool IsEditing { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the current editing user is the last admin
|
||||||
|
/// </summary>
|
||||||
|
private bool IsLastAdmin => IsEditing && EditModel?.Type == UserType.Admin && UserList?.Count(x => x.Type == UserType.Admin) <= 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the value of the user groups (ab)
|
/// Gets the value of the user groups (ab)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -126,6 +131,10 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
await ConfirmDialog.ShowAsync(ModalService, "Bestätigen", $"Soll eine E-Mail zum Festlegen des Passworts an {user.Mail} gesendet werden?", async () =>
|
await ConfirmDialog.ShowAsync(ModalService, "Bestätigen", $"Soll eine E-Mail zum Festlegen des Passworts an {user.Mail} gesendet werden?", async () =>
|
||||||
{
|
{
|
||||||
await AuthService.InitiateInitialPasswordSetup(user.Mail, NavigationManager.BaseUri);
|
await AuthService.InitiateInitialPasswordSetup(user.Mail, NavigationManager.BaseUri);
|
||||||
|
if (Notification != null)
|
||||||
|
{
|
||||||
|
await Notification.Success("E-Mail gesendet. Bitte weise den Benutzer darauf hin, auch den Spam-Ordner zu prüfen.");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,12 +189,6 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// <returns>A task that represents the asynchronous remove operation.</returns>
|
/// <returns>A task that represents the asynchronous remove operation.</returns>
|
||||||
private async Task RemoveUserAsync(User user)
|
private async Task RemoveUserAsync(User user)
|
||||||
{
|
{
|
||||||
if (user.IsAdmin())
|
|
||||||
{
|
|
||||||
await Notification.Error("Admins können nicht gelöscht werden!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await ConfirmDialog.ShowAsync(ModalService, "Bestätigen", $"User {user.Mail} löschen?", async () =>
|
await ConfirmDialog.ShowAsync(ModalService, "Bestätigen", $"User {user.Mail} löschen?", async () =>
|
||||||
{
|
{
|
||||||
var removeR = await UserService.RemoveAsync(user.Id);
|
var removeR = await UserService.RemoveAsync(user.Id);
|
||||||
|
|||||||
@@ -14,18 +14,18 @@
|
|||||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Foodsharing Einarbeitungen" />
|
<meta name="apple-mobile-web-app-title" content="Foodsharing Einarbeitungen" />
|
||||||
<link rel="manifest" href="/site.webmanifest" />
|
<link rel="manifest" href="/site.webmanifest" />
|
||||||
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css"/>
|
<link rel="stylesheet" href="~/css/bootstrap/bootstrap.min.css" asp-append-version="true" />
|
||||||
<link href="css/site.css" rel="stylesheet"/>
|
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
|
||||||
<link href="FoodsharingSiegen.Server.styles.css" rel="stylesheet"/>
|
<link href="~/FoodsharingSiegen.Server.styles.css" rel="stylesheet" asp-append-version="true" />
|
||||||
|
|
||||||
<!-- Material CSS -->
|
<!-- Material CSS -->
|
||||||
<link href="css/material.min.css" rel="stylesheet">
|
<link href="~/css/material.min.css" rel="stylesheet" asp-append-version="true" />
|
||||||
|
|
||||||
<!-- Add Material font (Roboto) and Material icon as needed -->
|
<!-- Add Material font (Roboto) and Material icon as needed -->
|
||||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i|Roboto+Mono:300,400,700|Roboto+Slab:300,400,700" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i|Roboto+Mono:300,400,700|Roboto+Slab:300,400,700" rel="stylesheet">
|
||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
|
|
||||||
<link href="css/all.min.css" rel="stylesheet" />
|
<link href="~/css/all.min.css" rel="stylesheet" asp-append-version="true" />
|
||||||
<link href="_content/Blazorise/blazorise.css?v=1.7.5.0" rel="stylesheet" />
|
<link href="_content/Blazorise/blazorise.css?v=1.7.5.0" rel="stylesheet" />
|
||||||
<link href="_content/Blazorise.Material/blazorise.material.css?v=1.7.5.0" rel="stylesheet" />
|
<link href="_content/Blazorise.Material/blazorise.material.css?v=1.7.5.0" rel="stylesheet" />
|
||||||
<link href="_content/Blazorise.Icons.Material/blazorise.icons.material.css?v=1.7.5.0" rel="stylesheet" />
|
<link href="_content/Blazorise.Icons.Material/blazorise.icons.material.css?v=1.7.5.0" rel="stylesheet" />
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.LoadAppSettings();
|
builder.LoadAppSettings();
|
||||||
|
|
||||||
builder.WebHost.UseUrls("http://+:8700");
|
// Keep the app default binding in config for Docker/container deployment.
|
||||||
|
// Local debugging can override it via ASPNETCORE_URLS in launchSettings.
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
|
|||||||
@@ -12,10 +12,11 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "http://localhost:56000/",
|
"launchUrl": "http://localhost:5010/",
|
||||||
"applicationUrl": "http://localhost:56000",
|
"applicationUrl": "http://localhost:5010",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"ASPNETCORE_URLS": "http://localhost:5010"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FoodsharingSiegen.Contracts.Model;
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
using MailKit.Net.Smtp;
|
using MailKit.Net.Smtp;
|
||||||
@@ -15,15 +16,17 @@ namespace FoodsharingSiegen.Server.Service
|
|||||||
{
|
{
|
||||||
private readonly MailSettings _mailSettings;
|
private readonly MailSettings _mailSettings;
|
||||||
private readonly TermSettings _termSettings;
|
private readonly TermSettings _termSettings;
|
||||||
|
private readonly Func<ISmtpClient> _smtpClientFactory;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MailService"/> class.
|
/// Initializes a new instance of the <see cref="MailService"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="appSettings">The configured application settings injected by DI, containing the <see cref="MailSettings"/>.</param>
|
/// <param name="appSettings">The configured application settings injected by DI, containing the <see cref="MailSettings"/>.</param>
|
||||||
public MailService(IOptions<AppSettings> appSettings)
|
public MailService(IOptions<AppSettings> appSettings, Func<ISmtpClient>? smtpClientFactory = null)
|
||||||
{
|
{
|
||||||
_mailSettings = appSettings.Value.Mail;
|
_mailSettings = appSettings.Value.Mail;
|
||||||
_termSettings = appSettings.Value.Terms;
|
_termSettings = appSettings.Value.Terms;
|
||||||
|
_smtpClientFactory = smtpClientFactory ?? (() => new SmtpClient());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -40,7 +43,7 @@ namespace FoodsharingSiegen.Server.Service
|
|||||||
};
|
};
|
||||||
email.Body = textPart;
|
email.Body = textPart;
|
||||||
|
|
||||||
using var smtp = new SmtpClient();
|
using var smtp = _smtpClientFactory();
|
||||||
var secureOptions = _mailSettings.UseSsl ? SecureSocketOptions.StartTls : SecureSocketOptions.Auto;
|
var secureOptions = _mailSettings.UseSsl ? SecureSocketOptions.StartTls : SecureSocketOptions.Auto;
|
||||||
|
|
||||||
await smtp.ConnectAsync(_mailSettings.Host, _mailSettings.Port, secureOptions);
|
await smtp.ConnectAsync(_mailSettings.Host, _mailSettings.Port, secureOptions);
|
||||||
|
|||||||
@@ -64,15 +64,15 @@
|
|||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
|
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<div @onclick="NavLinkClickedAsync">
|
<div @onclick="NavLinkClickedAsync">
|
||||||
<NavLink class="nav-link" href="audit" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href="audit" Match="NavLinkMatch.All">
|
||||||
<span class="fa-solid fa-clock-rotate-left mr-2" aria-hidden="true" style="font-size: 1.4em;"></span> Aktivitäten
|
<span class="fa-solid fa-clock-rotate-left mr-2" aria-hidden="true" style="font-size: 1.4em;"></span> Aktivitäten
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
|
|
||||||
<div class="flex-grow-1"></div>
|
<div class="flex-grow-1"></div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sourceRoot":"","sources":["NavMenu.razor.scss"],"names":[],"mappings":"AAEA;EACI;;AAEA;EAHJ;IAIQ;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EATJ;IAUQ;IACA;;;;AAKZ;EACI;EACA;EACA;EACA;;;AAGJ;EACI;EACA;;;AAGA;EACI;;;AAGJ;EACI;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;;;AAGR;EACI;EACA;;;AAGJ;EACI;EACA","file":"NavMenu.razor.css"}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export function attachScrollLoader(gridId, component) {
|
||||||
|
const grid = document.getElementById(gridId);
|
||||||
|
if (!grid) return;
|
||||||
|
|
||||||
|
const checkScroll = () => {
|
||||||
|
const distanceFromBottom = grid.scrollHeight - (grid.scrollTop + grid.clientHeight);
|
||||||
|
if (distanceFromBottom < 250) {
|
||||||
|
component.invokeMethodAsync('OnScrollNearBottom');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
grid.addEventListener('scroll', checkScroll, { passive: true });
|
||||||
|
grid.__prospectScrollCheck = checkScroll;
|
||||||
|
checkScroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function disposeScrollLoader(gridId) {
|
||||||
|
const grid = document.getElementById(gridId);
|
||||||
|
if (!grid || !grid.__prospectScrollCheck) return;
|
||||||
|
|
||||||
|
grid.removeEventListener('scroll', grid.__prospectScrollCheck);
|
||||||
|
delete grid.__prospectScrollCheck;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||||
|
<PackageReference Include="Moq" Version="4.20.72" />
|
||||||
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FoodsharingSiegen.Server\FoodsharingSiegen.Server.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using FoodsharingSiegen.Server.Service;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FoodsharingSiegen.Tests
|
||||||
|
{
|
||||||
|
public class LocalStorageServiceTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task GetItem_ReturnsDeserializedObject_WhenItemExists()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var mockJsRuntime = new Mock<IJSRuntime>();
|
||||||
|
var service = new LocalStorageService(mockJsRuntime.Object);
|
||||||
|
var expectedObject = new { Name = "Test" };
|
||||||
|
var jsonString = JsonSerializer.Serialize(expectedObject);
|
||||||
|
|
||||||
|
mockJsRuntime.Setup(x => x.InvokeAsync<string>("localStorage.getItem", It.IsAny<object[]>()))
|
||||||
|
.ReturnsAsync(jsonString);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await service.GetItem<dynamic>("testKey");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
mockJsRuntime.Verify(x => x.InvokeAsync<string>("localStorage.getItem", It.Is<object[]>(args => args.Length == 1 && args[0].ToString() == "testKey")), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetItem_ReturnsDefault_WhenItemDoesNotExist()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var mockJsRuntime = new Mock<IJSRuntime>();
|
||||||
|
var service = new LocalStorageService(mockJsRuntime.Object);
|
||||||
|
|
||||||
|
mockJsRuntime.Setup(x => x.InvokeAsync<string>("localStorage.getItem", It.IsAny<object[]>()))
|
||||||
|
.ReturnsAsync((string?)null);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await service.GetItem<string>("testKey");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Null(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SetItem_CallsSetItemInLocalStorage()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var mockJsRuntime = new Mock<IJSRuntime>();
|
||||||
|
var service = new LocalStorageService(mockJsRuntime.Object);
|
||||||
|
var objectToSave = new { Name = "Test" };
|
||||||
|
var expectedJson = JsonSerializer.Serialize(objectToSave);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await service.SetItem("testKey", objectToSave);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
// Note: InvokeVoidAsync is an extension method that calls InvokeAsync<IJSVoidResult> under the hood in Blazor.
|
||||||
|
mockJsRuntime.Verify(
|
||||||
|
x => x.InvokeAsync<It.IsAnyType>(
|
||||||
|
"localStorage.setItem",
|
||||||
|
It.Is<object[]>(args => args.Length == 2 && args[0].ToString() == "testKey" && args[1].ToString() == expectedJson)),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task RemoveItem_CallsRemoveItemInLocalStorage()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var mockJsRuntime = new Mock<IJSRuntime>();
|
||||||
|
var service = new LocalStorageService(mockJsRuntime.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await service.RemoveItem("testKey");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
mockJsRuntime.Verify(
|
||||||
|
x => x.InvokeAsync<It.IsAnyType>(
|
||||||
|
"localStorage.removeItem",
|
||||||
|
It.Is<object[]>(args => args.Length == 1 && args[0].ToString() == "testKey")),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
|
using FoodsharingSiegen.Server.Service;
|
||||||
|
using MailKit.Net.Smtp;
|
||||||
|
using MailKit.Security;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using MimeKit;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FoodsharingSiegen.Tests
|
||||||
|
{
|
||||||
|
public class MailServiceTests
|
||||||
|
{
|
||||||
|
private readonly Mock<IOptions<AppSettings>> _mockOptions;
|
||||||
|
private readonly AppSettings _appSettings;
|
||||||
|
private readonly Mock<ISmtpClient> _mockSmtpClient;
|
||||||
|
|
||||||
|
public MailServiceTests()
|
||||||
|
{
|
||||||
|
_appSettings = new AppSettings
|
||||||
|
{
|
||||||
|
Mail = new MailSettings
|
||||||
|
{
|
||||||
|
Host = "smtp.test.com",
|
||||||
|
Port = 587,
|
||||||
|
UseSsl = false,
|
||||||
|
Username = "user@test.com",
|
||||||
|
Password = "password123",
|
||||||
|
FromAddress = "no-reply@test.com"
|
||||||
|
},
|
||||||
|
Terms = new TermSettings
|
||||||
|
{
|
||||||
|
Title = "Foodsharing Test"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_mockOptions = new Mock<IOptions<AppSettings>>();
|
||||||
|
_mockOptions.Setup(o => o.Value).Returns(_appSettings);
|
||||||
|
|
||||||
|
_mockSmtpClient = new Mock<ISmtpClient>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SendEmailAsync_ConnectsAuthenticatesAndSendsEmail()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var service = new MailService(_mockOptions.Object, () => _mockSmtpClient.Object);
|
||||||
|
var toEmail = "recipient@test.com";
|
||||||
|
var subject = "Test Subject";
|
||||||
|
var body = "<p>Test Body</p>";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await service.SendEmailAsync(toEmail, subject, body);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockSmtpClient.Verify(
|
||||||
|
x => x.ConnectAsync(
|
||||||
|
"smtp.test.com",
|
||||||
|
587,
|
||||||
|
SecureSocketOptions.Auto,
|
||||||
|
It.IsAny<CancellationToken>()),
|
||||||
|
Times.Once);
|
||||||
|
|
||||||
|
_mockSmtpClient.Verify(
|
||||||
|
x => x.AuthenticateAsync(
|
||||||
|
"user@test.com",
|
||||||
|
"password123",
|
||||||
|
It.IsAny<CancellationToken>()),
|
||||||
|
Times.Once);
|
||||||
|
|
||||||
|
// Verify a MimeMessage is passed to SendAsync with correct attributes
|
||||||
|
_mockSmtpClient.Verify(
|
||||||
|
x => x.SendAsync(
|
||||||
|
It.Is<MimeMessage>(m => m.Subject == subject),
|
||||||
|
It.IsAny<CancellationToken>(),
|
||||||
|
It.IsAny<MailKit.ITransferProgress>()),
|
||||||
|
Times.Once);
|
||||||
|
|
||||||
|
_mockSmtpClient.Verify(
|
||||||
|
x => x.DisconnectAsync(
|
||||||
|
true,
|
||||||
|
It.IsAny<CancellationToken>()),
|
||||||
|
Times.Once);
|
||||||
|
|
||||||
|
_mockSmtpClient.Verify(
|
||||||
|
x => x.Dispose(),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SendEmailAsync_SkipsAuthentication_WhenUsernameIsBlank()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_appSettings.Mail.Username = "";
|
||||||
|
_appSettings.Mail.Password = "";
|
||||||
|
var service = new MailService(_mockOptions.Object, () => _mockSmtpClient.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await service.SendEmailAsync("recipient@test.com", "Subject", "Body");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockSmtpClient.Verify(
|
||||||
|
x => x.AuthenticateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()),
|
||||||
|
Times.Never);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
using FoodsharingSiegen.Contracts.Entity;
|
||||||
|
using FoodsharingSiegen.Contracts.Enums;
|
||||||
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
|
using FoodsharingSiegen.Server.Auth;
|
||||||
|
using FoodsharingSiegen.Server.Data;
|
||||||
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
|
using FoodsharingSiegen.Server.Service;
|
||||||
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FoodsharingSiegen.Tests;
|
||||||
|
|
||||||
|
public class ProspectServiceTests
|
||||||
|
{
|
||||||
|
private static FsContext CreateInMemoryContext(string dbName)
|
||||||
|
{
|
||||||
|
var options = new DbContextOptionsBuilder<FsContext>()
|
||||||
|
.UseInMemoryDatabase(databaseName: dbName)
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
return new FsContext(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AuthService CreateAuthService(FsContext context)
|
||||||
|
{
|
||||||
|
var mockJsRuntime = new Mock<IJSRuntime>();
|
||||||
|
var localStorageService = new LocalStorageService(mockJsRuntime.Object);
|
||||||
|
var authStateProvider = new Mock<AuthenticationStateProvider>();
|
||||||
|
var mailService = new Mock<IMailService>();
|
||||||
|
var appSettings = new Mock<IOptions<AppSettings>>();
|
||||||
|
appSettings.Setup(x => x.Value).Returns(new AppSettings());
|
||||||
|
|
||||||
|
return new AuthService(context, localStorageService, authStateProvider.Object, mailService.Object, appSettings.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetProspectsAsync_RespectsSkipAndTake()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = new AuditService(context, authService);
|
||||||
|
var prospectService = new ProspectService(context, authService, auditService);
|
||||||
|
|
||||||
|
for (var i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
context.Prospects!.Add(new Prospect
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = $"Prospect {i}",
|
||||||
|
Modified = DateTime.UtcNow.AddDays(-i),
|
||||||
|
Interactions = new List<Interaction>()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
|
var result = await prospectService.GetProspectsAsync(new GetProspectsParameter
|
||||||
|
{
|
||||||
|
Skip = 1,
|
||||||
|
Take = 2,
|
||||||
|
IncludeDeleted = true
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Equal(2, result.Data.Count);
|
||||||
|
Assert.Equal("Prospect 1", result.Data[0].Name);
|
||||||
|
Assert.Equal("Prospect 2", result.Data[1].Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,236 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FoodsharingSiegen.Contracts.Entity;
|
||||||
|
using FoodsharingSiegen.Contracts.Enums;
|
||||||
|
using FoodsharingSiegen.Contracts.Model;
|
||||||
|
using FoodsharingSiegen.Server.Auth;
|
||||||
|
using FoodsharingSiegen.Server.Data;
|
||||||
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
|
using FoodsharingSiegen.Server.Service;
|
||||||
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FoodsharingSiegen.Tests
|
||||||
|
{
|
||||||
|
public class UserServiceTests
|
||||||
|
{
|
||||||
|
private FsContext CreateInMemoryContext(string dbName)
|
||||||
|
{
|
||||||
|
var options = new DbContextOptionsBuilder<FsContext>()
|
||||||
|
.UseInMemoryDatabase(databaseName: dbName)
|
||||||
|
.Options;
|
||||||
|
return new FsContext(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AuthService CreateAuthService(FsContext context, User? currentUser = null)
|
||||||
|
{
|
||||||
|
var mockJsRuntime = new Mock<IJSRuntime>();
|
||||||
|
var localStorageService = new LocalStorageService(mockJsRuntime.Object);
|
||||||
|
var authStateProvider = new Mock<AuthenticationStateProvider>();
|
||||||
|
var mailService = new Mock<IMailService>();
|
||||||
|
var appSettings = new Mock<IOptions<AppSettings>>();
|
||||||
|
appSettings.Setup(x => x.Value).Returns(new AppSettings());
|
||||||
|
|
||||||
|
var authService = new AuthService(context, localStorageService, authStateProvider.Object, mailService.Object, appSettings.Object);
|
||||||
|
|
||||||
|
if (currentUser != null)
|
||||||
|
{
|
||||||
|
var field = typeof(AuthService).GetField("_user", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
field?.SetValue(authService, currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
return authService;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AuditService CreateAuditService(FsContext context, AuthService authService)
|
||||||
|
{
|
||||||
|
return new AuditService(context, authService);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddUserAsync_Fails_WhenEmailAlreadyExists()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
context.Users!.Add(new User { Mail = "existing@example.com", Name = "Existing", Password = "123" });
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var result = await userService.AddUserAsync(new User { Mail = "EXISTING@example.com", Name = "New" });
|
||||||
|
|
||||||
|
Assert.False(result.Success);
|
||||||
|
Assert.Equal("Diese E-Mail Adresse wird bereits verwendet", result.ErrorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddUserAsync_Succeeds_AndSetsPasswordEmpty_IfNull()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var newUser = new User { Mail = "new@example.com", Name = "New", };
|
||||||
|
|
||||||
|
var result = await userService.AddUserAsync(newUser);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Equal(string.Empty, result.Data?.Password);
|
||||||
|
Assert.NotNull(result.Data?.Created);
|
||||||
|
Assert.Single(context.Users!);
|
||||||
|
Assert.Single(context.Audits!);
|
||||||
|
Assert.Equal(AuditType.CreateUser, context.Audits!.First().Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task RemoveAsync_TransferInteractions_AndRemovesUser()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
|
||||||
|
var currentUser = new User { Id = Guid.NewGuid(), Mail = "current@example.com" };
|
||||||
|
var authService = CreateAuthService(context, currentUser);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var userToRemove = new User { Id = Guid.NewGuid(), Mail = "remove@example.com", Type = UserType.User };
|
||||||
|
context.Users!.Add(currentUser);
|
||||||
|
context.Users!.Add(userToRemove);
|
||||||
|
|
||||||
|
context.Interactions!.Add(new Interaction { Id = Guid.NewGuid(), UserID = userToRemove.Id });
|
||||||
|
context.Audits!.Add(new Audit { Id = Guid.NewGuid(), UserID = userToRemove.Id, Type = AuditType.None });
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var result = await userService.RemoveAsync(userToRemove.Id);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Empty(context.Users!.Where(u => u.Id == userToRemove.Id));
|
||||||
|
var interaction = context.Interactions!.First();
|
||||||
|
Assert.Equal(currentUser.Id, interaction.UserID);
|
||||||
|
Assert.Single(context.Audits!.Where(a => a.Type == AuditType.RemoveUser)); // created audit for remove
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task RemoveAsync_Fails_WhenLastAdmin()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var admin = new User { Id = Guid.NewGuid(), Mail = "admin@example.com", Type = UserType.Admin };
|
||||||
|
context.Users!.Add(admin);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var result = await userService.RemoveAsync(admin.Id);
|
||||||
|
|
||||||
|
Assert.False(result.Success);
|
||||||
|
Assert.Equal("Der letzte Administrator kann nicht gelöscht werden.", result.ErrorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SetPassword_Fails_IfUserNotFound()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var result = await userService.SetPassword(new User { Id = Guid.NewGuid(), Password = "P" });
|
||||||
|
|
||||||
|
Assert.False(result.Success);
|
||||||
|
Assert.Equal("User not found", result.ErrorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SetPassword_Succeeds()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var user = new User { Id = Guid.NewGuid(), Mail = "test@example.com", Password = "Old" };
|
||||||
|
context.Users!.Add(user);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var result = await userService.SetPassword(new User { Id = user.Id, Password = "New" });
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Equal("New", context.Users!.First().Password);
|
||||||
|
Assert.Equal(AuditType.SetUserPassword, context.Audits!.First().Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Update_Fails_IfNoChanges()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var user = new User { Id = Guid.NewGuid(), Mail = "a@a.com", Type = UserType.User };
|
||||||
|
context.Users!.Add(user);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var result = await userService.Update(new User { Id = user.Id, Mail = "a@a.com", Type = UserType.User });
|
||||||
|
|
||||||
|
Assert.False(result.Success);
|
||||||
|
Assert.Equal("Nichts zum Speichern gefunden", result.ErrorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Update_ForcesLogoutOnChange()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var user = new User { Id = Guid.NewGuid(), Mail = "a@a.com", Type = UserType.User };
|
||||||
|
context.Users!.Add(user);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var result = await userService.Update(new User { Id = user.Id, Mail = "b@b.com", Type = UserType.User });
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.True(context.Users!.First().ForceLogout);
|
||||||
|
Assert.Single(context.Audits!.Where(a => a.Type == AuditType.UpdateUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Update_Fails_WhenDemotingLastAdmin()
|
||||||
|
{
|
||||||
|
var dbName = Guid.NewGuid().ToString();
|
||||||
|
using var context = CreateInMemoryContext(dbName);
|
||||||
|
var authService = CreateAuthService(context);
|
||||||
|
var auditService = CreateAuditService(context, authService);
|
||||||
|
var userService = new UserService(context, authService, auditService);
|
||||||
|
|
||||||
|
var admin = new User { Id = Guid.NewGuid(), Mail = "a@a.com", Type = UserType.Admin };
|
||||||
|
context.Users!.Add(admin);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var result = await userService.Update(new User { Id = admin.Id, Mail = "a@a.com", Type = UserType.User });
|
||||||
|
|
||||||
|
Assert.False(result.Success);
|
||||||
|
Assert.Equal("Der Typ des letzten Administrators kann nicht geändert werden.", result.ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,23 +6,68 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodsharingSiegen.Contracts
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodsharingSiegen.Shared", "FoodsharingSiegen.Shared\FoodsharingSiegen.Shared.csproj", "{625167D9-A375-40AF-82DE-87484519F6D9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodsharingSiegen.Shared", "FoodsharingSiegen.Shared\FoodsharingSiegen.Shared.csproj", "{625167D9-A375-40AF-82DE-87484519F6D9}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodsharingSiegen.Tests", "FoodsharingSiegen.Tests\FoodsharingSiegen.Tests.csproj", "{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{63D6CC91-095D-44C3-8752-660DDF9C710C}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|Any CPU.Build.0 = Release|Any CPU
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{625167D9-A375-40AF-82DE-87484519F6D9}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{A3BBF859-E3BB-420A-895F-B1BCF4B38B74}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Reference in New Issue
Block a user