-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
307 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
@page "/group/{GroupSlug}/finance" | ||
|
||
@using GroupOrder.Data | ||
@using Microsoft.AspNetCore.WebUtilities | ||
@using Microsoft.EntityFrameworkCore | ||
@rendermode InteractiveServer | ||
|
||
@inject IDbContextFactory<GroupContext> DbFactory | ||
@inject NavigationManager nm | ||
|
||
<PageTitle>Mampf.Link @Group?.GroupName Finances</PageTitle> | ||
|
||
@if (Group != null) | ||
{ | ||
<h1>Finance Overview: @Group?.GroupName</h1> | ||
|
||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th> | ||
Name | ||
</th> | ||
<th> | ||
Price | ||
</th> | ||
<th> | ||
Payment Status | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (Order order in Group!.Orders) | ||
{ | ||
<tr> | ||
<td> | ||
@order.Name | ||
</td> | ||
<td> | ||
@order.getPrice()€ | ||
</td> | ||
<td style="padding-top: 3px; padding-bottom: 0"> | ||
<InputSelect class="form-select form-select-sm" style="max-width: 200px" @bind-Value="@order.PaymentStatus"> | ||
<option value="@PaymentStatus.Unpaid">Unpaid</option> | ||
<option value="@PaymentStatus.PaymentPending">Payment Pending</option> | ||
<option value="@PaymentStatus.Paid">Paid</option> | ||
</InputSelect> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
<button class="btn btn-primary" @onclick="Save">Save changes</button> | ||
} | ||
|
||
@code { | ||
|
||
private Group? Group { get; set; } | ||
|
||
private bool Loading { get; set; } = false; | ||
private bool NotFound { get; set; } = false; | ||
|
||
[Parameter] | ||
public string? GroupSlug { get; set; } | ||
|
||
private string? AdminCode { get; set; } | ||
|
||
protected override Task OnInitializedAsync() | ||
{ | ||
_context = DbFactory.CreateDbContext(); | ||
return base.OnInitializedAsync(); | ||
} | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
await LoadGroupAsync(); | ||
await base.OnParametersSetAsync(); | ||
} | ||
|
||
GroupContext? _context; | ||
|
||
// Loads the contact. | ||
private async Task LoadGroupAsync() | ||
{ | ||
if (nm.Uri.Contains("?") && QueryHelpers.ParseQuery(nm.Uri.Split("?")[1]).TryGetValue("admin", out var code)) | ||
{ | ||
AdminCode = code; | ||
} | ||
else | ||
{ | ||
NotFound = true; | ||
return; | ||
} | ||
|
||
if (Loading) | ||
{ | ||
return; //avoid concurrent requests. | ||
} | ||
|
||
Group = null; | ||
Loading = true; | ||
|
||
if (_context!.Groups is not null) | ||
{ | ||
Group = await _context!.Groups | ||
.Include(group => group.Orders) | ||
.SingleOrDefaultAsync( | ||
c => c.GroupSlug == GroupSlug && c.AdminCode == AdminCode); | ||
|
||
if (Group is null) | ||
{ | ||
NotFound = true; | ||
} | ||
} | ||
|
||
Loading = false; | ||
} | ||
|
||
private async void Save() | ||
{ | ||
if (Group == null) return; | ||
if (Group.AdminCode != AdminCode) return; // this theoretically should not happen | ||
await _context!.SaveChangesAsync(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace GroupOrder.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class Finance : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.AddColumn<int>( | ||
name: "PaymentStatus", | ||
table: "Orders", | ||
type: "INTEGER", | ||
nullable: false, | ||
defaultValue: 0); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropColumn( | ||
name: "PaymentStatus", | ||
table: "Orders"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters