FInished auto crud. Switched to auto crud for coupons. Added gift code manage
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Moonlight.App.Models.Forms.Store;
|
namespace Moonlight.App.Models.Forms.Admin.Store;
|
||||||
|
|
||||||
public class AddCouponForm
|
public class AddCouponForm
|
||||||
{
|
{
|
||||||
16
Moonlight/App/Models/Forms/Admin/Store/AddGiftCodeForm.cs
Normal file
16
Moonlight/App/Models/Forms/Admin/Store/AddGiftCodeForm.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Models.Forms.Admin.Store;
|
||||||
|
|
||||||
|
public class AddGiftCodeForm
|
||||||
|
{
|
||||||
|
[MinLength(5, ErrorMessage = "The code needs to be longer than 4")]
|
||||||
|
[MaxLength(15, ErrorMessage = "The code should not be longer than 15 characters")]
|
||||||
|
public string Code { get; set; } = "";
|
||||||
|
|
||||||
|
[Range(0, int.MaxValue, ErrorMessage = "The value needs to be equals or greater than 0")]
|
||||||
|
public double Value { get; set; }
|
||||||
|
|
||||||
|
[Range(0, int.MaxValue, ErrorMessage = "The amount needs to be equals or greater than 0")]
|
||||||
|
public int Amount { get; set; }
|
||||||
|
}
|
||||||
16
Moonlight/App/Models/Forms/Admin/Store/EditCouponForm.cs
Normal file
16
Moonlight/App/Models/Forms/Admin/Store/EditCouponForm.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Models.Forms.Admin.Store;
|
||||||
|
|
||||||
|
public class EditCouponForm
|
||||||
|
{
|
||||||
|
[MinLength(5, ErrorMessage = "The code needs to be longer than 4")]
|
||||||
|
[MaxLength(15, ErrorMessage = "The code should not be longer than 15 characters")]
|
||||||
|
public string Code { get; set; } = "";
|
||||||
|
|
||||||
|
[Range(1, 99, ErrorMessage = "The percent needs to be between 1 and 99")]
|
||||||
|
public int Percent { get; set; }
|
||||||
|
|
||||||
|
[Range(0, int.MaxValue, ErrorMessage = "The amount needs to be equals or greater than 0")]
|
||||||
|
public int Amount { get; set; }
|
||||||
|
}
|
||||||
16
Moonlight/App/Models/Forms/Admin/Store/EditGiftCodeForm.cs
Normal file
16
Moonlight/App/Models/Forms/Admin/Store/EditGiftCodeForm.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Models.Forms.Admin.Store;
|
||||||
|
|
||||||
|
public class EditGiftCodeForm
|
||||||
|
{
|
||||||
|
[MinLength(5, ErrorMessage = "The code needs to be longer than 4")]
|
||||||
|
[MaxLength(15, ErrorMessage = "The code should not be longer than 15 characters")]
|
||||||
|
public string Code { get; set; } = "";
|
||||||
|
|
||||||
|
[Range(0, int.MaxValue, ErrorMessage = "The value needs to be equals or greater than 0")]
|
||||||
|
public double Value { get; set; }
|
||||||
|
|
||||||
|
[Range(0, int.MaxValue, ErrorMessage = "The amount needs to be equals or greater than 0")]
|
||||||
|
public int Amount { get; set; }
|
||||||
|
}
|
||||||
@@ -1,61 +1,147 @@
|
|||||||
@using BlazorTable
|
@using BlazorTable
|
||||||
@using Moonlight.App.Repositories
|
@using Moonlight.App.Repositories
|
||||||
|
@using System.Linq.Expressions
|
||||||
|
@using Mappy.Net
|
||||||
|
|
||||||
@typeparam TItem where TItem : class
|
@typeparam TItem where TItem : class
|
||||||
|
@typeparam TCreateForm
|
||||||
|
@typeparam TUpdateForm
|
||||||
|
|
||||||
@inject Repository<TItem> ItemRepository
|
@inject Repository<TItem> ItemRepository
|
||||||
|
@inject ToastService ToastService
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h3 class="card-title">@(Title)</h3>
|
<h3 class="card-title">@(Title)</h3>
|
||||||
<div class="card-toolbar">
|
<div class="card-toolbar">
|
||||||
<button class="btn btn-icon btn-success">
|
<button @onclick="StartCreate" class="btn btn-icon btn-success">
|
||||||
<i class="bx bx-sm bx-plus"></i>
|
<i class="bx bx-sm bx-plus"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<LazyLoader Load="LoadItems">
|
<LazyLoader @ref="LazyLoader" Load="LoadItems">
|
||||||
<Table TableItem="TItem"
|
<Table TableItem="TItem"
|
||||||
Items="Items"
|
Items="Items"
|
||||||
PageSize="50"
|
PageSize="50"
|
||||||
TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3 fs-6"
|
TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3 fs-6"
|
||||||
TableHeadClass="fw-bold text-muted">
|
TableHeadClass="fw-bold text-muted">
|
||||||
@ChildContent
|
@ChildContent
|
||||||
|
<Column TableItem="TItem" Field="IdExpression" Title="" Sortable="false" Filterable="false">
|
||||||
|
<Template>
|
||||||
|
<div class="text-end">
|
||||||
|
<div class="btn-group">
|
||||||
|
<button @onclick="() => StartUpdate(context)" class="btn btn-icon btn-warning">
|
||||||
|
<i class="bx bx-sm bx-slider"></i>
|
||||||
|
</button>
|
||||||
|
<button @onclick="() => StartDelete(context)" class="btn btn-icon btn-danger">
|
||||||
|
<i class="bx bx-sm bx-trash"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Template>
|
||||||
|
</Column>
|
||||||
</Table>
|
</Table>
|
||||||
</LazyLoader>
|
</LazyLoader>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<SmartModal @ref="CreateModal" CssClasses="modal-dialog-centered modal-lg">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Create</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<SmartForm Model="CreateForm" OnValidSubmit="FinishCreate">
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="row">
|
||||||
|
<AutoForm Columns="6" Model="CreateForm"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||||
|
</div>
|
||||||
|
</SmartForm>
|
||||||
|
</SmartModal>
|
||||||
|
|
||||||
|
<SmartModal @ref="UpdateModal" CssClasses="modal-dialog-centered modal-lg">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Update</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<SmartForm Model="UpdateForm" OnValidSubmit="FinishUpdate">
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="row">
|
||||||
|
<AutoForm Columns="6" Model="UpdateForm"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||||
|
</div>
|
||||||
|
</SmartForm>
|
||||||
|
</SmartModal>
|
||||||
|
|
||||||
|
<SmartModal @ref="DeleteModal" CssClasses="modal-dialog-centered">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Do you want to delete this item?</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p class="text-gray-400 fs-5 fw-semibold">
|
||||||
|
This action cannot be undone. The data will be deleted and cannot be restored
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer p-3">
|
||||||
|
<div class="btn-group w-100">
|
||||||
|
<WButton OnClick="FinishDelete" Text="Delete" CssClasses="btn btn-danger w-50 me-3"/>
|
||||||
|
<button class="btn btn-secondary w-50" data-bs-dismiss="modal">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SmartModal>
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
|
|
||||||
[Parameter]
|
|
||||||
public Type CreateForm { get; set; }
|
|
||||||
|
|
||||||
[Parameter]
|
|
||||||
public Type UpdateForm { get; set; }
|
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<Repository<TItem>, TItem[]> Load { get; set; }
|
public Func<Repository<TItem>, TItem[]> Load { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public RenderFragment ChildContent { get; set; }
|
public RenderFragment ChildContent { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Func<TItem, Task>? ValidateAdd { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Func<TItem, Task>? ValidateUpdate { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Func<TItem, Task>? ValidateDelete { get; set; }
|
||||||
|
|
||||||
private TItem[] Items;
|
private TItem[] Items;
|
||||||
|
private TCreateForm CreateForm;
|
||||||
|
private TUpdateForm UpdateForm;
|
||||||
|
private TItem ItemToUpdate;
|
||||||
|
private TItem ItemToDelete;
|
||||||
|
|
||||||
|
private SmartModal CreateModal;
|
||||||
|
private SmartModal UpdateModal;
|
||||||
|
private SmartModal DeleteModal;
|
||||||
|
|
||||||
|
private Expression<Func<TItem, object>> IdExpression;
|
||||||
|
private LazyLoader LazyLoader;
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
if (CreateForm == null)
|
|
||||||
throw new ArgumentNullException(nameof(CreateForm));
|
|
||||||
|
|
||||||
if (UpdateForm == null)
|
|
||||||
throw new ArgumentNullException(nameof(UpdateForm));
|
|
||||||
|
|
||||||
if (Load == null)
|
if (Load == null)
|
||||||
throw new ArgumentNullException(nameof(Load));
|
throw new ArgumentNullException(nameof(Load));
|
||||||
|
|
||||||
|
CreateForm = Activator.CreateInstance<TCreateForm>()!;
|
||||||
|
UpdateForm = Activator.CreateInstance<TUpdateForm>()!;
|
||||||
|
|
||||||
|
IdExpression = CreateExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task LoadItems(LazyLoader _)
|
private Task LoadItems(LazyLoader _)
|
||||||
@@ -64,4 +150,86 @@
|
|||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task StartUpdate(TItem item)
|
||||||
|
{
|
||||||
|
UpdateForm = Mapper.Map<TUpdateForm>(item);
|
||||||
|
ItemToUpdate = item;
|
||||||
|
await UpdateModal.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task FinishUpdate()
|
||||||
|
{
|
||||||
|
var item = Mapper.Map(ItemToUpdate, UpdateForm!);
|
||||||
|
|
||||||
|
if (ValidateUpdate != null) // Optional additional validation
|
||||||
|
await ValidateUpdate.Invoke(item);
|
||||||
|
|
||||||
|
ItemRepository.Update(item);
|
||||||
|
|
||||||
|
// Reset
|
||||||
|
await UpdateModal.Hide();
|
||||||
|
await LazyLoader.Reload();
|
||||||
|
await ToastService.Success("Successfully updated item");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task StartCreate()
|
||||||
|
{
|
||||||
|
CreateForm = Activator.CreateInstance<TCreateForm>()!;
|
||||||
|
await CreateModal.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task FinishCreate()
|
||||||
|
{
|
||||||
|
var item = Mapper.Map<TItem>(CreateForm!);
|
||||||
|
|
||||||
|
if (ValidateAdd != null) // Optional additional validation
|
||||||
|
await ValidateAdd.Invoke(item);
|
||||||
|
|
||||||
|
ItemRepository.Add(item);
|
||||||
|
|
||||||
|
// Reset
|
||||||
|
await CreateModal.Hide();
|
||||||
|
await LazyLoader.Reload();
|
||||||
|
await ToastService.Success("Successfully added item");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task StartDelete(TItem item)
|
||||||
|
{
|
||||||
|
ItemToDelete = item;
|
||||||
|
await DeleteModal.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task FinishDelete()
|
||||||
|
{
|
||||||
|
if (ValidateDelete != null) // Optional additional validation
|
||||||
|
await ValidateDelete.Invoke(ItemToDelete);
|
||||||
|
|
||||||
|
ItemRepository.Delete(ItemToDelete);
|
||||||
|
|
||||||
|
// Reset
|
||||||
|
await DeleteModal.Hide();
|
||||||
|
await LazyLoader.Reload();
|
||||||
|
await ToastService.Success("Successfully deleted item");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Expression<Func<TItem, object>> CreateExpression()
|
||||||
|
{
|
||||||
|
// Parameter expression for the input object
|
||||||
|
var inputParam = Expression.Parameter(typeof(TItem), "input");
|
||||||
|
|
||||||
|
// Convert the input object to the actual model type (MyModel in this example)
|
||||||
|
var castedInput = Expression.Convert(inputParam, typeof(TItem));
|
||||||
|
|
||||||
|
// Create a property access expression using the property name
|
||||||
|
var propertyAccess = Expression.Property(castedInput, "Id");
|
||||||
|
|
||||||
|
// Convert the property value to an object
|
||||||
|
var castedResult = Expression.Convert(propertyAccess, typeof(object));
|
||||||
|
|
||||||
|
// Create a lambda expression
|
||||||
|
var lambda = Expression.Lambda<Func<TItem, object>>(castedResult, inputParam);
|
||||||
|
|
||||||
|
return lambda;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
@using Moonlight.App.Repositories
|
@using Moonlight.App.Repositories
|
||||||
@using Moonlight.App.Database.Entities.Store
|
@using Moonlight.App.Database.Entities.Store
|
||||||
@using Mappy.Net
|
@using Mappy.Net
|
||||||
|
@using Moonlight.App.Models.Forms.Admin.Store
|
||||||
|
|
||||||
@inject Repository<Coupon> CouponRepository
|
@inject Repository<Coupon> CouponRepository
|
||||||
@inject ToastService ToastService
|
@inject ToastService ToastService
|
||||||
|
|||||||
@@ -117,7 +117,10 @@
|
|||||||
|
|
||||||
await StoreService.Gift.Redeem(IdentityService.CurrentUser, GiftCode);
|
await StoreService.Gift.Redeem(IdentityService.CurrentUser, GiftCode);
|
||||||
|
|
||||||
|
// Reset
|
||||||
GiftCode = "";
|
GiftCode = "";
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
await ToastService.Success("Successfully applied gift code");
|
await ToastService.Success("Successfully applied gift code");
|
||||||
await LazyLoader.Reload();
|
await LazyLoader.Reload();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,70 +1,43 @@
|
|||||||
@page "/admin/store/coupons"
|
@page "/admin/store/coupons"
|
||||||
|
|
||||||
@using BlazorTable
|
|
||||||
@using Moonlight.App.Database.Entities.Store
|
@using Moonlight.App.Database.Entities.Store
|
||||||
@using Moonlight.App.Repositories
|
@using Moonlight.App.Repositories
|
||||||
@using Moonlight.Shared.Components.Modals.Store
|
@using BlazorTable
|
||||||
|
@using Moonlight.App.Models.Forms.Admin.Store
|
||||||
|
|
||||||
@inject Repository<Coupon> CouponRepository
|
@inject Repository<Coupon> CouponRepository
|
||||||
@inject Repository<CouponUse> CouponUseRepository
|
|
||||||
@inject ToastService ToastService
|
|
||||||
|
|
||||||
<AdminStoreNavigation Index="1" />
|
<AdminStoreNavigation Index="1"/>
|
||||||
|
|
||||||
<div class="card">
|
<div class="mt-5">
|
||||||
<div class="card-header">
|
<AutoCrud TItem="Coupon"
|
||||||
<h3 class="card-title">Coupons</h3>
|
TCreateForm="AddCouponForm"
|
||||||
<div class="card-toolbar">
|
TUpdateForm="EditCouponForm"
|
||||||
<button @onclick="() => AddCouponModal.Show()" class="btn btn-icon btn-success"><i class="bx bx-sm bx-plus"></i></button>
|
Title="Manage coupons"
|
||||||
</div>
|
Load="LoadData"
|
||||||
</div>
|
ValidateAdd="Validate"
|
||||||
<div class="card-body">
|
ValidateUpdate="Validate">
|
||||||
<LazyLoader @ref="LazyLoader" Load="Load">
|
|
||||||
<Table TableItem="Coupon"
|
|
||||||
Items="AllCoupons"
|
|
||||||
PageSize="50"
|
|
||||||
TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3 fs-6"
|
|
||||||
TableHeadClass="fw-bold text-muted">
|
|
||||||
<Column TableItem="Coupon" Title="Id" Field="@(x => x.Id)" Sortable="true" Filterable="true"/>
|
<Column TableItem="Coupon" Title="Id" Field="@(x => x.Id)" Sortable="true" Filterable="true"/>
|
||||||
<Column TableItem="Coupon" Title="Code" Field="@(x => x.Code)" Sortable="true" Filterable="true"/>
|
<Column TableItem="Coupon" Title="Code" Field="@(x => x.Code)" Sortable="true" Filterable="true"/>
|
||||||
<Column TableItem="Coupon" Title="Amount" Field="@(x => x.Amount)" Sortable="true" Filterable="true"/>
|
<Column TableItem="Coupon" Title="Amount" Field="@(x => x.Amount)" Sortable="true" Filterable="true"/>
|
||||||
<Column TableItem="Coupon" Title="Percent" Field="@(x => x.Percent)" Sortable="true" Filterable="true"/>
|
<Column TableItem="Coupon" Title="Percent" Field="@(x => x.Percent)" Sortable="true" Filterable="true"/>
|
||||||
<Column TableItem="Coupon" Title="" Field="@(x => x.Id)" Sortable="false" Filterable="false">
|
</AutoCrud>
|
||||||
<Template>
|
|
||||||
<a @onclick="() => Remove(context)" @onclick:preventDefault href="#" class="text-danger">Remove</a>
|
|
||||||
</Template>
|
|
||||||
</Column>
|
|
||||||
</Table>
|
|
||||||
</LazyLoader>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AddCouponModal @ref="AddCouponModal" OnUpdate="() => LazyLoader.Reload()" />
|
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private Coupon[] AllCoupons;
|
private Coupon[] LoadData(Repository<Coupon> repository)
|
||||||
|
|
||||||
private LazyLoader LazyLoader;
|
|
||||||
private AddCouponModal AddCouponModal;
|
|
||||||
|
|
||||||
private Task Load(LazyLoader _)
|
|
||||||
{
|
{
|
||||||
AllCoupons = CouponRepository
|
return repository
|
||||||
.Get()
|
.Get()
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task Validate(Coupon coupon)
|
||||||
|
{
|
||||||
|
if (CouponRepository.Get().Any(x => x.Code == coupon.Code && x.Id != coupon.Id))
|
||||||
|
throw new DisplayException("A coupon with that code does already exist");
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Remove(Coupon coupon)
|
|
||||||
{
|
|
||||||
if (CouponUseRepository.Get().Any(x => x.Coupon.Id == coupon.Id))
|
|
||||||
throw new DisplayException("The coupon has been used so it cannot be deleted");
|
|
||||||
|
|
||||||
CouponRepository.Delete(coupon);
|
|
||||||
|
|
||||||
await ToastService.Success("Successfully deleted coupon");
|
|
||||||
await LazyLoader.Reload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,41 @@
|
|||||||
@page "/admin/store/gifts"
|
@page "/admin/store/gifts"
|
||||||
|
|
||||||
<AdminStoreNavigation Index="2" />
|
@using Moonlight.App.Database.Entities.Store
|
||||||
|
@using Moonlight.App.Models.Forms.Admin.Store
|
||||||
|
@using Moonlight.App.Repositories
|
||||||
|
@using BlazorTable
|
||||||
|
|
||||||
|
@inject Repository<GiftCode> GiftCodeRepository
|
||||||
|
|
||||||
|
<AdminStoreNavigation Index="2"/>
|
||||||
|
|
||||||
|
<div class="mt-5">
|
||||||
|
<AutoCrud TItem="GiftCode"
|
||||||
|
TCreateForm="AddGiftCodeForm"
|
||||||
|
TUpdateForm="EditGiftCodeForm"
|
||||||
|
Title="Manage gift codes"
|
||||||
|
Load="LoadData"
|
||||||
|
ValidateAdd="Validate">
|
||||||
|
<Column TableItem="GiftCode" Field="@(x => x.Code)" Title="Code" Sortable="false" Filterable="true" />
|
||||||
|
<Column TableItem="GiftCode" Field="@(x => x.Amount)" Title="Amount" Sortable="true" Filterable="true" />
|
||||||
|
<Column TableItem="GiftCode" Field="@(x => x.Value)" Title="Value" Sortable="true" Filterable="true" />
|
||||||
|
</AutoCrud>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private GiftCode[] LoadData(Repository<GiftCode> repository)
|
||||||
|
{
|
||||||
|
return repository
|
||||||
|
.Get()
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task Validate(GiftCode giftCode)
|
||||||
|
{
|
||||||
|
if (GiftCodeRepository.Get().Any(x => x.Code == giftCode.Code && x.Id != giftCode.Id))
|
||||||
|
throw new DisplayException("A gift code with that code does already exist");
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user