public List <EmployeeModel> GetAllEmployees()
        {
            List <EmployeeModel> employees = new List <EmployeeModel>();

            try
            {
                var employeeList = _employeeInfoDAL.GetAll().Where(x => x.IsActive).OrderBy(y => y.FullName).ToList();
                foreach (var item in employeeList)
                {
                    employees.Add(new EmployeeModel
                    {
                        EmployeeID           = item.EmployeeID,
                        ID                   = item.ID,
                        Department           = LookupItemHelper.ConvertToModel(item.Department),
                        Location             = LookupItemHelper.ConvertToModel(item.FactoryLocation),
                        DepartmentPermission = item.DepartmentPermission,
                        FullName             = item.FullName,
                        EmployeeType         = item.EmployeeType
                    });
                }
                return(employees);
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - GetAllEmployees - GetManagerByDepartment fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
                return(null);
            }
        }
        /// <summary>
        /// Get manager list with min level
        /// </summary>
        /// <param name="departmentId"></param>
        /// <param name="minLevel"></param>
        /// <returns></returns>
        /// URL: _vti_bin/Services/Employee/EmployeeService.svc/GetManagerByDepartment/5/4
        public List <EmployeeModel> GetManagerByDepartment(string departmentId, string minLevel)
        {
            try
            {
                List <EmployeeModel> employees = new List <EmployeeModel>();
                var employeePositions          = _employeePositionDAL.GetByMinLevel(double.Parse(minLevel, System.Globalization.CultureInfo.InvariantCulture));
                if (employeePositions != null && employeePositions.Count() > 0)
                {
                    var employeePositionIds = employeePositions.Select(x => x.ID).ToList();
                    var employeeList        = _employeeInfoDAL.GetByUserType(true, StringConstant.EmployeeType.ADUser);

                    ////Filter by min level
                    employeeList = employeeList.Where(x => x.Department == null || (x.EmployeeLevel != null && employeePositionIds.Contains(x.EmployeeLevel.LookupId))).ToList();


                    if (!string.IsNullOrEmpty(departmentId) && Convert.ToInt32(departmentId) > 0)
                    {
                        employeeList = employeeList.Where(x => x.Department == null || (x.Department != null && (x.Department.LookupId == 0 || x.Department.LookupId == Convert.ToInt32(departmentId)))).ToList();
                    }

                    foreach (var item in employeeList)
                    {
                        employees.Add(new EmployeeModel
                        {
                            EmployeeID           = item.EmployeeID,
                            ID                   = item.ID,
                            Department           = LookupItemHelper.ConvertToModel(item.Department),
                            Location             = LookupItemHelper.ConvertToModel(item.FactoryLocation),
                            DepartmentPermission = item.DepartmentPermission,
                            FullName             = item.FullName,
                            EmployeeType         = item.EmployeeType
                        });
                    }
                }
                return(employees);
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - Employee Service - GetManagerByDepartment fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
                return(null);
            }
        }
 private ShiftTimeModel ConvertToShiftTimeModel(Biz.Models.ShiftTime item)
 {
     return(new ShiftTimeModel()
     {
         Id = item.ID,
         Code = item.Code,
         Name = item.Name,
         Depscription = item.Description,
         WorkingHourFromHour = item.WorkingHourFromHour.Hour,
         WorkingHourFromMinute = item.WorkingHourFromHour.Minute,
         WorkingHourToHour = item.WorkingHourToHour.Hour,
         WorkingHourToMinute = item.WorkingHourToHour.Minute,
         BreakHourFromHour = Convert.ToString(item.BreakHourFromHour.Hour),
         BreakHourFromMinute = Convert.ToString(item.BreakHourFromHour.Minute),
         BreakHourToHour = Convert.ToString(item.BreakHourToHour.Hour),
         BreakHourToMinute = Convert.ToString(item.BreakHourToHour.Minute),
         ShiftTimeWorkingHourNumber = item.ShiftTimeWorkingHourNumber,
         ShiftTimeBreakHourNumber = item.ShiftTimeBreakHourNumber,
         UnexpectedLeaveFirstApprovalRole = LookupItemHelper.ConvertToModel(item.UnexpectedLeaveFirstApprovalRole),
         ShiftRequired = item.ShiftRequired
     });
 }
 /// <summary>
 /// Get active Eeployee by locationId & departmentId
 /// </summary>
 /// <param name="locationId"></param>
 /// <param name="departmentId"></param>
 /// <param name="maxLevel"></param>
 /// <returns></returns>
 /// CALL URL: _vti_bin/Services/Employee/EmployeeService.svc/GetByDepartmentLocation/1/1
 public List <EmployeeModel> GetByDepartmentLocation(string locationId, string departmentId, string maxLevel)
 {
     try
     {
         List <EmployeeModel> employees = new List <EmployeeModel>();
         int locationIdValue, departmentIdValue;
         int level = Convert.ToInt32(maxLevel);
         if (int.TryParse(locationId, out locationIdValue) && int.TryParse(departmentId, out departmentIdValue))
         {
             string[] viewFields   = new string[] { EmployeeInfoList.EmployeeIDField, EmployeeInfoList.FullNameField, EmployeeInfoList.DepartmentField, EmployeeInfoList.FactoryLocationField, EmployeeInfoList.EmployeeTypeField, EmployeeInfoList.DepartmentPermissionField };
             var      employeeList = _employeeInfoDAL.GetByLocationAndDepartment(locationIdValue, departmentIdValue, true, level, StringConstant.EmployeeInfoList.FullNameField, viewFields);
             if (employeeList != null)
             {
                 foreach (var item in employeeList)
                 {
                     employees.Add(new EmployeeModel
                     {
                         EmployeeID           = item.EmployeeID,
                         ID                   = item.ID,
                         Department           = LookupItemHelper.ConvertToModel(item.Department),
                         Location             = LookupItemHelper.ConvertToModel(item.FactoryLocation),
                         DepartmentPermission = item.DepartmentPermission,
                         FullName             = item.FullName,
                         EmployeeType         = item.EmployeeType
                     });
                 }
             }
         }
         return(employees);
     }
     catch (Exception ex)
     {
         ULSLogging.Log(new SPDiagnosticsCategory("STADA - Employee Service - GetByDepartmentLocation fn",
                                                  TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                        string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
         return(null);
     }
 }
        public EmployeeModel GetEmployeeByEmployeeID(string id)
        {
            var employee = new EmployeeModel();

            try
            {
                var empItem = _employeeInfoDAL.GetByID(Convert.ToInt32(id));
                if (empItem != null)
                {
                    employee.ID            = empItem.ID;
                    employee.EmployeeType  = empItem.EmployeeType;
                    employee.FullName      = empItem.FullName;
                    employee.EmployeeLevel = LookupItemHelper.ConvertToModel(empItem.EmployeeLevel);
                    //ToDo: Add more property if need
                }
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - Employee Service - GetEmployeeByEmployeeID fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
            }
            return(employee);
        }
        public OverTimeModel GetById(string Id)
        {
            try
            {
                OverTimeModel overTimeModel = new OverTimeModel();
                int           itemId        = Convert.ToInt32(Id);
                var           overtime      = _overTimeManagementDAL.GetByID(itemId);
                if (overtime != null && overtime.ID > 0)
                {
                    overTimeModel.ID = overtime.ID;
                    overTimeModel.OtherRequirements = overtime.OtherRequirements;
                    overTimeModel.DHComments        = overtime.DHComments;
                    overTimeModel.BODComments       = overtime.BODComments;
                    overTimeModel.SecurityComments  = overtime.SecurityComments;
                    overTimeModel.Requester         = LookupItemHelper.ConvertToModel(overtime.Requester);
                    if (overtime.ApprovedBy != null)
                    {
                        overTimeModel.ApprovedBy = new UserModel {
                            FirstName = overtime.ApprovedBy.FirstName, FullName = overtime.ApprovedBy.FullName, ID = overtime.ApprovedBy.ID, IsGroup = overtime.ApprovedBy.IsGroup, LastName = overtime.ApprovedBy.LastName, UserName = overtime.ApprovedBy.UserName
                        };
                    }

                    overTimeModel.SumOfEmployee = overtime.SumOfEmployee + "";
                    overTimeModel.SumOfMeal     = overtime.SumOfMeal + "";

                    overTimeModel.ApprovalStatus   = overtime.ApprovalStatus;
                    overTimeModel.CommonDepartment = LookupItemHelper.ConvertToModel(overtime.CommonDepartment);

                    overTimeModel.Date = overtime.CommonDate.ToString("s");
                    overTimeModel.FirstApprovedDate = overtime.FirstApprovedDate.ToString(StringConstant.DateFormatddMMyyyyHHmmss);
                    overTimeModel.Modified          = overtime.Modified.ToString(StringConstant.DateFormatddMMyyyyHHmmss);
                    if (overtime.FirstApprovedBy != null)
                    {
                        overTimeModel.FirstApprovedBy = new UserModel {
                            FirstName = overtime.FirstApprovedBy.FirstName, FullName = overtime.FirstApprovedBy.FullName, ID = overtime.FirstApprovedBy.ID, IsGroup = overtime.FirstApprovedBy.IsGroup, LastName = overtime.FirstApprovedBy.LastName, UserName = overtime.FirstApprovedBy.UserName
                        };
                    }
                    overTimeModel.CommonLocation = LookupItemHelper.ConvertToModel(overtime.CommonLocation);
                    overTimeModel.Place          = overtime.Place;
                    overTimeModel.ApprovalStatus = overtime.ApprovalStatus;

                    if (overtime.RequestDueDate != null && overtime.RequestDueDate != default(DateTime))
                    {
                        overTimeModel.RequestDueDate = overtime.RequestDueDate.ToString(StringConstant.DateFormatddMMyyyy2);
                        if (overtime.RequestDueDate.Date < DateTime.Now.Date)
                        {
                            //overTimeModel.RequestExpired = true;
                            overTimeModel.RequestExpired = false;
                        }
                    }

                    overTimeModel.ApprovedLevel = 0;
                    if (overTimeModel.ApprovalStatus == "true")
                    {
                        overTimeModel.ApprovedLevel = 1; // Truong phong Approved
                        // Check Approved By: BOD
                        var approverInfo = _employeeInfoDAL.GetByADAccount(overtime.ApprovedBy.ID);
                        if (approverInfo.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.BOD) // BOD Approved
                        {
                            overTimeModel.ApprovedLevel = 2;
                        }
                    }
                    else if (overTimeModel.ApprovalStatus == "false")
                    {
                        overTimeModel.ApprovedLevel = 1; // Truong phong Rejected
                        // Check Approved By: BOD
                        var approverInfo = _employeeInfoDAL.GetByADAccount(overtime.ApprovedBy.ID);
                        if (approverInfo.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.BOD) // BOD Rejected
                        {
                            overTimeModel.ApprovedLevel = 2;
                        }
                    }
                    else // Check Truong phong co duyet chua
                    {
                        // Check Approved By: BOD
                        var approverInfo = _employeeInfoDAL.GetByADAccount(overtime.ApprovedBy.ID);
                        if (approverInfo.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.BOD) // BOD Rejected
                        {
                            overTimeModel.ApprovedLevel = 1;
                        }
                    }


                    var OverTimeDetails = _overTimeManagementDetailDAL.GetByOvertimeId(overTimeModel.ID);
                    foreach (var detail in OverTimeDetails)
                    {
                        var overtimeDetailModel = new OvertimeDetailModel();
                        overtimeDetailModel.ID                         = detail.ID;
                        overtimeDetailModel.OvertimeFrom               = detail.OvertimeFrom.ToString();
                        overtimeDetailModel.OvertimeManagementID       = LookupItemHelper.ConvertToModel(detail.OvertimeManagementID);
                        overtimeDetailModel.Employee.LookupId          = detail.Employee.LookupId;
                        overtimeDetailModel.Employee.LookupValue       = detail.Employee.LookupValue;
                        overtimeDetailModel.OvertimeMgmtApprovalStatus = LookupItemHelper.ConvertToModel(detail.ApprovalStatus);
                        overtimeDetailModel.SummaryLinks               = detail.SummaryLinks;
                        overtimeDetailModel.OvertimeTo                 = detail.OvertimeTo.ToString();
                        overtimeDetailModel.Task                       = string.IsNullOrEmpty(detail.SummaryLinks) ? detail.Task : detail.Task + "_" + detail.SummaryLinks;
                        overtimeDetailModel.CompanyTransport           = detail.CompanyTransport;
                        overtimeDetailModel.WorkingHours               = detail.WorkingHours + "";
                        // Grid
                        overtimeDetailModel.FullName         = overtimeDetailModel.Employee.LookupValue + "_" + overtimeDetailModel.Employee.LookupId + "_";
                        overtimeDetailModel.OvertimeHourFrom = detail.OvertimeFrom.Hour + ":" + detail.OvertimeFrom.Minute;
                        overtimeDetailModel.OvertimeHourTo   = detail.OvertimeTo.Hour + ":" + detail.OvertimeTo.Minute;
                        overTimeModel.OvertimeDetailModelList.Add(overtimeDetailModel);
                    }
                }
                return(overTimeModel);
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - Overtime Service - GetById fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
                return(null);
            }
        }