Compare commits

...

2 Commits

Author SHA1 Message Date
Amir Hossein Khademi f883451697 feat : add ver 0.4.3.12 , improve ui 2024-02-09 22:40:13 +03:30
Amir Hossein Khademi ed513f93bc feat : add shipping methods CRUD
create shipping page and action dialog , complete shipping CRUD
2024-02-09 21:43:16 +03:30
14 changed files with 582 additions and 28 deletions

View File

@ -41,6 +41,17 @@
Icon="@Icons.Material.Outlined.AccountBalance">پرداختـــ ها</MudNavLink>
</MudNavGroup>
<MudNavGroup Title="انبارداری" Expanded="false"
Icon="@Icons.Material.Outlined.Inventory">
<MudNavLink Href="inveroty"
Icon="@Icons.Material.Outlined.Inventory2">انبار</MudNavLink>
<MudNavLink Href="inventory/shipping"
Icon="@Icons.Material.Outlined.AirportShuttle">روش های ارسال</MudNavLink>
</MudNavGroup>
<MudNavGroup Title="باشگاه مشتریانـــ" Expanded="false"
Icon="@Icons.Material.Outlined.AccountBalance">

View File

@ -31,7 +31,7 @@
</MudItem>
<MudItem sm="8">
<MudTextField Disabled="@ViewModel.PageDto.IsInfinity" @bind-Value="@ViewModel.PageDto.Count" T="int" Label="تعداد قابل استفاده" Variant="Variant.Outlined" />
<MudTextField Disabled="@ViewModel.PageDto.IsInfinity" Format="N0" @bind-Value="@ViewModel.PageDto.Count" T="int" Label="تعداد قابل استفاده" Variant="Variant.Outlined" />
</MudItem>
<MudItem sm="4">
@ -47,21 +47,21 @@
</MudItem>
<MudItem md="4">
<MudTextField Disabled="@ViewModel.IsPercentType.Not()" @bind-Value="@ViewModel.PageDto.DiscountPercent" T="int" Label="درصد تخفیف" Variant="Variant.Outlined" />
<MudTextField Disabled="@ViewModel.IsPercentType.Not()" Format="N0" @bind-Value="@ViewModel.PageDto.DiscountPercent" T="int" Label="درصد تخفیف" Variant="Variant.Outlined" />
</MudItem>
<MudItem md="4">
<MudTextField Disabled="@ViewModel.IsAmountType.Not()" @bind-Value="@ViewModel.PageDto.DiscountAmount" T="long" Label="مبلغ تخفیفــ" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
<MudTextField Disabled="@ViewModel.IsAmountType.Not()" Format="N0" @bind-Value="@ViewModel.PageDto.DiscountAmount" T="long" Label="مبلغ تخفیفــ" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
</MudItem>
<MudItem md="6">
<MudTextField @bind-Value="@ViewModel.PageDto.PriceFloor" T="long" Label="کف قیمت برای تخفیف" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
<MudTextField @bind-Value="@ViewModel.PageDto.PriceFloor" Format="N0" T="long" Label="کف قیمت برای تخفیف" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
</MudItem>
<MudItem md="6">
<MudTextField @bind-Value="@ViewModel.PageDto.PriceCeiling" T="long" Label="سقف قیمت برای تخفیف" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
<MudTextField @bind-Value="@ViewModel.PageDto.PriceCeiling" Format="N0" T="long" Label="سقف قیمت برای تخفیف" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
</MudItem>
<MudItem sm="6">

View File

