diff --git a/NetinaShop.AdminPanel.PWA/Dialogs/BrandActionDialogBox.razor b/NetinaShop.AdminPanel.PWA/Dialogs/BrandActionDialogBox.razor index cd057ac..c3f5878 100644 --- a/NetinaShop.AdminPanel.PWA/Dialogs/BrandActionDialogBox.razor +++ b/NetinaShop.AdminPanel.PWA/Dialogs/BrandActionDialogBox.razor @@ -5,6 +5,7 @@ @inject ISnackbar Snackbar @inject IRestWrapper RestWrapper @inject IUserUtility UserUtility +@inject IDialogService DialogService @@ -34,6 +35,46 @@ + + + + تصاویر برند + می توانید برای برند چند تصویر اپلود کنید + + + + + @foreach (var item in Files) + { +
+ + + + @if (item.IsHeader) + { +

هدر

+ } + @if (item.IsPrimary) + { +

اصلی

+ } +
+ } + +
+
@@ -66,6 +107,7 @@ public BrandSDto? Brand { get; set; } void Cancel() => MudDialog.Cancel(); + public readonly ObservableCollection Files = new ObservableCollection(); private bool _isProcessing = false; private string _persianName = string.Empty; private string _englishName = string.Empty; @@ -74,18 +116,42 @@ private bool _isEditing; private string _pageUrl = string.Empty; - protected override Task OnParametersSetAsync() + protected override async Task OnParametersSetAsync() { if (Brand != null) { _isEditing = true; - _hasSpecialPage = Brand.HasSpecialPage; - _description = Brand.Description; - _englishName = Brand.EnglishName; - _persianName = Brand.PersianName; + try + { + _isProcessing = true; + var response = await RestWrapper.CrudDtoApiRest(Address.BrandController).ReadOne(Brand.Id); + var brandLDto = response; + brandLDto.Files.ForEach(f => Files.Add(f)); + + _hasSpecialPage = brandLDto.HasSpecialPage; + _description = brandLDto.Description; + _englishName = brandLDto.EnglishName; + _persianName = brandLDto.PersianName; + } + catch (ApiException ex) + { + var exe = await ex.GetContentAsAsync(); + 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; + } } - return base.OnParametersSetAsync(); + await base.OnParametersSetAsync(); } private async Task SubmitCreateAsync() @@ -96,7 +162,9 @@ throw new AppException("لطفا نام برند را وارد کنید"); _isProcessing = true; var token = await UserUtility.GetBearerTokenAsync(); - var request = new CreateBrandCommand(_persianName,_englishName, _description, _hasSpecialPage, string.Empty, new List()); + if (token == null) + throw new AppException("Token is null"); + var request = new CreateBrandCommand(_persianName, _englishName, _description, _hasSpecialPage, _pageUrl, Files.ToList()); await RestWrapper.CrudApiRest(Address.BrandController).Create(request, token); MudDialog.Close(DialogResult.Ok(true)); } @@ -125,9 +193,10 @@ if (_englishName.IsNullOrEmpty()) throw new AppException("لطفا نام برند را وارد کنید"); _isProcessing = true; - await Task.Delay(1000); var token = await UserUtility.GetBearerTokenAsync(); - var request = new UpdateBrandCommand(Brand.Id, _persianName,_englishName, _description, _hasSpecialPage, string.Empty , new List()); + if (token == null) + throw new AppException("Token is null"); + var request = new UpdateBrandCommand(Brand.Id, _persianName, _englishName, _description, _hasSpecialPage, _pageUrl, Files.ToList()); await RestWrapper.CrudApiRest(Address.BrandController).Update(request, token); MudDialog.Close(); } @@ -148,4 +217,20 @@ _isProcessing = false; } } + + + public async Task SelectFileAsync() + { + DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true }; + var dialog = await DialogService.ShowAsync("انتخاب عکس برند", maxWidth); + var result = await dialog.Result; + var file = result.Data; + if (file is StorageFileSDto storageFile) + Files.Add(storageFile); + } + + public void RemoveFile(StorageFileSDto file) + { + Files.Remove(file); + } } \ No newline at end of file diff --git a/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor b/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor index 51e7186..ce767dc 100644 --- a/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor +++ b/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor @@ -1,6 +1,7 @@ @inject ISnackbar Snackbar @inject IRestWrapper RestWrapper @inject IUserUtility UserUtility +@inject IDialogService DialogService @@ -23,7 +24,7 @@ @@ -42,6 +43,46 @@ + + + + تصاویر برند + می توانید برای برند چند تصویر اپلود کنید + + + + + @foreach (var item in ViewModel.Files) + { +
+ + + + @if (item.IsHeader) + { +

هدر

+ } + @if (item.IsPrimary) + { +

اصلی

+ } +
+ } + +
+
@@ -90,12 +131,13 @@ [Parameter] public ProductCategorySDto? Category { get; set; } - protected override Task OnInitializedAsync() + protected override async Task OnInitializedAsync() { if (Category == null) - ViewModel = new ProductCategoryActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, MudDialog); + ViewModel = new ProductCategoryActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, MudDialog,DialogService); else - ViewModel = new ProductCategoryActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, MudDialog,Category); - return base.OnInitializedAsync(); + ViewModel = new ProductCategoryActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, MudDialog, DialogService, Category); + await ViewModel.InitializeAsync(); + await base.OnInitializedAsync(); } } \ No newline at end of file diff --git a/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor.cs b/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor.cs index d1bff31..bbc52cd 100644 --- a/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor.cs +++ b/NetinaShop.AdminPanel.PWA/Dialogs/ProductCategoryActionDialogBox.razor.cs @@ -1,4 +1,11 @@ -namespace NetinaShop.AdminPanel.PWA.Dialogs; +using MediatR; +using NetinaShop.Common.Models.Mapper; +using NetinaShop.Domain.Dtos.LargDtos; +using NetinaShop.Domain.Entities.Discounts; +using NetinaShop.Domain.Entities.Products; +using System.Linq.Dynamic.Core.Tokenizer; + +namespace NetinaShop.AdminPanel.PWA.Dialogs; public class ProductCategoryActionDialogBoxViewModel:BaseViewModel { @@ -6,21 +13,24 @@ public class ProductCategoryActionDialogBoxViewModel:BaseViewModel private readonly IRestWrapper _restWrapper; private readonly IUserUtility _userUtility; private readonly MudDialogInstance _mudDialog; + private readonly IDialogService _dialogService; - public ProductCategoryActionDialogBoxViewModel(ISnackbar snackbar, IRestWrapper restWrapper, IUserUtility userUtility, MudDialogInstance mudDialog) + public ProductCategoryActionDialogBoxViewModel(ISnackbar snackbar, IRestWrapper restWrapper, IUserUtility userUtility, MudDialogInstance mudDialog, IDialogService dialogService) { _snackbar = snackbar; _restWrapper = restWrapper; _userUtility = userUtility; _mudDialog = mudDialog; + _dialogService = dialogService; } - public ProductCategoryActionDialogBoxViewModel(ISnackbar snackbar, IRestWrapper restWrapper, IUserUtility userUtility, MudDialogInstance mudDialog,ProductCategorySDto category) + public ProductCategoryActionDialogBoxViewModel(ISnackbar snackbar, IRestWrapper restWrapper, IUserUtility userUtility, MudDialogInstance mudDialog, IDialogService dialogService,ProductCategorySDto category) { _snackbar = snackbar; _restWrapper = restWrapper; _userUtility = userUtility; _mudDialog = mudDialog; + _dialogService = dialogService; Category = category; } public void Cancel() => _mudDialog.Cancel(); @@ -29,6 +39,7 @@ public class ProductCategoryActionDialogBoxViewModel:BaseViewModel public string Description = string.Empty; public bool IsMain; public bool IsEditing = false; + public readonly ObservableCollection Files = new ObservableCollection(); private ProductCategorySDto? _category = null; [Parameter] @@ -40,13 +51,46 @@ public class ProductCategoryActionDialogBoxViewModel:BaseViewModel _category = value; if (_category != null) { - Name = _category.Name; - Description = _category.Description; IsEditing = true; } } } + public override async Task InitializeAsync() + { + if (IsEditing && Category != null) + { + try + { + IsProcessing = true; + var response = await _restWrapper.CrudDtoApiRest(Address.ProductCategoryController).ReadOne(Category.Id); + var categoryLDto = response; + categoryLDto.Files.ForEach(f => Files.Add(f)); + SelectedCategory = new ProductCategorySDto { Id = categoryLDto.ParentId, Name = categoryLDto.ParentName }; + Name = categoryLDto.Name; + Description = categoryLDto.Description; + IsMain = categoryLDto.IsMain; + } + 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 @@ -55,7 +99,9 @@ public class ProductCategoryActionDialogBoxViewModel:BaseViewModel throw new AppException("لطفا نام دسته را وارد کنید"); IsProcessing = true; var token = await _userUtility.GetBearerTokenAsync(); - var request = new CreateProductCategoryCommand(Name, Description, IsMain, SelectedCategory?.Id ?? default, new List()); + if (token == null) + throw new AppException("Token is null"); + var request = new CreateProductCategoryCommand(Name, Description, IsMain, SelectedCategory?.Id ?? default, Files.ToList()); await _restWrapper.CrudApiRest(Address.ProductCategoryController).Create(request, token); _mudDialog.Close(DialogResult.Ok(true)); } @@ -88,7 +134,7 @@ public class ProductCategoryActionDialogBoxViewModel:BaseViewModel IsProcessing = true; await Task.Delay(1000); var token = await _userUtility.GetBearerTokenAsync(); - var request = new UpdateProductCategoryCommand(Category.Id, Name, Description, IsMain, SelectedCategory?.Id ?? default, new List()); + var request = new UpdateProductCategoryCommand(Category.Id, Name, Description, IsMain, SelectedCategory?.Id ?? default, Files.ToList()); await _restWrapper.CrudApiRest(Address.ProductCategoryController).Update(request, token); _mudDialog.Close(DialogResult.Ok(true)); } @@ -112,7 +158,7 @@ public class ProductCategoryActionDialogBoxViewModel:BaseViewModel private List _productCategories = new List(); public ProductCategorySDto? SelectedCategory; - public async Task> SearchCity(string city) + public async Task> SearchCategory(string city) { try { @@ -136,4 +182,20 @@ public class ProductCategoryActionDialogBoxViewModel:BaseViewModel return _productCategories; } } + + + public async Task SelectFileAsync() + { + DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true }; + var dialog = await _dialogService.ShowAsync("انتخاب عکس", maxWidth); + var result = await dialog.Result; + var file = result.Data; + if (file is StorageFileSDto storageFile) + Files.Add(storageFile); + } + + public void RemoveFile(StorageFileSDto file) + { + Files.Remove(file); + } } \ 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 9788f99..d745bc9 100644 --- a/NetinaShop.AdminPanel.PWA/Services/RestServices/ICrudApiRest.cs +++ b/NetinaShop.AdminPanel.PWA/Services/RestServices/ICrudApiRest.cs @@ -13,6 +13,9 @@ public interface ICrudApiRest where T : class [Get("/{key}")] Task ReadOne(TKey key, [Header("Authorization")] string authorization); + [Get("/{key}")] + Task ReadOne(TKey key); + [Put("")] Task Update([Body] TUpdateCommand payload, [Header("Authorization")] string authorization); diff --git a/NetinaShop.AdminPanel.PWA/version.json b/NetinaShop.AdminPanel.PWA/version.json index 0aac904..66e2506 100644 --- a/NetinaShop.AdminPanel.PWA/version.json +++ b/NetinaShop.AdminPanel.PWA/version.json @@ -1,20 +1,16 @@ { "version": "0.17.18.25", - "versionNumber": 0.101623, + "versionNumber": 0.171825, "versionName": "چرتکه", "description": "", "features": [ - "افزودن خبرنامه", - "افزودن نام انگلیسی برند", - "افزودن دیالوگ اپدیت جدید", - "افزودن تخفیف همکاری در فروش", - "افزودن قابلیت تغییر نمایش سریع کالا" + "افزودن تم دارک", + "تکمیل پروسه سفارش گیری", + "قابلیت افزودن تصویر به برند ها", + "قابلیت افزودن تصویر به دسته بندی محصولات" ], "bugFixes": [ "حل مشکلات امنیتی", - "حل مشکل ویرایش کالا", - "حل مشکل فیلترهای کالاها", - "حل مشکل رسپانسیو صفحه اصلی", - "حل مشکل انتخاب دسته بندی در صفحه کالاها" + "رفع مشکلات رسپانسیو" ] }