fix(CancelOrder)
parent
80abffa292
commit
956b0421b2
|
@ -199,6 +199,7 @@
|
|||
<BaseButtonUi class="h-12 w-full rounded-md" IsProcessing="@ViewModel.IsProcessing"
|
||||
Icon="@Icons.Material.Outlined.RemoveCircle"
|
||||
Variant="Variant.Outlined" Color="Color.Error"
|
||||
OnClickCallback="ViewModel.CancelAsync"
|
||||
Content="لغو سفارش" />
|
||||
</MudItem>
|
||||
|
||||
|
|
|
@ -259,4 +259,41 @@ public class OrderActionDialogBoxViewModel : BaseViewModel<OrderLDto>
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CancelAsync()
|
||||
{
|
||||
var reference = await _dialogService.ShowQuestionDialog($"ایا از کنسل کردن سفارش اطمینان دارید ?");
|
||||
var result = await reference.Result;
|
||||
if (!result.Canceled)
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = await _userUtility.GetBearerTokenAsync();
|
||||
if (token == null)
|
||||
throw new Exception("Token is null");
|
||||
IsProcessing = true;
|
||||
|
||||
|
||||
await _restWrapper.OrderRestApi.CancelOrderStepAsync(PageDto.Id, token);
|
||||
_snackbar.Add($"سفارش {PageDto.FactorCode} کنسل شد", Severity.Warning);
|
||||
_mudDialog.Close(true);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
var exe = await ex.GetContentAsAsync<ApiResult>();
|
||||
_snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
|
||||
_mudDialog.Cancel();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_snackbar.Add(e.Message, Severity.Error);
|
||||
_mudDialog.Cancel();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
IsProcessing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
namespace Netina.AdminPanel.PWA.Pages;
|
||||
|
||||
public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductSDto>>
|
||||
public class ProductsPageViewModel(
|
||||
NavigationManager navigationManager,
|
||||
ISnackbar snackbar,
|
||||
IUserUtility userUtility,
|
||||
IRestWrapper restWrapper,
|
||||
IDialogService dialogService,
|
||||
IBrowserViewportService browserViewportService)
|
||||
: BaseViewModel<ObservableCollection<ProductSDto>>(userUtility)
|
||||
{
|
||||
private readonly NavigationManager _navigationManager;
|
||||
private readonly ISnackbar _snackbar;
|
||||
private readonly IUserUtility _userUtility;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IBrowserViewportService _browserViewportService;
|
||||
private readonly IRestWrapper _restWrapper;
|
||||
private readonly NavigationManager _navigationManager = navigationManager;
|
||||
private readonly IUserUtility _userUtility = userUtility;
|
||||
|
||||
public string? Search = string.Empty;
|
||||
public int CurrentPage = 0;
|
||||
|
@ -18,22 +21,6 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
public bool IsXs = false;
|
||||
public bool IsEnable { get; set; } = true;
|
||||
|
||||
public ProductsPageViewModel(NavigationManager navigationManager,
|
||||
ISnackbar snackbar,
|
||||
IUserUtility userUtility,
|
||||
IRestWrapper restWrapper,
|
||||
IDialogService dialogService,
|
||||
IBrowserViewportService browserViewportService) : base(userUtility)
|
||||
{
|
||||
_navigationManager = navigationManager;
|
||||
_snackbar = snackbar;
|
||||
_userUtility = userUtility;
|
||||
_restWrapper = restWrapper;
|
||||
_dialogService = dialogService;
|
||||
_browserViewportService = browserViewportService;
|
||||
|
||||
}
|
||||
|
||||
public override async Task InitializeAsync()
|
||||
{
|
||||
await GetEntitiesAsync();
|
||||
|
@ -50,21 +37,21 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
IsProcessing = true;
|
||||
PageDto.Clear();
|
||||
var search = Search.IsNullOrEmpty() ? null : Search;
|
||||
var dto = await _restWrapper.ProductRestApi.ReadAll(CurrentPage, search, SelectedCategory?.Id, IsEnable);
|
||||
var dto = await restWrapper.ProductRestApi.ReadAll(CurrentPage, search, SelectedCategory?.Id, IsEnable);
|
||||
dto.Products.ForEach(d => PageDto.Add(d));
|
||||
if (PageDto.Count % 20 == 0)
|
||||
PageCount = CurrentPage + 2;
|
||||
TotalItems = dto.Pager.TotalItems;
|
||||
IsXs = (await _browserViewportService.GetCurrentBreakpointAsync()) == Breakpoint.Xs;
|
||||
IsXs = (await browserViewportService.GetCurrentBreakpointAsync()) == Breakpoint.Xs;
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
var exe = await ex.GetContentAsAsync<ApiResult>();
|
||||
_snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
|
||||
snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_snackbar.Add(e.Message, Severity.Error);
|
||||
snackbar.Add(e.Message, Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -82,10 +69,10 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
public async Task AddProductClicked()
|
||||
{
|
||||
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Large, FullWidth = true, DisableBackdropClick = true };
|
||||
var breakPoint = await _browserViewportService.GetCurrentBreakpointAsync();
|
||||
var breakPoint = await browserViewportService.GetCurrentBreakpointAsync();
|
||||
if (breakPoint == Breakpoint.Xs)
|
||||
maxWidth = new DialogOptions { FullScreen = true, CloseButton = true };
|
||||
var dialogResult = 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)
|
||||
{
|
||||
|
@ -97,10 +84,10 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
public async Task AddFastProductClicked()
|
||||
{
|
||||
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Large, FullWidth = true, NoHeader = true, DisableBackdropClick = true, CloseButton = true };
|
||||
var breakPoint = await _browserViewportService.GetCurrentBreakpointAsync();
|
||||
var breakPoint = await browserViewportService.GetCurrentBreakpointAsync();
|
||||
if (breakPoint == Breakpoint.Xs)
|
||||
maxWidth = new DialogOptions { FullScreen = true, NoHeader = true, CloseButton = true };
|
||||
var dialogResult = await _dialogService.ShowAsync<FastProductCreateDialogBox>("افزودن محصول جدید", maxWidth);
|
||||
var dialogResult = await dialogService.ShowAsync<FastProductCreateDialogBox>("افزودن محصول جدید", maxWidth);
|
||||
var result = await dialogResult.Result;
|
||||
if (!result.Canceled && result.Data is bool and true)
|
||||
{
|
||||
|
@ -111,7 +98,7 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
{
|
||||
|
||||
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
|
||||
var dialogResult = await _dialogService.ShowAsync<DigikalaProductActionDialogBox>("افزودن محصول جدید", maxWidth);
|
||||
var dialogResult = await dialogService.ShowAsync<DigikalaProductActionDialogBox>("افزودن محصول جدید", maxWidth);
|
||||
var result = await dialogResult.Result;
|
||||
if (!result.Canceled && result.Data is bool and true)
|
||||
{
|
||||
|
@ -122,12 +109,12 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
public async Task EditProductClicked(ProductSDto product)
|
||||
{
|
||||
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Large, FullWidth = true, DisableBackdropClick = true };
|
||||
var breakPoint = await _browserViewportService.GetCurrentBreakpointAsync();
|
||||
var breakPoint = await browserViewportService.GetCurrentBreakpointAsync();
|
||||
if (breakPoint == Breakpoint.Xs)
|
||||
maxWidth = new DialogOptions { FullScreen = true, CloseButton = true };
|
||||
var parameters = new DialogParameters<ProductActionDialogBox>();
|
||||
parameters.Add(x => x.Product, product);
|
||||
var dialogResult = 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)
|
||||
{
|
||||
|
@ -137,7 +124,7 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
|
||||
public async Task DeleteProductAsync(Guid selectedCategoryId)
|
||||
{
|
||||
var reference = await _dialogService.ShowQuestionDialog($"آیا از حذف محصول اطمینان دارید ?");
|
||||
var reference = await dialogService.ShowQuestionDialog($"آیا از حذف محصول اطمینان دارید ?");
|
||||
var result = await reference.Result;
|
||||
if (!result.Canceled)
|
||||
{
|
||||
|
@ -147,20 +134,20 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
|
||||
IsProcessing = true;
|
||||
var token = await _userUtility.GetBearerTokenAsync();
|
||||
await _restWrapper.CrudDtoApiRest<Product, ProductSDto, Guid>(Address.ProductController)
|
||||
await restWrapper.CrudDtoApiRest<Product, ProductSDto, Guid>(Address.ProductController)
|
||||
.Delete(selectedCategoryId, token);
|
||||
_snackbar.Add("حذف محصول با موفقیت انجام شد", Severity.Success);
|
||||
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);
|
||||
snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_snackbar.Add(e.Message, Severity.Error);
|
||||
snackbar.Add(e.Message, Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -185,22 +172,22 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
try
|
||||
{
|
||||
if (category.IsNullOrEmpty())
|
||||
_productCategories = await _restWrapper.ProductCategoryRestApi.ReadAll(0);
|
||||
_productCategories = await restWrapper.ProductCategoryRestApi.ReadAll(0);
|
||||
else
|
||||
_productCategories = await _restWrapper.ProductCategoryRestApi.ReadAll(category);
|
||||
_productCategories = await restWrapper.ProductCategoryRestApi.ReadAll(category);
|
||||
return _productCategories;
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
var exe = await ex.GetContentAsAsync<ApiResult>();
|
||||
if (exe != null)
|
||||
_snackbar.Add(exe.Message, Severity.Error);
|
||||
_snackbar.Add(ex.Content, Severity.Error);
|
||||
snackbar.Add(exe.Message, Severity.Error);
|
||||
snackbar.Add(ex.Content, Severity.Error);
|
||||
return _productCategories;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_snackbar.Add(e.Message, Severity.Error);
|
||||
snackbar.Add(e.Message, Severity.Error);
|
||||
return _productCategories;
|
||||
}
|
||||
}
|
||||
|
@ -224,16 +211,16 @@ public class ProductsPageViewModel : BaseViewModel<ObservableCollection<ProductS
|
|||
var token = await _userUtility.GetBearerTokenAsync();
|
||||
if (token == null)
|
||||
throw new Exception("Token is null");
|
||||
await _restWrapper.ProductRestApi.ChangeDisplayedAsync(product.Id, product.BeDisplayed, token);
|
||||
await restWrapper.ProductRestApi.ChangeDisplayedAsync(product.Id, product.BeDisplayed, token);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
var exe = await ex.GetContentAsAsync<ApiResult>();
|
||||
_snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
|
||||
snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_snackbar.Add(e.Message, Severity.Error);
|
||||
snackbar.Add(e.Message, Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@ public interface IOrderRestApi
|
|||
|
||||
[Post("/{id}/confirm")]
|
||||
Task<bool> ConfirmOrderStepAsync(Guid id,[Query] OrderStatus nextOrderStatus, [Header("Authorization")] string authorization);
|
||||
|
||||
[Post("/{id}/cancel")]
|
||||
Task<bool> CancelOrderStepAsync(Guid id ,[Header("Authorization")] string authorization);
|
||||
[Post("/{id}/confirm")]
|
||||
Task<bool> ConfirmOrderStepAsync(Guid id, [Query] OrderStatus nextOrderStatus, [Query]string trackingCode, [Header("Authorization")] string authorization);
|
||||
}
|
Loading…
Reference in New Issue