@ -74,16 +74,16 @@
</MudAutocomplete>
</MudItem>
<MudItem lg="4" md="6">
<MudTextField @bind-Value="@ViewModel.PageDto.Cost" T="double" Label="قیمت محصول" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
<MudTextField @bind-Value="@ViewModel.PageDto.Cost" T="double" Label="قیمت محصول" Adornment="Adornment.End" Format="N0" AdornmentText="ریالــ" Variant="Variant.Outlined" />
</MudItem>
<MudItem lg="4" md="6">
<MudTextField @bind-Value="@ViewModel.PageDto.PackingCost" T="double" Label="مبلغ بسته بندی" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
<MudTextField @bind-Value="@ViewModel.PageDto.PackingCost" T="double" Label="مبلغ بسته بندی" Format="N0" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
</MudItem>
<MudItem lg="4" md="6">
<MudTextField @bind-Value="@ViewModel.PageDto.Stock" T="int" Label="موجودی انبار" Variant="Variant.Outlined" />
<MudTextField @bind-Value="@ViewModel.PageDto.Stock" T="int" Format="N0" Label="موجودی انبار" Variant="Variant.Outlined" />
</MudItem>
<MudItem lg="4" md="6">
<MudTextField @bind-Value="@ViewModel.PageDto.MaxOrderCount" T="int" Label="بیشترین خرید" Variant="Variant.Outlined" />
<MudTextField @bind-Value="@ViewModel.PageDto.MaxOrderCount" T="int" Format="N0" Label="بیشترین خرید" Variant="Variant.Outlined" />
</MudItem>
<MudItem lg="4" md="6">
<MudTextField @bind-Value="@ViewModel.PageDto.Warranty" T="string" Label="گارانتی" Variant="Variant.Outlined" />
@ -282,11 +282,11 @@
</MudItem>
<MudItem md="4">
<MudTextField Disabled="@ViewModel.IsPercentType.Not()" @bind-Value="@ViewModel.Discount.DiscountPercent" T="int" Label="درصد تخفیف" Variant="Variant.Outlined" />
<MudTextField Disabled="@ViewModel.IsPercentType.Not()" @bind-Value="@ViewModel.Discount.DiscountPercent" Format="N0" T="int" Label="درصد تخفیف" Variant="Variant.Outlined" />
</MudItem>
<MudItem md="4">
<MudTextField Disabled="@ViewModel.IsAmountType.Not()" @bind-Value="@ViewModel.Discount.DiscountAmount" T="long" Label="مبلغ تخفیفــ" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
<MudTextField Disabled="@ViewModel.IsAmountType.Not()" @bind-Value="@ViewModel.Discount.DiscountAmount" Format="N0" T="long" Label="مبلغ تخفیفــ" Adornment="Adornment.End" AdornmentText="ریالــ" Variant="Variant.Outlined" />
</MudItem>

View File

@ -0,0 +1,90 @@
@using NetinaShop.Domain.Entities.Users
@inject ISnackbar Snackbar
@inject IRestWrapper RestWrapper
@inject IUserUtility UserUtility
@inject IDialogService DialogService
<MudDialog DisableSidePadding="true" class="mx-auto">
<DialogContent>
<MudContainer class="max-h-[30rem]" Style="overflow-y: scroll">
<MudStack>
<MudDivider class="-mt-3" />
<MudStack Spacing="0">
<MudText Typo="Typo.h6"><b>اطلاعات کلی</b></MudText>
<MudText Typo="Typo.caption">اطلاعات کلی روش ارسال را به دقت وارد کنید</MudText>
</MudStack>
<MudGrid>
<MudItem sm="12" md="6">
<MudTextField T="string" Label="نام" @bind-Value="@ViewModel.PageDto.Name" Variant="Variant.Outlined"></MudTextField>
</MudItem>
<MudItem sm="12" md="6">
<MudTextField T="string" Label="نام انبار" @bind-Value="@ViewModel.PageDto.WarehouseName" Variant="Variant.Outlined"></MudTextField>
</MudItem>
<MudItem sm="12" md="6">
<MudSelect T="bool" @bind-Value="@ViewModel.PageDto.IsExpressShipping" Label="ایا ارسال سریع میباشد ؟" ToStringFunc="b=>b.ToPersianString()" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomCenter">
<MudSelectItem T="bool" Value="false" />
<MudSelectItem T="bool" Value="true" />
</MudSelect>
</MudItem>
<MudItem sm="12" md="6">
<MudTextField T="double" Label="هزینه ارسال" Adornment="Adornment.End" Format="N0" AdornmentText="ریالــ" @bind-Value="@ViewModel.PageDto.DeliveryCost" Variant="Variant.Outlined"></MudTextField>
</MudItem>
<MudItem sm="12" md="6">
<MudSelect T="bool" @bind-Value="@ViewModel.PageDto.IsOriginalWarehouse" Label="ایا ارسال از انبار اصلی میباشد ؟" ToStringFunc="b=>b.ToPersianString()" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomCenter">
<MudSelectItem T="bool" Value="false" />
<MudSelectItem T="bool" Value="true" />
</MudSelect>
</MudItem>
</MudGrid>
</MudStack>
</MudContainer>
</DialogContent>
<DialogActions>
<MudStack Row="true" class="w-full mx-4 mb-2">
@if (ViewModel.IsEditing)
{
<BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
Icon="@Icons.Material.Outlined.Check"
Variant="Variant.Filled" Color="Color.Success"
Content="ثبت ویرایش" OnClickCallback="@ViewModel.SubmitEditAsync" />
}
else
{
<BaseButtonUi class="w-64 rounded-md" IsProcessing="@ViewModel.IsProcessing"
Icon="@Icons.Material.Outlined.Check"
Variant="Variant.Filled" Color="Color.Success"
Content="تایید" OnClickCallback="@ViewModel.SubmitCreateAsync" />
}
<MudSpacer />
<MudButton Variant="Variant.Outlined" Size="Size.Large" Color="Color.Error" OnClick="@ViewModel.Cancel">بستن</MudButton>
</MudStack>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
MudDialogInstance MudDialog { get; set; }
[Parameter]
public ShippingSDto? Shipping { get; set; }
public ShippingActionDialogBoxViewModel ViewModel { get; set; }
protected override async Task OnInitializedAsync()
{
if (Shipping == null)
ViewModel = new ShippingActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog);
else
ViewModel = new ShippingActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog, Shipping);
await ViewModel.InitializeAsync();
await base.OnInitializedAsync();
}
}

