113 lines
4.0 KiB
C#
113 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.FileEmployeeAgg;
|
|
using CompanyManagment.App.Contracts.FileEmployee;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class FileEmployeeRepository : RepositoryBase<long, FileEmployee>, IFileEmployeeRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public DateTime initial = new DateTime(1922, 01, 01, 00, 00, 00, 0000000);
|
|
public FileEmployeeRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public List<FileEmployeeViewModel> GetFileEmployee()
|
|
{
|
|
return _context.FileEmployeeSet.Where(x => x.IsActive == "true").Select(x => new FileEmployeeViewModel()
|
|
{
|
|
Id = x.id,
|
|
FName = x.FName,
|
|
IsActive = x.IsActive,
|
|
LName = x.LName,
|
|
FullName = x.FName + " " + x.LName,
|
|
FatherName = x.FatherName,
|
|
NationalCode = x.NationalCode,
|
|
IdNumber = x.IdNumber,
|
|
DateOfBirth = x.DateOfBirth == initial ? "" : x.DateOfBirth.ToFarsi(),
|
|
|
|
}).ToList();
|
|
}
|
|
|
|
public EditFileEmployee GetDetails(long id)
|
|
{
|
|
return _context.FileEmployeeSet.Select(x => new EditFileEmployee()
|
|
{
|
|
Id = x.id,
|
|
FName = x.FName,
|
|
LName = x.LName,
|
|
Gender = x.Gender,
|
|
NationalCode = x.NationalCode,
|
|
IdNumber = x.IdNumber,
|
|
FatherName = x.FatherName,
|
|
DateOfBirth = x.DateOfBirth == initial ? "" : x.DateOfBirth.ToFarsi(),
|
|
Phone = x.Phone,
|
|
MaritalStatus = x.MaritalStatus,
|
|
LevelOfEducation = x.LevelOfEducation,
|
|
FieldOfStudy = x.FieldOfStudy,
|
|
InsuranceCode = x.InsuranceCode,
|
|
RepresentativeFullName = x.RepresentativeFullName,
|
|
OfficePhone = x.OfficePhone,
|
|
FullName = x.FName + " " + x.LName,
|
|
MclsUserName = x.MclsUserName,
|
|
MclsPassword = x.MclsPassword,
|
|
EserviceUserName = x.EserviceUserName,
|
|
EservicePassword = x.EservicePassword,
|
|
TaxOfficeUserName = x.TaxOfficeUserName,
|
|
TaxOfficepassword = x.TaxOfficepassword,
|
|
SanaUserName = x.SanaUserName,
|
|
SanaPassword = x.SanaPassword,
|
|
RepresentativeId = x.RepresentativeId,
|
|
|
|
|
|
|
|
})
|
|
.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public List<FileEmployeeViewModel> Search(FileEmployeeSearchModel searchModel)
|
|
{
|
|
var query = _context.FileEmployeeSet.Select(x => new FileEmployeeViewModel()
|
|
{
|
|
Id = x.id,
|
|
FName = x.FName,
|
|
|
|
LName = x.LName,
|
|
NationalCode = x.NationalCode,
|
|
IdNumber = x.IdNumber,
|
|
FullName = x.FName + " " + x.LName,
|
|
IsActive = x.IsActive,
|
|
|
|
|
|
});
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.FName))
|
|
query = query.Where(x => x.FName.Contains(searchModel.FName));
|
|
if (!string.IsNullOrWhiteSpace(searchModel.LName))
|
|
query = query.Where(x => x.LName.Contains(searchModel.LName));
|
|
if (!string.IsNullOrWhiteSpace(searchModel.NationalCode))
|
|
query = query.Where(x => x.NationalCode.Contains(searchModel.NationalCode));
|
|
if (!string.IsNullOrWhiteSpace(searchModel.IdNumber))
|
|
query = query.Where(x => x.IdNumber.Contains(searchModel.IdNumber));
|
|
|
|
|
|
if (searchModel.IsActive=="true")
|
|
{
|
|
query = query.Where(x => x.IsActive == "true");
|
|
}
|
|
else if (searchModel.IsActive == "both")
|
|
{
|
|
query = query.Where(x => x.IsActive == "false" || x.IsActive == "true");
|
|
}
|
|
else if(searchModel.IsActive =="false")
|
|
{
|
|
query = query.Where(x => x.IsActive == "false");
|
|
}
|
|
return query.OrderByDescending(x => x.Id).ToList();
|
|
}
|
|
} |