From f9e4bb3a976ff7036651fb4ad44d351e2925bac6 Mon Sep 17 00:00:00 2001 From: DeepnaPooja Date: Wed, 9 Sep 2026 16:29:54 +0530 Subject: [PATCH] Update scheme management to include IsActive --- Distribution/Features/Scheme/SchemeDTOs.cs | 3 ++- Distribution/Features/Scheme/SchemeRepository.cs | 2 +- Distribution/Features/Scheme/SchemeService.cs | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Distribution/Features/Scheme/SchemeDTOs.cs b/Distribution/Features/Scheme/SchemeDTOs.cs index be901c3..5e49bb7 100644 --- a/Distribution/Features/Scheme/SchemeDTOs.cs +++ b/Distribution/Features/Scheme/SchemeDTOs.cs @@ -46,7 +46,8 @@ public record UpdateSchemeRequest( DateTime DateRangeFrom, DateTime DateRangeTo, bool AgentLimitExempt, - decimal? BaselineExpectedSales); + decimal? BaselineExpectedSales, + bool IsActive); public record ApplySchemeRequest(Guid SchemeId); diff --git a/Distribution/Features/Scheme/SchemeRepository.cs b/Distribution/Features/Scheme/SchemeRepository.cs index ae7123c..123ca69 100644 --- a/Distribution/Features/Scheme/SchemeRepository.cs +++ b/Distribution/Features/Scheme/SchemeRepository.cs @@ -20,7 +20,7 @@ public class SchemeRepository(AppDBContext context) : ISchemeRepository .Include(s => s.TriggerItem) .Include(s => s.FreeItem) .Include(s => s.BundleComponents).ThenInclude(c => c.Item) - .Where(s => s.IsActive); + .AsQueryable(); if (regionId.HasValue) query = query.Where(s => s.FK_RegionId == regionId); diff --git a/Distribution/Features/Scheme/SchemeService.cs b/Distribution/Features/Scheme/SchemeService.cs index 5d88d34..ebf4329 100644 --- a/Distribution/Features/Scheme/SchemeService.cs +++ b/Distribution/Features/Scheme/SchemeService.cs @@ -41,7 +41,7 @@ public class SchemeService( public async Task GetByIdAsync(Guid id) { var scheme = await repo.GetByIdAsync(id); - return scheme is null || !scheme.IsActive ? null : ToResponse(scheme); + return scheme is null ? null : ToResponse(scheme); } /// @@ -114,7 +114,7 @@ public class SchemeService( public async Task UpdateAsync(Guid id, UpdateSchemeRequest request, CancellationToken ct = default) { var scheme = await repo.GetByIdAsync(id); - if (scheme is null || !scheme.IsActive) return null; + if (scheme is null) return null; ValidatePercentRuleConfig(scheme.RuleType, request.RuleConfig); if (request.DateRangeFrom > request.DateRangeTo) @@ -128,6 +128,7 @@ public class SchemeService( scheme.DateRangeTo = request.DateRangeTo; scheme.AgentLimitExempt = request.AgentLimitExempt; scheme.BaselineExpectedSales = request.BaselineExpectedSales; + scheme.IsActive = request.IsActive; await uow.BeginAsync(ct); try { repo.Update(scheme); await uow.CommitAsync(ct); } @@ -255,7 +256,7 @@ public class SchemeService( var orderItems = await orderRepo.GetItemsByOrderIdAsync(orderId); var regionId = store.Route?.FK_RegionId; - var candidates = await repo.GetAllAsync(); + var candidates = (await repo.GetAllAsync()).Where(s => s.IsActive); var result = new List(); foreach (var scheme in candidates)