View File

@ -0,0 +1,130 @@
using Mapster;
using NetinaShop.Domain.Entities.Warehouses;
namespace NetinaShop.AdminPanel.PWA.Dialogs;
public class ShippingActionDialogBoxViewModel : BaseViewModel<ShippingSDto>
{
private readonly ISnackbar _snackbar;
private readonly IRestWrapper _restWrapper;
private readonly IUserUtility _userUtility;
private readonly IDialogService _dialogService;
private readonly MudDialogInstance _mudDialog;
public ShippingActionDialogBoxViewModel(ISnackbar snackbar,
IRestWrapper restWrapper,
IUserUtility userUtility,
IDialogService dialogService,
MudDialogInstance mudDialog)
{
_snackbar = snackbar;
_restWrapper = restWrapper;
_userUtility = userUtility;
_dialogService = dialogService;
_mudDialog = mudDialog;
}
public ShippingActionDialogBoxViewModel(ISnackbar snackbar,
IRestWrapper restWrapper,
IUserUtility userUtility,
IDialogService dialogService,
MudDialogInstance mudDialog,
ShippingSDto shipping)
{
_snackbar = snackbar;
_restWrapper = restWrapper;
_userUtility = userUtility;
_dialogService = dialogService;
_mudDialog = mudDialog;
PageDto = shipping;
IsEditing = true;
}
public bool IsEditing = false;
public void Cancel() => _mudDialog.Cancel();
public async Task SubmitEditAsync()
{
try
{
IsProcessing = true;
if (PageDto.Id == default)
throw new Exception("Id is null !");
var token = await _userUtility.GetBearerTokenAsync();
if (token == null)
throw new Exception("Token is null");
if (PageDto.Name.IsNullOrEmpty())
throw new Exception("نام را وارد کنید");
if (PageDto.WarehouseName.IsNullOrEmpty())
throw new Exception("نام انبار را وارد کنید");
var request = PageDto.Adapt<UpdateShippingCommand>();
await _restWrapper.CrudApiRest<Shipping, Guid>(Address.ShippingController).Update<UpdateShippingCommand>(request, token);
_snackbar.Add($"ویرایش {PageDto.Name} با موفقیت انجام شد", Severity.Success);
_mudDialog.Close(DialogResult.Ok(true));
}
catch (ApiException ex)
{
var exe = await ex.GetContentAsAsync<ApiResult>();
if (exe != null)
_snackbar.Add(exe.Message, Severity.Error);
_snackbar.Add(ex.Content, Severity.Error);
_mudDialog.Cancel();
}
catch (Exception e)
{
_snackbar.Add(e.Message, Severity.Error);
_mudDialog.Cancel();
}
finally
{
IsProcessing = false;
}
}
public async Task SubmitCreateAsync()
{
try
{
IsProcessing = true;
var token = await _userUtility.GetBearerTokenAsync();
if (token == null)
throw new Exception("Token is null");
if (PageDto.Name.IsNullOrEmpty())
throw new Exception("نام را وارد کنید");
if (PageDto.WarehouseName.IsNullOrEmpty())
throw new Exception("نام انبار را وارد کنید");
var request = PageDto.Adapt<CreateShippingCommand>();
await _restWrapper.CrudApiRest<Shipping, Guid>(Address.ShippingController).Create<CreateShippingCommand>(request, token);
_snackbar.Add($"ساخت {PageDto.Name} با موفقیت انجام شد", Severity.Success);
_mudDialog.Close(DialogResult.Ok(true));
}
catch (ApiException ex)
{
var exe = await ex.GetContentAsAsync<ApiResult>();
if (exe != null)
_snackbar.Add(exe.Message, Severity.Error);
_snackbar.Add(ex.Content, Severity.Error);
_mudDialog.Cancel();
}
catch (Exception e)
{
_snackbar.Add(e.Message, Severity.Error);
_mudDialog.Cancel();
}
finally
{
IsProcessing = false;
}
}
}

