66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.EmployeeComputeOptionsAgg;
|
|
using CompanyManagment.App.Contracts.EmployeeComputeOptions;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class EmployeeComputeOptionsRepository : RepositoryBase<long, EmployeeComputeOptions>, IEmployeeComputeOptionsRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public EmployeeComputeOptionsRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public EmployeeComputeOptionsViewModel GetEmployeeOptions(long workshopId, long employeeId)
|
|
{
|
|
var result = new EmployeeComputeOptionsViewModel();
|
|
result = _context.EmployeeComputeOptionsSet.Select(x => new EmployeeComputeOptionsViewModel
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
ComputeOptions = x.ComputeOptions,
|
|
YearsOptions = x.YearsOptions,
|
|
BonusesOptions = x.BonusesOptions,
|
|
|
|
}).FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId);
|
|
|
|
if (result == null)
|
|
{
|
|
var getFromWorkshop = _context.Workshops.FirstOrDefault(x => x.id == workshopId);
|
|
if (getFromWorkshop != null)
|
|
{
|
|
var fromWorkshop = new EmployeeComputeOptionsViewModel()
|
|
{
|
|
EmployeeId = employeeId,
|
|
WorkshopId = workshopId,
|
|
ComputeOptions = getFromWorkshop.ComputeOptions,
|
|
YearsOptions = getFromWorkshop.YearsOptions,
|
|
BonusesOptions= getFromWorkshop.BonusesOptions,
|
|
};
|
|
|
|
result = fromWorkshop;
|
|
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<EmployeeComputeOptionsViewModel> GetAllByWorkshopId(long workshopId)
|
|
{
|
|
return _context.EmployeeComputeOptionsSet.Select(x => new EmployeeComputeOptionsViewModel
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
ComputeOptions = x.ComputeOptions,
|
|
YearsOptions = x.YearsOptions,
|
|
BonusesOptions = x.BonusesOptions,
|
|
|
|
}).Where(x => x.WorkshopId == workshopId).ToList();
|
|
}
|
|
} |