public List <EmployeeListDTO> EmployeeList(string searchKey = null) { Employee[] employees = null; var today = DateTime.UtcNow; var statusApprovedID = _vacationStatuses.GetByType(VacationStatusTypeEnum.Approved.ToString()).VacationStatusTypeID; var vacations = _vacations.Get(x => x.VacationStatusTypeID.Equals(statusApprovedID)); var result = new List <EmployeeListDTO>(); if (searchKey != null) { bool whereLinq(Employee emp) => (string.Format($"{emp.Name} {emp.Surname}").ToLower().Contains(searchKey.ToLower()) || emp.PhoneNumber.ToLower().Contains(searchKey.ToLower()) || emp.WorkEmail.ToLower().Contains(searchKey.ToLower())) && emp.Status; employees = _employees.Get(whereLinq); } else { employees = _employees.Get(x => x.Status); } foreach (var employee in employees) { if (employee.EmployeesTeam.Count == 0) { var temp = Mapper.Map <Employee, EmployeeForListDTO>(employee); temp.CurrentVacationID = vacations.FirstOrDefault(x => x.EmployeeID.Equals(temp.EmployeeID) && x.DateOfBegin.Date <= today && x.DateOfEnd.Date >= today)?.VacationID; result.Add(new EmployeeListDTO { EmployeeDto = temp, TeamDto = new TeamDTO { TeamID = "Empty", TeamLeadID = "Empty", TeamName = "Empty" } }); } else { foreach (var team in employee.EmployeesTeam) { var temp = Mapper.Map <Employee, EmployeeForListDTO>(employee); temp.CurrentVacationID = vacations.FirstOrDefault(x => x.EmployeeID.Equals(temp.EmployeeID) && x.DateOfBegin.Date <= today && x.DateOfEnd.Date >= today)?.VacationID; result.Add(new EmployeeListDTO { EmployeeDto = temp, TeamDto = new TeamDTO { TeamID = team.TeamID, TeamLeadID = team.TeamLeadID, TeamName = team.TeamName } }); } } } return(result.OrderBy(x => FunctionHelper.EmployeeSortFunc(x.TeamDto.TeamName)).ToList()); }
public void ApproveVacation(RequestProcessResultDTO result) { var vacation = _vacations.GetById(result.VacationID); var employee = _employees.GetById(result.EmployeeID); if (vacation != null && employee != null) { using (TransactionScope scope = new TransactionScope()) { var transaction = new VacationsDAL.Entities.Transaction { BalanceChange = result.Duration, Discription = result.Discription ?? Empty, EmployeeID = result.EmployeeID, TransactionDate = DateTime.UtcNow, TransactionTypeID = _transactionTypes.GetByType(TransactionTypeEnum.VacationApprove.ToString()).TransactionTypeID, TransactionID = Guid.NewGuid().ToString() }; _transactions.Add(transaction); vacation.Duration = result.Duration; vacation.DateOfBegin = result.DateOfBegin; vacation.DateOfEnd = result.DateOfEnd; vacation.ProcessedByID = ReviewerID; vacation.TransactionID = transaction.TransactionID; vacation.VacationStatusTypeID = _vacationStatusTypes.GetByType(VacationStatusTypeEnum.Approved.ToString()).VacationStatusTypeID; _vacations.Update(vacation); employee.VacationBalance -= result.Duration; _employees.Update(); _emailService.SendAsync(employee.WorkEmail, $"{employee.Name} {employee.Surname}", "Vacation request.", "Your vacation request was approved.", $"{employee.Name} {employee.Surname}, your vacation request from {vacation.DateOfBegin.ToString("dd-MM-yyyy")} to {vacation.DateOfEnd.ToString("dd-MM-yyyy")} was approved. Have a nice vacation."); scope.Complete(); } } }
public string GetStatusIdByType(string type) { return(_vacationStatusTypes.GetByType(type).VacationStatusTypeID); }