View File

@ -18,4 +18,5 @@ public static class Address
public static string BlogCategoryController => $"{BaseAddress}/blog/category";
public static string DiscountController => $"{BaseAddress}/discount";
public static string RoleController => $"{BaseAddress}/user/role";
public static string ShippingController => $"{BaseAddress}/warehouse/shipping";
}

View File

@ -5,8 +5,8 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<AssemblyVersion>0.2.5.11</AssemblyVersion>
<FileVersion>0.2.5.11</FileVersion>
<AssemblyVersion>0.4.3.12</AssemblyVersion>
<FileVersion>0.4.3.12</FileVersion>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">

View File

@ -35,12 +35,44 @@
OnAdornmentClick="@ViewModel.SearchAsync"></MudTextField>
</ToolBarContent>
<Columns>
<PropertyColumn Title="کد تخفیفــ" Property="arg => arg.Code" />
<PropertyColumn Title="تعداد" Property="arg => arg.Count" />
<PropertyColumn Title="تاریخ شروع" Property="arg => arg.StartDate" />
<PropertyColumn Title="تاریخ انقضا" Property="arg => arg.ExpireDate" />
<PropertyColumn Title="پیشنهاد ویژه" Property="arg => arg.IsSpecialOffer" />
<PropertyColumn Title="تعداد استفاده شده" Property="arg => arg.UseCount" />
<TemplateColumn T="DiscountSDto" Title="کد تخفیفــ">
<CellTemplate>
@if (context.Item.HasCode)
{
<p>@context.Item.Code</p>
}
else
{
<p>بدون کد</p>
}
</CellTemplate>
</TemplateColumn>
<TemplateColumn T="DiscountSDto" Title="تاریخ شروع">
<CellTemplate>
<p>@context.Item.StartDate.ToPersianDateTime().ToLongDateString()</p>
</CellTemplate>
</TemplateColumn>
<TemplateColumn T="DiscountSDto" Title="تاریخ انقضا">
<CellTemplate>
<p>@context.Item.ExpireDate.ToPersianDateTime().ToLongDateString()</p>
</CellTemplate>
</TemplateColumn>
<TemplateColumn T="DiscountSDto" Title="تعداد قابل استفاده">
<CellTemplate>
@if (context.Item.IsInfinity)
{
<p>--</p>
}
else
{
<p>@context.Item.Count</p>
}
</CellTemplate>
</TemplateColumn>
<TemplateColumn CellClass="d-flex justify-end">
<CellTemplate>
<MudStack Row="true">

View File

