ProspectService updates
This commit is contained in:
74
FoodsharingSiegen.Server/Controls/InteractionRow.razor
Normal file
74
FoodsharingSiegen.Server/Controls/InteractionRow.razor
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
@using FoodsharingSiegen.Contracts.Entity
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Prospect Prospect { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public InteractionType Type { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback AddClick { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<Guid> RemoveClick { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public string Caption { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public string ButtonText { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public string IconClass { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool Multiple { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public int Minimum { get; set; } = 1;
|
||||||
|
|
||||||
|
private List<Interaction> Interactions => Prospect?.Interactions?.Where(x => x.Type == Type).ToList() ?? new List<Interaction>();
|
||||||
|
|
||||||
|
private bool Done => Interactions.Count >= Minimum;
|
||||||
|
}
|
||||||
|
|
||||||
|
@{
|
||||||
|
var rowClass = "";
|
||||||
|
if (Done) rowClass += "done";
|
||||||
|
}
|
||||||
|
|
||||||
|
<tr class="@rowClass" style="border-top: 5px solid transparent;">
|
||||||
|
<th class="text-center align-top pr-2">
|
||||||
|
<i class="@IconClass"></i>
|
||||||
|
</th>
|
||||||
|
<th class="pr-2 align-top">@Caption:</th>
|
||||||
|
<td class="align-top">
|
||||||
|
@if (Interactions.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var interaction in Interactions)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
@interaction.User.Name (@interaction.Date.ToShortDateString())
|
||||||
|
@if (!string.IsNullOrWhiteSpace(interaction.Info))
|
||||||
|
{
|
||||||
|
<span>(<i>@interaction.Info</i>)</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!Prospect.Complete || interaction.Type == InteractionType.Complete)
|
||||||
|
{
|
||||||
|
<span> <a href=""><i class="fa-solid fa-square-xmark" @onclick="async () => await RemoveClick.InvokeAsync(interaction.Id)" @onclick:preventDefault></i></a></span>
|
||||||
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!Prospect.Complete && (Interactions.Count == 0 || Multiple))
|
||||||
|
{
|
||||||
|
if (Multiple) ButtonText = "+";
|
||||||
|
<Button Size="Size.Small" Clicked="AddClick">@ButtonText</Button>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
tr.done th {
|
||||||
|
color: #64ae24;
|
||||||
|
}
|
||||||
@@ -34,15 +34,16 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
var targetProspect = await Context.Prospects.Include(x => x.Interactions).FirstOrDefaultAsync(x => x.Id == interaction.ProspectId);
|
var targetProspect = await Context.Prospects.Include(x => x.Interactions).FirstOrDefaultAsync(x => x.Id == interaction.ProspectId);
|
||||||
if (targetProspect == null) return new OperationResult<Interaction>(new Exception("Invalid prospect id"));
|
if (targetProspect == null) return new OperationResult<Interaction>(new Exception("Invalid prospect id"));
|
||||||
|
|
||||||
var dummyUser = Context.Users.First().Id;
|
|
||||||
|
|
||||||
interaction.ProspectId = Guid.Empty;
|
interaction.ProspectId = Guid.Empty;
|
||||||
interaction.UserId = dummyUser;
|
|
||||||
|
|
||||||
targetProspect.Interactions.Add(interaction);
|
targetProspect.Interactions.Add(interaction);
|
||||||
|
|
||||||
await Context.SaveChangesAsync();
|
await Context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Detatch entities
|
||||||
|
Context.Entry(targetProspect).State = EntityState.Detached;
|
||||||
|
Context.Entry(interaction).State = EntityState.Detached;
|
||||||
|
|
||||||
return new OperationResult<Interaction>(interaction);
|
return new OperationResult<Interaction>(interaction);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -53,6 +54,21 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public async Task<OperationResult> RemoveInteraction(Guid interactionId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Context.Interactions.Remove(new Interaction { Id = interactionId });
|
||||||
|
await Context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new OperationResult();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new OperationResult(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Public Method AddProspectAsync
|
#region Public Method AddProspectAsync
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -95,7 +111,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var prospects = await Context.Prospects.Include(x => x.Interactions).ThenInclude(x => x.User).OrderBy(x => x.Name).ToListAsync();
|
var prospects = await Context.Prospects.AsNoTracking().Include(x => x.Interactions).ThenInclude(x => x.User).OrderBy(x => x.Name).ToListAsync();
|
||||||
return new OperationResult<List<Prospect>>(prospects);
|
return new OperationResult<List<Prospect>>(prospects);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@page "/"
|
@page "/user"
|
||||||
|
@page "/users"
|
||||||
@using FoodsharingSiegen.Contracts.Entity
|
@using FoodsharingSiegen.Contracts.Entity
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<PageTitle>Benutzer</PageTitle>
|
<PageTitle>Benutzerverwaltung</PageTitle>
|
||||||
|
|
||||||
<h2>Benutzerverwaltung <span style="font-size: .5em; line-height: 0;">Admin</span></h2>
|
<h2>Benutzerverwaltung <span style="font-size: .5em; line-height: 0;">Admin</span></h2>
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
|
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
|
||||||
<nav class="flex-column">
|
<nav class="flex-column">
|
||||||
<div class="nav-item px-3">
|
|
||||||
<NavLink class="nav-link" href="counter">
|
|
||||||
<span class="fas fa-tasks mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Übersicht
|
|
||||||
</NavLink>
|
|
||||||
</div>
|
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
||||||
|
<span class="fas fa-tasks mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Übersicht
|
||||||
|
</NavLink>
|
||||||
|
</div>
|
||||||
|
<div class="nav-item px-3">
|
||||||
|
<NavLink class="nav-link" href="users" Match="NavLinkMatch.All">
|
||||||
<span class="fas fa-users mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Benutzer
|
<span class="fas fa-users mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Benutzer
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ h1:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a, .btn-link {
|
a, .btn-link {
|
||||||
color: #0071c1;
|
color: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-primary {
|
.btn-primary {
|
||||||
|
|||||||
Reference in New Issue
Block a user