diff --git a/NetinaShop.AdminPanel.PWA/Components/Originals/SideBarUi.razor b/NetinaShop.AdminPanel.PWA/Components/Originals/SideBarUi.razor index 3416b14..2282f05 100644 --- a/NetinaShop.AdminPanel.PWA/Components/Originals/SideBarUi.razor +++ b/NetinaShop.AdminPanel.PWA/Components/Originals/SideBarUi.razor @@ -41,6 +41,17 @@ Icon="@Icons.Material.Outlined.AccountBalance">پرداختـــ ها + + + + انبار + + روش های ارسال + + diff --git a/NetinaShop.AdminPanel.PWA/Dialogs/ShippingActionDialogBox.razor b/NetinaShop.AdminPanel.PWA/Dialogs/ShippingActionDialogBox.razor new file mode 100644 index 0000000..7f49522 --- /dev/null +++ b/NetinaShop.AdminPanel.PWA/Dialogs/ShippingActionDialogBox.razor @@ -0,0 +1,90 @@ +@using NetinaShop.Domain.Entities.Users + +@inject ISnackbar Snackbar +@inject IRestWrapper RestWrapper +@inject IUserUtility UserUtility +@inject IDialogService DialogService + + + + + + + + + اطلاعات کلی + اطلاعات کلی روش ارسال را به دقت وارد کنید + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @if (ViewModel.IsEditing) + { + + } + else + { + + } + + بستن + + + +@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(); + } +} diff --git a/NetinaShop.AdminPanel.PWA/Dialogs/ShippingActionDialogBox.razor.cs b/NetinaShop.AdminPanel.PWA/Dialogs/ShippingActionDialogBox.razor.cs new file mode 100644 index 0000000..7609899 --- /dev/null +++ b/NetinaShop.AdminPanel.PWA/Dialogs/ShippingActionDialogBox.razor.cs @@ -0,0 +1,130 @@ +using Mapster; +using NetinaShop.Domain.Entities.Warehouses; + +namespace NetinaShop.AdminPanel.PWA.Dialogs; + +public class ShippingActionDialogBoxViewModel : BaseViewModel +{ + 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(); + await _restWrapper.CrudApiRest(Address.ShippingController).Update(request, token); + _snackbar.Add($"ویرایش {PageDto.Name} با موفقیت انجام شد", Severity.Success); + _mudDialog.Close(DialogResult.Ok(true)); + } + catch (ApiException ex) + { + var exe = await ex.GetContentAsAsync(); + 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(); + await _restWrapper.CrudApiRest(Address.ShippingController).Create(request, token); + _snackbar.Add($"ساخت {PageDto.Name} با موفقیت انجام شد", Severity.Success); + _mudDialog.Close(DialogResult.Ok(true)); + } + catch (ApiException ex) + { + var exe = await ex.GetContentAsAsync(); + 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; + } + } +} \ No newline at end of file diff --git a/NetinaShop.AdminPanel.PWA/Models/Address.cs b/NetinaShop.AdminPanel.PWA/Models/Address.cs index b382424..2c4bd73 100644 --- a/NetinaShop.AdminPanel.PWA/Models/Address.cs +++ b/NetinaShop.AdminPanel.PWA/Models/Address.cs @@ -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"; } \ No newline at end of file diff --git a/NetinaShop.AdminPanel.PWA/Pages/ShippingPage.razor b/NetinaShop.AdminPanel.PWA/Pages/ShippingPage.razor new file mode 100644 index 0000000..cc6286c --- /dev/null +++ b/NetinaShop.AdminPanel.PWA/Pages/ShippingPage.razor @@ -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 + + + + + + روش های ارسال سفارش + + افزودن روش جدید + + + + + + + + + + @if (@context.Item.IsExpressShipping) + { +

بلی

+ } + else + { +

خیر

+ + } +
+
+ + + @if (@context.Item.IsOriginalWarehouse) + { +

بلی

+ } + else + { +

خیر

+ + } +
+
+ + + + + + + + +
+ + + + + + + +
+
+
+
+
+ +@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(); + } +} diff --git a/NetinaShop.AdminPanel.PWA/Pages/ShippingPage.razor.cs b/NetinaShop.AdminPanel.PWA/Pages/ShippingPage.razor.cs new file mode 100644 index 0000000..9ca1bc9 --- /dev/null +++ b/NetinaShop.AdminPanel.PWA/Pages/ShippingPage.razor.cs @@ -0,0 +1,161 @@ +using NetinaShop.Domain.Entities.Warehouses; + +namespace NetinaShop.AdminPanel.PWA.Pages; + +public class ShippingPageViewModel : BaseViewModel> +{ + 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(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(); + _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 dto = new List(); + dto = await _restWrapper.CrudDtoApiRest(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(); + _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("افزودن روش ارسال جدید", 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(); + parameters.Add(x => x.Shipping, shipping); + var dialogResult = await _dialogService.ShowAsync($"ویرایش روش ارسال {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(); + parameters.Add(x => x.ContentText, "آیا از حذف روش ارسال اطمینان دارید ?"); + var dialogReference = await _dialogService.ShowAsync("حذف روش ارسال", 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(Address.ShippingController) + .Delete(selectedCategoryId, token); + _snackbar.Add("حذف روش ارسال با موفقیت انجام شد", Severity.Success); + await InitializeAsync(); + + } + catch (ApiException ex) + { + var exe = await ex.GetContentAsAsync(); + _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); + } + catch (Exception e) + { + _snackbar.Add(e.Message, Severity.Error); + } + finally + { + + IsProcessing = false; + } + } + } +} \ No newline at end of file diff --git a/NetinaShop.AdminPanel.PWA/Services/RestServices/ICrudApiRest.cs b/NetinaShop.AdminPanel.PWA/Services/RestServices/ICrudApiRest.cs index f6e059b..9788f99 100644 --- a/NetinaShop.AdminPanel.PWA/Services/RestServices/ICrudApiRest.cs +++ b/NetinaShop.AdminPanel.PWA/Services/RestServices/ICrudApiRest.cs @@ -30,6 +30,9 @@ public interface ICrudDtoApiRest where T : class where TDto : [Get("")] Task> ReadAll([Query]int page); + [Get("")] + Task> ReadAll([Query] int page, [Header("Authorization")] string authorization); + [Get("")] Task> ReadAll();