@ -1,4 +1,5 @@
using NetinaShop.Domain.Entities.Discounts;
using MudBlazor;
using NetinaShop.Domain.Entities.Discounts;
namespace NetinaShop.AdminPanel.PWA.Pages;
@ -103,7 +104,12 @@ public class DiscountPageViewModel : BaseViewModel<ObservableCollection<Discount
public async Task AddAsync()
{
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
await _dialogService.ShowAsync<DiscountActionDialogBox>("افزودن بلاگ جدید", maxWidth);
var dialogResult = await _dialogService.ShowAsync<DiscountActionDialogBox>("افزودن تخفیف جدید", maxWidth);
var result = await dialogResult.Result;
if (!result.Canceled && result.Data is bool and true)
{
await InitializeAsync();
}
}
public async Task EditAsync(DiscountSDto discount)
@ -111,7 +117,12 @@ public class DiscountPageViewModel : BaseViewModel<ObservableCollection<Discount
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
var parameters = new DialogParameters<DiscountActionDialogBox>();
parameters.Add(x => x.Discount, discount);
await _dialogService.ShowAsync<DiscountActionDialogBox>($"ویرایش تخفیف {discount.Code}", parameters, maxWidth);
var dialogResult= await _dialogService.ShowAsync<DiscountActionDialogBox>($"ویرایش تخفیف {discount.Code}", parameters, maxWidth);
var result = await dialogResult.Result;
if (!result.Canceled && result.Data is bool and true)
{
await InitializeAsync();
}
}
public async Task DeleteAsync(Guid selectedDiscountId)
@ -119,7 +130,7 @@ public class DiscountPageViewModel : BaseViewModel<ObservableCollection<Discount
var options = new DialogOptions { CloseOnEscapeKey = true };
var parameters = new DialogParameters<QuestionDialog>();
parameters.Add(x => x.ContentText, "آیا از حذف تخفیف اطمینان دارید ?");
var dialogReference = await _dialogService.ShowAsync<QuestionDialog>("حذف بلاگ", parameters, options);
var dialogReference = await _dialogService.ShowAsync<QuestionDialog>("حذف تخفیف", parameters, options);
var result = await dialogReference.Result;
if (!result.Canceled)
{
@ -131,7 +142,7 @@ public class DiscountPageViewModel : BaseViewModel<ObservableCollection<Discount
var token = await _userUtility.GetBearerTokenAsync();
if (token == null)
throw new Exception("Token is null");
await _restWrapper.CrudDtoApiRest<Discount, DiscountSDto, Guid>(Address.BlogController)
await _restWrapper.CrudDtoApiRest<Discount, DiscountSDto, Guid>(Address.DiscountController)
.Delete(selectedDiscountId, token);
_snackbar.Add("حذف تخفیف با موفقیت انجام شد", Severity.Success);

View File

@ -78,7 +78,11 @@
}
</CellTemplate>
</TemplateColumn>
<PropertyColumn Title="قیمتــ" Property="arg => arg.Cost"/>
<TemplateColumn T="ProductSDto" Title="قیمتــ">
<CellTemplate>
<p>@context.Item.Cost.ToString("N0") ریالــ</p>
</CellTemplate>
</TemplateColumn>
<TemplateColumn CellClass="d-flex justify-end">
<CellTemplate>
<MudStack Row="true">

View File

@ -1,4 +1,6 @@
namespace NetinaShop.AdminPanel.PWA.Pages;
using MudBlazor;
namespace NetinaShop.AdminPanel.PWA.Pages;
public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductSDto>>
{
@ -95,7 +97,12 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
public async Task AddProductClicked()
{
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
await _dialogService.ShowAsync<ProductActionDialogBox>("افزودن محصول جدید", maxWidth);
var dialogResult = await _dialogService.ShowAsync<ProductActionDialogBox>("افزودن محصول جدید", maxWidth);
var result = await dialogResult.Result;
if (!result.Canceled && result.Data is bool and true)
{
await InitializeAsync();
}
}
public async Task EditProductClicked(ProductSDto product)
@ -103,7 +110,12 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
var parameters = new DialogParameters<ProductActionDialogBox>();
parameters.Add(x => x.Product, product);
await _dialogService.ShowAsync<ProductActionDialogBox>($"ویرایش محصول {product.PersianName}", parameters, maxWidth);
var dialogResult = await _dialogService.ShowAsync<ProductActionDialogBox>($"ویرایش محصول {product.PersianName}", parameters, maxWidth);
var result = await dialogResult.Result;
if (!result.Canceled && result.Data is bool and true)
{
await InitializeAsync();
}
}
public async Task DeleteProductAsync(Guid selectedCategoryId)
@ -124,6 +136,7 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
await _restWrapper.CrudDtoApiRest<Product, ProductSDto, Guid>(Address.ProductController)
.Delete(selectedCategoryId, token);
_snackbar.Add("حذف محصول با موفقیت انجام شد", Severity.Success);
await InitializeAsync();
}
catch (ApiException ex)

