fix create employee bug
This commit is contained in:
@@ -20,120 +20,120 @@ namespace CompanyManagment.Application
|
||||
private readonly IRollCallEmployeeStatusRepository _employeeRollCallStatusRepository;
|
||||
private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository;
|
||||
private readonly ILeftWorkRepository _leftWorkRepository;
|
||||
private readonly IRollCallServiceRepository _rollCallServiceRepository;
|
||||
private readonly ILeftWorkTempRepository _leftWorkTempRepository;
|
||||
private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository;
|
||||
private readonly IRollCallServiceRepository _rollCallServiceRepository;
|
||||
private readonly ILeftWorkTempRepository _leftWorkTempRepository;
|
||||
private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository;
|
||||
|
||||
|
||||
|
||||
public RollCallEmployeeStatusApplication(IRollCallEmployeeStatusRepository employeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, ILeftWorkRepository leftWorkRepository, IRollCallServiceRepository rollCallServiceRepository, ILeftWorkTempRepository leftWorkTempRepository, ILeftWorkInsuranceRepository leftWorkInsuranceRepository)
|
||||
public RollCallEmployeeStatusApplication(IRollCallEmployeeStatusRepository employeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, ILeftWorkRepository leftWorkRepository, IRollCallServiceRepository rollCallServiceRepository, ILeftWorkTempRepository leftWorkTempRepository, ILeftWorkInsuranceRepository leftWorkInsuranceRepository)
|
||||
{
|
||||
_employeeRollCallStatusRepository = employeeStatusRepository;
|
||||
_rollCallEmployeeRepository = rollCallEmployeeRepository;
|
||||
_leftWorkRepository = leftWorkRepository;
|
||||
_rollCallServiceRepository = rollCallServiceRepository;
|
||||
_leftWorkTempRepository = leftWorkTempRepository;
|
||||
_leftWorkInsuranceRepository = leftWorkInsuranceRepository;
|
||||
}
|
||||
_rollCallServiceRepository = rollCallServiceRepository;
|
||||
_leftWorkTempRepository = leftWorkTempRepository;
|
||||
_leftWorkInsuranceRepository = leftWorkInsuranceRepository;
|
||||
}
|
||||
|
||||
public OperationResult Create(CreateRollCallEmployeeStatus cmd)
|
||||
{
|
||||
OperationResult op = new();
|
||||
RollCallEmployee rollCallEmployee = _rollCallEmployeeRepository.Get(cmd.RollCallEmployeeId);
|
||||
if (rollCallEmployee == null)
|
||||
return op.Failed("کارمند مجاز نیست");
|
||||
public OperationResult Create(CreateRollCallEmployeeStatus cmd)
|
||||
{
|
||||
OperationResult op = new();
|
||||
RollCallEmployee rollCallEmployee = _rollCallEmployeeRepository.Get(cmd.RollCallEmployeeId);
|
||||
if (rollCallEmployee == null)
|
||||
return op.Failed("کارمند مجاز نیست");
|
||||
|
||||
if (!_leftWorkRepository.Exists(x =>
|
||||
x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId &&
|
||||
x.StartWorkDate <= DateTime.Now && x.LeftWorkDate > DateTime.Now) &&
|
||||
!_leftWorkTempRepository.Exists(x =>
|
||||
x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId &&
|
||||
x.LeftWorkType == LeftWorkTempType.StartWork))
|
||||
{
|
||||
return op.Failed("کارمند شروع به کار ندارد");
|
||||
}
|
||||
if (!_leftWorkRepository.Exists(x =>
|
||||
x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId &&
|
||||
x.StartWorkDate <= DateTime.Now && x.LeftWorkDate > DateTime.Now) &&
|
||||
!_leftWorkTempRepository.Exists(x =>
|
||||
x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId &&
|
||||
x.LeftWorkType == LeftWorkTempType.StartWork))
|
||||
{
|
||||
return op.Failed("کارمند شروع به کار ندارد");
|
||||
}
|
||||
|
||||
if (_employeeRollCallStatusRepository.Exists(y =>
|
||||
rollCallEmployee.id == y.RollCallEmployeeId && y.EndDate.Date > DateTime.Now.Date))
|
||||
return op.Failed("کارمند فعال می باشد");
|
||||
if (_employeeRollCallStatusRepository.Exists(y =>
|
||||
rollCallEmployee.id == y.RollCallEmployeeId && y.EndDate.Date > DateTime.Now.Date))
|
||||
return op.Failed("کارمند فعال می باشد");
|
||||
|
||||
if (_employeeRollCallStatusRepository.Exists(y =>
|
||||
rollCallEmployee.id == y.RollCallEmployeeId && y.EndDate.Date == DateTime.Now.Date))
|
||||
{
|
||||
RollCallEmployeeStatus previousStatusInDate = _employeeRollCallStatusRepository.GetByRollCallEmployeeIdAndDate(cmd.RollCallEmployeeId, DateTime.Now.Date);
|
||||
previousStatusInDate.Edit(previousStatusInDate.StartDate, Tools.GetUndefinedDateTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
var pc = new PersianCalendar();
|
||||
var startStatus = DateTime.Today;
|
||||
LeftWork leftWork =
|
||||
_leftWorkRepository.GetLastLeftWork(rollCallEmployee.EmployeeId, rollCallEmployee.WorkshopId).GetAwaiter().GetResult();
|
||||
if (_employeeRollCallStatusRepository.Exists(y =>
|
||||
rollCallEmployee.id == y.RollCallEmployeeId && y.EndDate.Date == DateTime.Now.Date))
|
||||
{
|
||||
RollCallEmployeeStatus previousStatusInDate = _employeeRollCallStatusRepository.GetByRollCallEmployeeIdAndDate(cmd.RollCallEmployeeId, DateTime.Now.Date);
|
||||
previousStatusInDate.Edit(previousStatusInDate.StartDate, Tools.GetUndefinedDateTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
var pc = new PersianCalendar();
|
||||
var startStatus = DateTime.Today;
|
||||
LeftWork leftWork =
|
||||
_leftWorkRepository.GetLastLeftWork(rollCallEmployee.EmployeeId, rollCallEmployee.WorkshopId).GetAwaiter().GetResult();
|
||||
|
||||
if (leftWork.StartWorkDate > DateTime.Today)
|
||||
startStatus = leftWork.StartWorkDate;
|
||||
if (leftWork != null && leftWork.StartWorkDate > DateTime.Today)
|
||||
startStatus = leftWork.StartWorkDate;
|
||||
|
||||
//else if(pc.GetMonth(DateTime.Today) == pc.GetMonth(leftWork.StartWorkDate))
|
||||
//{
|
||||
// startStatus = new DateTime(pc.GetYear(leftWork.StartWorkDate), pc.GetMonth(leftWork.StartWorkDate),
|
||||
// 1, pc);
|
||||
//}
|
||||
//else if(pc.GetMonth(DateTime.Today) == pc.GetMonth(leftWork.StartWorkDate))
|
||||
//{
|
||||
// startStatus = new DateTime(pc.GetYear(leftWork.StartWorkDate), pc.GetMonth(leftWork.StartWorkDate),
|
||||
// 1, pc);
|
||||
//}
|
||||
|
||||
RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, startStatus);
|
||||
_employeeRollCallStatusRepository.Create(newRecord);
|
||||
}
|
||||
RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, startStatus);
|
||||
_employeeRollCallStatusRepository.Create(newRecord);
|
||||
}
|
||||
|
||||
_employeeRollCallStatusRepository.SaveChanges();
|
||||
_employeeRollCallStatusRepository.SaveChanges();
|
||||
|
||||
return op.Succcedded();
|
||||
}
|
||||
return op.Succcedded();
|
||||
}
|
||||
|
||||
public bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
|
||||
{
|
||||
//موقت
|
||||
// دادمهرگستر 11
|
||||
//585 کاشی گالری سرامیس (بابک ابراهیمی )
|
||||
//آموزشگاه ملل 604
|
||||
//کاریابی ملل 605
|
||||
//368 پیتزا امیر آماده سازی
|
||||
//367 پیتزا امیر رستوران
|
||||
//286 مرکز توان بخشی رسالت
|
||||
bool skipRollCallByWorkshopId = workshopId is 11 or 585 or 604 or 605 or 368 or 367 or 286;
|
||||
public bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
|
||||
{
|
||||
//موقت
|
||||
// دادمهرگستر 11
|
||||
//585 کاشی گالری سرامیس (بابک ابراهیمی )
|
||||
//آموزشگاه ملل 604
|
||||
//کاریابی ملل 605
|
||||
//368 پیتزا امیر آماده سازی
|
||||
//367 پیتزا امیر رستوران
|
||||
//286 مرکز توان بخشی رسالت
|
||||
bool skipRollCallByWorkshopId = workshopId is 11 or 585 or 604 or 605 or 368 or 367 or 286;
|
||||
|
||||
//#if DEBUG
|
||||
// skipRollCallByWorkshopId = workshopId is 11 or 585 or 604 or 605 or 368 or 367;
|
||||
//#endif
|
||||
if (skipRollCallByWorkshopId)
|
||||
return false;
|
||||
//#if DEBUG
|
||||
// skipRollCallByWorkshopId = workshopId is 11 or 585 or 604 or 605 or 368 or 367;
|
||||
//#endif
|
||||
if (skipRollCallByWorkshopId)
|
||||
return false;
|
||||
|
||||
|
||||
// 42550 مصطفی مقدس نژاد فومنی
|
||||
bool skipRollCallByEmployeeId = employeeId is 42550;
|
||||
if (skipRollCallByEmployeeId)
|
||||
return false;
|
||||
// 42550 مصطفی مقدس نژاد فومنی
|
||||
bool skipRollCallByEmployeeId = employeeId is 42550;
|
||||
if (skipRollCallByEmployeeId)
|
||||
return false;
|
||||
|
||||
|
||||
var service = _rollCallServiceRepository.GetAllServiceByWorkshopId(workshopId);
|
||||
var service = _rollCallServiceRepository.GetAllServiceByWorkshopId(workshopId);
|
||||
|
||||
if (!service.Any(x => x.StartService.Date <= contractStart.Date && x.EndService.Date >= contractEnd.Date))
|
||||
return false;
|
||||
var rollCallEmployee =
|
||||
_rollCallEmployeeRepository.GetByEmployeeIdAndWorkshopId(employeeId,workshopId);
|
||||
if (!service.Any(x => x.StartService.Date <= contractStart.Date && x.EndService.Date >= contractEnd.Date))
|
||||
return false;
|
||||
var rollCallEmployee =
|
||||
_rollCallEmployeeRepository.GetByEmployeeIdAndWorkshopId(employeeId, workshopId);
|
||||
|
||||
if (rollCallEmployee == null)
|
||||
return false;
|
||||
if (rollCallEmployee == null)
|
||||
return false;
|
||||
|
||||
return _employeeRollCallStatusRepository.Exists(x => x.RollCallEmployeeId == rollCallEmployee.Id &&
|
||||
x.StartDate.Date <= contractStart.Date &&
|
||||
x.EndDate.Date >= contractEnd.Date);
|
||||
}
|
||||
return _employeeRollCallStatusRepository.Exists(x => x.RollCallEmployeeId == rollCallEmployee.Id &&
|
||||
x.StartDate.Date <= contractStart.Date &&
|
||||
x.EndDate.Date >= contractEnd.Date);
|
||||
}
|
||||
|
||||
public List<RollCallEmployeeStatusViewModel> GetActiveByWorkshopIdInDate(long workshopId, DateTime startDateGr, DateTime endDateGr)
|
||||
{
|
||||
return _employeeRollCallStatusRepository.GetActiveByWorkshopIdInDate(workshopId, startDateGr, endDateGr);
|
||||
}
|
||||
public List<RollCallEmployeeStatusViewModel> GetActiveByWorkshopIdInDate(long workshopId, DateTime startDateGr, DateTime endDateGr)
|
||||
{
|
||||
return _employeeRollCallStatusRepository.GetActiveByWorkshopIdInDate(workshopId, startDateGr, endDateGr);
|
||||
}
|
||||
|
||||
public OperationResult Deactivate(long id)
|
||||
public OperationResult Deactivate(long id)
|
||||
{
|
||||
OperationResult op = new();
|
||||
RollCallEmployeeStatus entity = _employeeRollCallStatusRepository.Get(id);
|
||||
|
||||
Reference in New Issue
Block a user