From 6b8eaac49cf6dd6a37b72f3511987f226cfa329f Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Mon, 14 Apr 2025 18:02:07 +0330 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20brand-specific=20discount=20f?= =?UTF-8?q?eature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ➕ Add `MudAutocomplete` for brand selection in UI Introduced a new component in `DiscountActionDialogBox.razor`. - 🆕 Introduce `IsBrandEnable` property in ViewModel Added to manage the state of brand-specific discounts. - 🔄 Update ViewModel logic for `IsBrandEnable` Ensured mutual exclusivity with other discount types. - 🛠️ Handle brand selection in `SubmitEditAsync` Added logic for brand selection and validation. - 🔍 Modify `SearchBrand` method in ViewModel Fetch and return brand data for selection. - 📦 Change target framework to `net5.0` Updated `Netina.Common.csproj` and `Netina.Domain.csproj`. - 🆙 Update `UpdateDiscountCommand` and `DiscountLDto` Included `BrandId` and `BrandName` properties. - 🛠️ Modify `UpdateDiscountCommandHandler` Handle brand-specific discount updates. - 🆕 Add `SubmitEditAsync` method in ViewModel For handling discount edits. Changes made by Amir.H Khademi --- .../Dialogs/DiscountActionDialogBox.razor | 26 +++++++ .../Dialogs/DiscountActionDialogBox.razor.cs | 70 ++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) 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