View File

@ -0,0 +1,98 @@
@page "/inventory/shipping"
@attribute [Microsoft.AspNetCore.Authorization.Authorize]
@inject IDialogService DialogService
@inject NavigationManager NavigationManager
@inject ISnackbar Snackbar
@inject IUserUtility UserUtility
@inject IRestWrapper RestWrapper
<MudStack class="w-full p-8 h-screen bg-[--mud-palette-background-grey]">
<MudGrid>
<MudItem xs="12">
<MudStack Row="true" class="mb-5">
<MudText Typo="Typo.h4">روش های ارسال سفارش</MudText>
<MudSpacer />
<MudButton Variant="Variant.Filled"
DisableElevation="true"
StartIcon="@Icons.Material.Outlined.Add"
Color="Color.Secondary"
OnClick="@ViewModel.AddClicked"
class="my-auto">افزودن روش جدید</MudButton>
</MudStack>
<MudPaper>
<MudDataGrid FixedFooter="true" FixedHeader="true" Striped="true"
T="ShippingSDto" Items="@ViewModel.PageDto" CurrentPage="@ViewModel.CurrentPage"
RowsPerPage="20" Filterable="false" Loading="@ViewModel.IsProcessing"
SortMode="@SortMode.None" Groupable="false">
<Columns>
<PropertyColumn Title="نام" Property="arg => arg.Name" />
<PropertyColumn Title="نام انبار ارسال" Property="arg => arg.WarehouseName" />
<PropertyColumn Title="هرینه ارسال" Property="arg => arg.DeliveryCost" />
<TemplateColumn T="ShippingSDto" Title="ارسال فوری می باشد">
<CellTemplate>
@if (@context.Item.IsExpressShipping)
{
<p>بلی</p>
}
else
{
<p>خیر</p>
}
</CellTemplate>
</TemplateColumn>
<TemplateColumn T="ShippingSDto" Title="ارسال از انبار اصلی">
<CellTemplate>
@if (@context.Item.IsOriginalWarehouse)
{
<p>بلی</p>
}
else
{
<p>خیر</p>
}
</CellTemplate>
</TemplateColumn>
<TemplateColumn CellClass="d-flex justify-end">
<CellTemplate>
<MudStack Row="true">
<MudIconButton Icon="@Icons.Material.Filled.Edit"
Size="@Size.Small"
Variant="@Variant.Outlined"
Color="@Color.Info"
OnClick="async()=>await ViewModel.EditClicked(context.Item)" />
<MudIconButton Icon="@Icons.Material.Filled.Delete"
Size="@Size.Small"
Variant="@Variant.Outlined"
OnClick="async () => await ViewModel.DeleteAsync(context.Item.Id)"
Color="@Color.Error" />
</MudStack>
</CellTemplate>
</TemplateColumn>
</Columns>
<PagerContent>
<MudStack Row="true" class="w-full">
<MudPagination Rectangular="true" Variant="Variant.Filled" Count="@ViewModel.PageCount"
SelectedChanged="@ViewModel.ChangePageAsync" class="my-4 mx-auto" />
</MudStack>
</PagerContent>
</MudDataGrid>
</MudPaper>
</MudItem>
</MudGrid>
</MudStack>
@code
{
public ShippingPageViewModel ViewModel { get; set; }
protected override async Task OnInitializedAsync()
{
ViewModel = new ShippingPageViewModel(NavigationManager, Snackbar, UserUtility, RestWrapper, DialogService);
await ViewModel.InitializeAsync();
await base.OnInitializedAsync();
}
}

View File

