feat: implement method to retrieve paginated contract list for client with filtering options
This commit is contained in:
@@ -49,7 +49,7 @@ public interface IContractRepository : IRepository<long, Contract>
|
||||
|
||||
List<ContractViweModel> SearchForClient(ContractSearchModel searchModel);
|
||||
|
||||
//Task<PagedResult<GetContractClientViewModel>> GetContractListForClient(ContractClientSearchModel searchModel);
|
||||
Task<PagedResult<GetContractListForClientResponse>> GetContractListForClient(GetContractListForClientRequest searchModel);
|
||||
|
||||
#endregion
|
||||
#region NewChangeByHeydari
|
||||
@@ -66,4 +66,36 @@ public interface IContractRepository : IRepository<long, Contract>
|
||||
ContractViweModel GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime startOfMonth, DateTime endOfMonth);
|
||||
List<ContractViweModel> GetByWorkshopIdInDates(long workshopId, DateTime contractStart, DateTime contractEnd);
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class GetContractListForClientResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string PersonnelCode { get; set; }
|
||||
public string ContractNo { get; set; }
|
||||
public string EmployeeFullName { get; set; }
|
||||
public string ContractStart { get; set; }
|
||||
public string ContractEnd { get; set; }
|
||||
public bool IsSigned { get; set; }
|
||||
}
|
||||
|
||||
public class GetContractListForClientRequest: PaginationRequest
|
||||
{
|
||||
public int Year { get; set; }
|
||||
public int Month { get; set; }
|
||||
public string StartDate { get; set; }
|
||||
public string EndDate { get; set; }
|
||||
public long EmployeeId { get; set; }
|
||||
public ContractListOrderType? OrderType { get; set; }
|
||||
}
|
||||
|
||||
public enum ContractListOrderType
|
||||
{
|
||||
ByContractCreationDate,
|
||||
BySignedContract,
|
||||
ByUnSignedContract,
|
||||
ByPersonnelCode,
|
||||
ByPersonnelCodeDescending,
|
||||
ByContractStartDate,
|
||||
ByContractStartDateDescending
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Exceptions;
|
||||
using _0_Framework.InfraStructure;
|
||||
using Company.Domain.ContractAgg;
|
||||
using Company.Domain.empolyerAgg;
|
||||
@@ -1506,6 +1507,109 @@ public class ContractRepository : RepositoryBase<long, Contract>, IContractRepos
|
||||
|
||||
}
|
||||
|
||||
public async Task<PagedResult<GetContractListForClientResponse>> GetContractListForClient(GetContractListForClientRequest searchModel)
|
||||
{
|
||||
var workshopId = _authHelper.GetWorkshopId();
|
||||
var query = _context.Contracts
|
||||
.Where(c => c.WorkshopIds == workshopId);
|
||||
|
||||
#region Search
|
||||
|
||||
if (searchModel.EmployeeId > 0)
|
||||
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
|
||||
if (!string.IsNullOrWhiteSpace(searchModel.StartDate) && string.IsNullOrWhiteSpace(searchModel.EndDate))
|
||||
{
|
||||
if (!searchModel.StartDate.TryToGeorgianDateTime(out var startDate))
|
||||
throw new BadRequestException("تاریخ شروع وارد شده معتبر نمی باشد.");
|
||||
|
||||
if (!searchModel.EndDate.TryToGeorgianDateTime(out var endDate))
|
||||
throw new BadRequestException("تاریخ پایان وارد شده معتبر نمی باشد.");
|
||||
|
||||
query = query.Where(x => x.ContarctStart <=endDate && x.ContractEnd >= startDate);
|
||||
}
|
||||
|
||||
if (searchModel.Year>0 && searchModel.Month >0)
|
||||
{
|
||||
|
||||
var startDateFa = $"{searchModel.Year:0000}/{searchModel.Month:00}/01";
|
||||
if (!startDateFa.TryToGeorgianDateTime(out var startDate))
|
||||
throw new BadRequestException("سال و ماه وارد شده معتبر نمی باشد.");
|
||||
|
||||
if(!startDateFa.FindeEndOfMonth().TryToGeorgianDateTime(out var endDate))
|
||||
throw new BadRequestException("سال و ماه وارد شده معتبر نمی باشد.");
|
||||
|
||||
query = query.Where(x => x.ContarctStart <=endDate && x.ContractEnd >= startDate);
|
||||
}
|
||||
|
||||
if (searchModel.OrderType != null)
|
||||
{
|
||||
switch (searchModel.OrderType)
|
||||
{
|
||||
case ContractListOrderType.ByContractCreationDate:
|
||||
query = query.OrderBy(x => x.CreationDate);
|
||||
break;
|
||||
case ContractListOrderType.ByContractStartDate:
|
||||
query = query.OrderBy(x => x.ContarctStart);
|
||||
break;
|
||||
case ContractListOrderType.ByContractStartDateDescending:
|
||||
query = query.OrderByDescending(x=>x.ContarctStart);
|
||||
break;
|
||||
case ContractListOrderType.ByPersonnelCode:
|
||||
query = query.OrderBy(x => x.PersonnelCode);
|
||||
break;
|
||||
case ContractListOrderType.ByPersonnelCodeDescending:
|
||||
query = query.OrderByDescending(x => x.PersonnelCode);
|
||||
break;
|
||||
case ContractListOrderType.BySignedContract:
|
||||
query = query.OrderByDescending(x => x.Signature == "1");
|
||||
break;
|
||||
case ContractListOrderType.ByUnSignedContract:
|
||||
query = query.OrderBy(x => x.Signature == "1");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
query = query.OrderByDescending(x => x.id);
|
||||
}
|
||||
#endregion
|
||||
|
||||
var pagedList =await query
|
||||
.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync();
|
||||
|
||||
var employeeIds = pagedList.Select(x => x.EmployeeId).ToList();
|
||||
|
||||
var employees = await _context.Employees
|
||||
.Where(x => employeeIds.Contains(x.id)).Select(x => new
|
||||
{
|
||||
Id = x.id,
|
||||
x.FullName
|
||||
}).ToListAsync();
|
||||
|
||||
var result = new PagedResult<GetContractListForClientResponse>
|
||||
{
|
||||
TotalCount = await query.CountAsync(),
|
||||
List = pagedList.Select(c =>
|
||||
{
|
||||
var employeeFullName = employees
|
||||
.FirstOrDefault(e => e.Id == c.EmployeeId)?.FullName ?? "";
|
||||
|
||||
return new GetContractListForClientResponse
|
||||
{
|
||||
Id = c.id,
|
||||
PersonnelCode = c.PersonnelCode.ToString(),
|
||||
ContractStart = c.ContarctStart.ToFarsi(),
|
||||
ContractEnd = c.ContractEnd.ToFarsi(),
|
||||
ContractNo = c.ContractNo,
|
||||
IsSigned = c.Signature == "1",
|
||||
EmployeeFullName = employeeFullName
|
||||
};
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NewChangeByHeydari
|
||||
|
||||
Reference in New Issue
Block a user