feat : add shipping methods CRUD

create shipping page and action dialog , complete shipping CRUD
release
Amir Hossein Khademi 2024-02-09 21:43:16 +03:30
parent e081a39682
commit ed513f93bc
7 changed files with 494 additions and 0 deletions

View File

@ -41,6 +41,17 @@
Icon="@Icons.Material.Outlined.AccountBalance">پرداختـــ ها</MudNavLink> Icon="@Icons.Material.Outlined.AccountBalance">پرداختـــ ها</MudNavLink>
</MudNavGroup> </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" <MudNavGroup Title="باشگاه مشتریانـــ" Expanded="false"
Icon="@Icons.Material.Outlined.AccountBalance"> Icon="@Icons.Material.Outlined.AccountBalance">

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="هزینه ارسال" @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 BlogCategoryController => $"{BaseAddress}/blog/category";
public static string DiscountController => $"{BaseAddress}/discount"; public static string DiscountController => $"{BaseAddress}/discount";
public static string RoleController => $"{BaseAddress}/user/role"; public static string RoleController => $"{BaseAddress}/user/role";
public static string ShippingController => $"{BaseAddress}/warehouse/shipping";
} }

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("")] [Get("")]
Task<List<TDto>> ReadAll([Query]int page); Task<List<TDto>> ReadAll([Query]int page);
[Get("")]
Task<List<TDto>> ReadAll([Query] int page, [Header("Authorization")] string authorization);
[Get("")] [Get("")]
Task<List<TDto>> ReadAll(); Task<List<TDto>> ReadAll();