80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.RewardAgg;
|
|
using CompanyManagment.App.Contracts.Reward;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class RewardRepository : RepositoryBase<long, Reward>, IRewardRepository
|
|
{
|
|
private readonly CompanyContext _companyContext;
|
|
public RewardRepository(CompanyContext companyContext) : base(companyContext)
|
|
{
|
|
_companyContext = companyContext;
|
|
}
|
|
|
|
public List<RewardViewModel> GetSearchList(RewardSearchModel searchViewModel)
|
|
{
|
|
var query = _companyContext.Rewards.Where(x => x.WorkshopId == searchViewModel.WorkshopId && x.IsActive == IsActive.True);
|
|
|
|
if (searchViewModel.EmployeeId != 0)
|
|
query = query.Where(x => x.EmployeeId == searchViewModel.EmployeeId);
|
|
var enumQuery = query;
|
|
var result = enumQuery.OrderByDescending(x=>x.CreationDate).Select(x => new RewardViewModel()
|
|
{
|
|
Id = x.id,
|
|
EmployeeId = x.EmployeeId,
|
|
Description = x.Description,
|
|
Amount = x.Amount.ToMoney(),
|
|
WorkshopId = x.WorkshopId,
|
|
CreationDate = x.CreationDate.ToFarsi(),
|
|
GrantDate = x.GrantDate.ToFarsi()
|
|
}).Skip(searchViewModel.PageIndex).Take(30);
|
|
|
|
var employees = _companyContext.Employees.Where(x => result.Any(a => a.EmployeeId == x.id));
|
|
var personnelCodes = _companyContext.PersonnelCodeSet
|
|
.Where(x => result.Any(a => a.EmployeeId == x.EmployeeId && x.WorkshopId == a.WorkshopId));
|
|
return result.Select(x => new RewardViewModel()
|
|
{
|
|
Amount = x.Amount,
|
|
CreationDate = x.CreationDate,
|
|
Description = x.Description,
|
|
GrantDate = x.GrantDate,
|
|
EmployeeFullName = employees.FirstOrDefault(e => e.id == x.EmployeeId).FullName ,
|
|
Id = x.Id,
|
|
PersonnelCode = personnelCodes
|
|
.FirstOrDefault(a => a.WorkshopId == x.WorkshopId && a.EmployeeId == x.EmployeeId).PersonnelCode
|
|
.ToString(),
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId
|
|
}).ToList();
|
|
}
|
|
|
|
public EditRewardViewModel GetDetails(long id)
|
|
{
|
|
var entity = _companyContext.Rewards.FirstOrDefault(x => x.id == id);
|
|
if (entity == null)
|
|
return new();
|
|
var res = new EditRewardViewModel()
|
|
{
|
|
Id = entity.id,
|
|
WorkshopId = entity.WorkshopId,
|
|
EmployeeId = entity.EmployeeId,
|
|
Amount = entity.Amount.ToMoney(),
|
|
Description = entity.Description,
|
|
RewardedByAccountId = entity.RewardedByAccountId,
|
|
GrantDate = entity.GrantDate.ToFarsi()
|
|
};
|
|
|
|
res.EmployeeFullName = _companyContext.Employees.Find(entity.EmployeeId)?.FullName;
|
|
return res;
|
|
|
|
}
|
|
|
|
public List<Reward> GetBy(IEnumerable<long> ids)
|
|
{
|
|
return _companyContext.Rewards.Where(x => ids.Contains(x.id)).ToList();
|
|
}
|
|
} |