diff --git a/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor b/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor index ebd57cb..9ebf8fe 100644 --- a/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor +++ b/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor @@ -136,6 +136,32 @@ + + + + + + +
+ +

منتظر بمانید

+
+
+
+
+ +

@e.PersianName

+
+
+
+ + + + diff --git a/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs b/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs index 34bea56..4c55144 100644 --- a/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs +++ b/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs @@ -40,8 +40,23 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel IsEditing = true; } - private bool _isProductEnable; + private bool _isBrandEnable; + public bool IsBrandEnable + { + get => _isBrandEnable; + set + { + _isBrandEnable = value; + if (_isBrandEnable) + { + IsCategoryEnable = false; + IsProductEnable = false; + IsAllEnable = false; + } + } + } + private bool _isProductEnable; public bool IsProductEnable { get => _isProductEnable; @@ -51,10 +66,12 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel if (_isProductEnable) { IsCategoryEnable = false; + IsBrandEnable = false; IsAllEnable = false; } } } + private bool _isCategoryEnable; public bool IsCategoryEnable { @@ -65,6 +82,7 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel if (_isCategoryEnable) { IsProductEnable = false; + IsBrandEnable = false; IsAllEnable = false; } } @@ -79,6 +97,7 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel if (_isAllEnable) { IsCategoryEnable = false; + IsBrandEnable = false; IsProductEnable = false; } } @@ -123,6 +142,10 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel if (PageDto.CategoryId != default) SelectedCategory = new ProductCategorySDto { Id = PageDto.CategoryId, Name = PageDto.CategoryName }; + if (PageDto.ProductId != default) + SelectedProduct = new ProductSDto { Id = PageDto.ProductId, PersianName = PageDto.ProductName }; + + if (PageDto.ProductId != default) SelectedProduct = new ProductSDto { Id = PageDto.ProductId, PersianName = PageDto.ProductName }; @@ -185,6 +208,13 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel throw new Exception("کالا مورد نظر را برای تخفیف انتخاب نمایید"); PageDto.ProductId = SelectedProduct.Id; } + else if (IsBrandEnable) + { + PageDto.Type = DiscountType.Brand; + if (SelectedBrand == null) + throw new Exception("برند مورد نظر را برای تخفیف انتخاب نمایید"); + PageDto.BrandId = SelectedBrand.Id; + } var token = await _userUtility.GetBearerTokenAsync(); if (token == null) @@ -216,7 +246,7 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel PageDto.IsForFirstPurchase, PageDto.ProductId, PageDto.CategoryId, - default); + PageDto.BrandId); await _restWrapper.CrudDtoApiRest(Address.DiscountController).Create(request, token); _snackbar.Add($"ساخت تخفیف با موفقیت انجام شد", Severity.Success); @@ -244,6 +274,7 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel IsProcessing = false; } } + public async Task SubmitEditAsync() { try @@ -270,6 +301,13 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel throw new Exception("کالا مورد نظر را برای تخفیف انتخاب نمایید"); PageDto.ProductId = SelectedProduct.Id; } + else if (IsBrandEnable) + { + PageDto.Type = DiscountType.Brand; + if (SelectedBrand == null) + throw new Exception("برند مورد نظر را برای تخفیف انتخاب نمایید"); + PageDto.BrandId = SelectedBrand.Id; + } var token = await _userUtility.GetBearerTokenAsync(); if (token == null) @@ -298,7 +336,8 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel PageDto.IsSpecialOffer, PageDto.IsForFirstPurchase, PageDto.ProductId, - PageDto.CategoryId); + PageDto.CategoryId, + PageDto.BrandId); await _restWrapper.CrudApiRest(Address.DiscountController).Update(request, token); _snackbar.Add($"ویرایش تخفیف با موفقیت انجام شد", Severity.Success); _mudDialog.Close(true); @@ -379,4 +418,29 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel return _products; } } + + private List _brands = new List(); + public BrandSDto? SelectedBrand; + public async Task> SearchBrand(string brand) + { + try + { + if (brand.IsNullOrEmpty()) + _brands = await _restWrapper.BrandRestApi.ReadAll(0); + else + _brands = await _restWrapper.BrandRestApi.ReadAll(brand); + return _brands; + } + catch (ApiException ex) + { + var exe = await ex.GetContentAsAsync(); + _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); + return _brands; + } + catch (Exception e) + { + _snackbar.Add(e.Message, Severity.Error); + return _brands; + } + } } \ No newline at end of file