diff --git a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs index 214df689..b8b95235 100644 --- a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs +++ b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs @@ -73,6 +73,7 @@ public interface IInsuranceListRepository:IRepository Task GetInsuranceOperationDetails(long id); Task GetTabCounts(InsuranceListSearchModel searchModel); + Task> GetInsuranceClientList(InsuranceClientSearchModel searchModel); #endregion diff --git a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs index 9d48019c..1a36dafb 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs @@ -90,8 +90,27 @@ public interface IInsuranceListApplication Task GetInsuranceOperationDetails(long id); Task GetTabCounts(InsuranceListSearchModel searchModel); + Task> GetInsuranceClientList(InsuranceClientSearchModel searchModel); + #endregion Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); +} + +public class InsuranceClientSearchModel:PaginationRequest +{ + public int Year { get; set; } + public int Month { get; set; } + public string Sorting { get; set; } +} +public class InsuranceClientListViewModel +{ + public long Id { get; set; } + public string Year { get; set; } + public string Month { get; set; } + public long WorkShopId { get; set; } + public int YearInt { get; set; } + public string MonthName { get; set; } + public int MonthInt { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 2cac4299..5a3c5fb0 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -2371,6 +2371,11 @@ public class InsuranceListApplication : IInsuranceListApplication return _insuranceListRepositpry.GetTabCounts(searchModel); } + public async Task> GetInsuranceClientList(InsuranceClientSearchModel searchModel) + { + return await _insuranceListRepositpry.GetInsuranceClientList(searchModel); + } + public async Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel) { return await _insuranceListRepositpry.GetNotCreatedWorkshop(searchModel); diff --git a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs index a2768060..da63d47b 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs @@ -1777,6 +1777,49 @@ public class InsuranceListRepository : RepositoryBase, IIns return res; } + public async Task> GetInsuranceClientList(InsuranceClientSearchModel searchModel) + { + var workshopId = _authHelper.GetWorkshopId(); + var query = _context.InsuranceListSet + .Select(x => new InsuranceClientListViewModel + { + Id = x.id, + WorkShopId = x.WorkshopId, + Year = x.Year, + YearInt = Convert.ToInt32(x.Year), + Month = x.Month, + MonthName = x.Month.ToFarsiMonthByNumber(), + MonthInt = Convert.ToInt32(x.Month), + }).Where(x => x.WorkShopId == workshopId); + + + if (searchModel.Year>0) + { + query = query.Where(x => x.YearInt == searchModel.Year); + } + if (searchModel.Month > 0) + { + query = query.Where(x => x.MonthInt == searchModel.Month); + } + + var res = new PagedResult + { + TotalCount = query.Count() + }; + query = searchModel.Sorting switch + { + "CreationDate-Max" => query.OrderByDescending(x => x.Id), + "CreationDate-Min" => query.OrderBy(x => x.Id), + "Month-Max" => query.OrderByDescending(x => x.MonthInt), + "Month-Min" => query.OrderBy(x => x.MonthInt), + "Year-Max" => query.OrderByDescending(x => x.YearInt), + "Year-Min" => query.OrderBy(x => x.YearInt), + _ => query.OrderByDescending(x => x.Id), + }; + res.List =await query.ApplyPagination(searchModel.PageIndex,searchModel.PageSize).ToListAsync(); + return res; + } + public async Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel) { if (string.IsNullOrEmpty(searchModel.Month) || string.IsNullOrEmpty(searchModel.Year)) diff --git a/ServiceHost/Areas/Client/Controllers/InsuranceController.cs b/ServiceHost/Areas/Client/Controllers/InsuranceController.cs new file mode 100644 index 00000000..00f8ee06 --- /dev/null +++ b/ServiceHost/Areas/Client/Controllers/InsuranceController.cs @@ -0,0 +1,22 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.InsuranceList; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Client.Controllers; + +public class InsuranceController:ClientBaseController +{ + private readonly IInsuranceListApplication _insuranceListApplication; + + public InsuranceController(IInsuranceListApplication insuranceListApplication) + { + _insuranceListApplication = insuranceListApplication; + } + [HttpGet] + public async Task>> GetInsurances(InsuranceClientSearchModel searchModel) + { + var insurances =await _insuranceListApplication.GetInsuranceClientList(searchModel); + return Ok(insurances); + } +} diff --git a/ServiceHost/Areas/Client/Pages/Company/InsuranceList/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/InsuranceList/Index.cshtml.cs index 9e61c886..dac87887 100644 --- a/ServiceHost/Areas/Client/Pages/Company/InsuranceList/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/InsuranceList/Index.cshtml.cs @@ -1,4 +1,4 @@ -using System; + using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -39,7 +39,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.InsuranceList public string WorkshopName; public List YearlyList; public string Year; - public string Month; + public string Month; public string Sorting; public int PageIndex; public string TypeOfInsurance; @@ -163,6 +163,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.InsuranceList } #endregion + #region OldClientByHeydari //public IActionResult OnGetSearch(InsuranceListSearchModel searchModel)