@ -0,0 +1,161 @@
using NetinaShop.Domain.Entities.Warehouses;
namespace NetinaShop.AdminPanel.PWA.Pages;
public class ShippingPageViewModel : BaseViewModel<ObservableCollection<ShippingSDto>>
{
private readonly NavigationManager _navigationManager;
private readonly ISnackbar _snackbar;
private readonly IUserUtility _userUtility;
private readonly IDialogService _dialogService;
private readonly IRestWrapper _restWrapper;
public string Search = string.Empty;
public int CurrentPage = 0;
public int PageCount = 1;
public ShippingPageViewModel(NavigationManager navigationManager, ISnackbar snackbar, IUserUtility userUtility, IRestWrapper restWrapper, IDialogService dialogService)
{
_navigationManager = navigationManager;
_snackbar = snackbar;
_userUtility = userUtility;
_restWrapper = restWrapper;
_dialogService = dialogService;
}
public override async Task InitializeAsync()
{
try
{
var token = await _userUtility.GetBearerTokenAsync();
if (token == null)
throw new Exception("Token is null");
IsProcessing = true;
PageDto.Clear();
var dto = await _restWrapper.CrudDtoApiRest<Shipping, ShippingSDto, Guid>(Address.ShippingController)
.ReadAll(CurrentPage, token);
dto.ForEach(d => PageDto.Add(d));
if (PageDto.Count == 20)
PageCount = 2;
}
catch (ApiException ex)
{
var exe = await ex.GetContentAsAsync<ApiResult>();
_snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
}
catch (Exception e)
{
_snackbar.Add(e.Message, Severity.Error);
}
finally
{
IsProcessing = false;
}
await base.InitializeAsync();
}
public async Task ChangePageAsync(int page)
{
CurrentPage = page - 1;
if (CurrentPage > PageCount - 2)
{
try
{
IsProcessing = true;
var token = await _userUtility.GetBearerTokenAsync();
if (token == null)
throw new Exception("Token is null");
List<ShippingSDto> dto = new List<ShippingSDto>();
dto = await _restWrapper.CrudDtoApiRest<Shipping, ShippingSDto, Guid>(Address.ShippingController)
.ReadAll(CurrentPage,token);
dto.ForEach(d => PageDto.Add(d));
if (PageDto.Count % 20 == 0)
PageCount = CurrentPage + 2;
}
catch (ApiException ex)
{
var exe = await ex.GetContentAsAsync<ApiResult>();
_snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
}
catch (Exception e)
{
_snackbar.Add(e.Message, Severity.Error);
}
finally
{
IsProcessing = false;
}
}
}
public async Task AddClicked()
{
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
var dialogResult = await _dialogService.ShowAsync<ShippingActionDialogBox>("افزودن روش ارسال جدید", maxWidth);
var result = await dialogResult.Result;
if (!result.Canceled && result.Data is bool and true)
{
await InitializeAsync();
}
}
public async Task EditClicked(ShippingSDto shipping)
{
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
var parameters = new DialogParameters<ShippingActionDialogBox>();
parameters.Add(x => x.Shipping, shipping);
var dialogResult = await _dialogService.ShowAsync<ShippingActionDialogBox>($"ویرایش روش ارسال {shipping.Name}", parameters, maxWidth);
var result = await dialogResult.Result;
if (!result.Canceled && result.Data is bool and true)
{
await InitializeAsync();
}
}
public async Task DeleteAsync(Guid selectedCategoryId)
{
var options = new DialogOptions { CloseOnEscapeKey = true };
var parameters = new DialogParameters<QuestionDialog>();
parameters.Add(x => x.ContentText, "آیا از حذف روش ارسال اطمینان دارید ?");
var dialogReference = await _dialogService.ShowAsync<QuestionDialog>("حذف روش ارسال", parameters, options);
var result = await dialogReference.Result;
if (!result.Canceled)
{
try
{
IsProcessing = true;
var token = await _userUtility.GetBearerTokenAsync();
if (token == null)
throw new Exception("Token is null");
await _restWrapper.CrudDtoApiRest<Shipping, ShippingSDto, Guid>(Address.ShippingController)
.Delete(selectedCategoryId, token);
_snackbar.Add("حذف روش ارسال با موفقیت انجام شد", Severity.Success);
await InitializeAsync();
}
catch (ApiException ex)
{
var exe = await ex.GetContentAsAsync<ApiResult>();
_snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
}
catch (Exception e)
{
_snackbar.Add(e.Message, Severity.Error);
}
finally
{
IsProcessing = false;
}
}
}
}

View File

@ -30,6 +30,9 @@ public interface ICrudDtoApiRest<T, TDto, in TKey> where T : class where TDto :
[Get("")]
Task<List<TDto>> ReadAll([Query]int page);
[Get("")]
Task<List<TDto>> ReadAll([Query] int page, [Header("Authorization")] string authorization);
[Get("")]
Task<List<TDto>> ReadAll();