Пример #1
0
        //
        // CUSTOM FUNCTION HERE
        //
        public SupportFormData GetInitData(int userID, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };

            SupportFormData data = new SupportFormData();

            data.EmployeeDTOs          = new List <EmployeeDTO>();
            data.CompanyDTOs           = new List <CompanyDTO>();
            data.AnnualLeaveStatusDTOs = new List <AnnualLeaveStatusDTO>();
            try
            {
                using (AnnualLeaveMngEntities context = CreateContext())
                {
                    data.EmployeeDTOs          = converter.DB2DTO_EmployeeDTO(context.AnnualLeaveMng_Employee_View.ToList());
                    data.AnnualLeaveStatusDTOs = converter.DB2DTO_AnnualLeaveStatusDTO(context.AnnualLeaveMng_AnnualLeaveStatus_View.ToList());
                    data.CompanyDTOs           = converter.DB2DTO_CompanyDTO(context.AnnualLeaveMng_Company_View.ToList());
                }

                return(data);
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;

                return(data);
            }
        }
Пример #2
0
        public DTO.EditFormData GetData(int userId, int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.AnnualLeaveTrackingDTO = new AnnualLeaveTrackingDTO();
            data.EmployeeDTOs           = new List <EmployeeDTO>();
            data.AnnualLeaveTypeDTOs    = new List <AnnualLeaveTypeDTO>();
            data.AnnualLeaveStatusDTOs  = new List <AnnualLeaveStatusDTO>();

            //try to get data
            try
            {
                using (AnnualLeaveMngEntities context = CreateContext())
                {
                    if (id > 0)
                    {
                        data.AnnualLeaveTrackingDTO = converter.DB2DTO_AnnualLeaveTrackingDTO(context.AnnualLeaveMng_AnnualLeaveTracking_View
                                                                                              .Include("AnnualLeaveMng_AnnualLeaveTrackingDetail_View")
                                                                                              .FirstOrDefault(o => o.AnnualLeaveTrackingID == id));
                    }

                    int?companyId = frameworkFactory.GetCompanyID(userId);

                    data.EmployeeDTOs          = converter.DB2DTO_EmployeeDTO(context.AnnualLeaveMng_Employee_View.Where(s => s.CompanyID == companyId.Value).ToList());
                    data.AnnualLeaveTypeDTOs   = converter.DB2DTO_AnnualLeaveTypeDTO(context.AnnualLeaveMng_AnnualLeaveType_View.ToList());
                    data.AnnualLeaveStatusDTOs = converter.DB2DTO_AnnualLeaveStatusDTO(context.AnnualLeaveMng_AnnualLeaveStatus_View.ToList());

                    if (id == 0)
                    {
                        data.AnnualLeaveTrackingDTO.StatusUpdatedBy           = userId;
                        data.AnnualLeaveTrackingDTO.StatusUpdatedEmployeeIDBy = data.EmployeeDTOs.Where(s => s.UserID == userId).FirstOrDefault().EmployeeID;
                    }
                    else
                    {
                        data.AnnualLeaveTrackingDTO.StatusUpdatedEmployeeIDBy = data.EmployeeDTOs.Where(s => s.UserID == data.AnnualLeaveTrackingDTO.StatusUpdatedBy).FirstOrDefault().EmployeeID;
                    }

                    data.AnnualLeaveTrackingDTO.EmployeeLoginID = data.EmployeeDTOs.Where(s => s.UserID == userId).FirstOrDefault().EmployeeID;
                    //bind time range
                    var compnayInfo = context.AnnualLeaveMng_Company_View.Where(s => s.CompanyID == companyId.Value).FirstOrDefault();
                    data.FromTimeRange = new List <string>();
                    data.FromTimeRange.Add(compnayInfo.MorningShiftFrom);
                    data.FromTimeRange.Add(compnayInfo.AfternoonShiftFrom);
                    data.ToTimeRange = new List <string>();
                    data.ToTimeRange.Add(compnayInfo.MorningShiftTo);
                    data.ToTimeRange.Add(compnayInfo.AfternoonShiftTo);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Пример #3
0
        public DTO.SearchFormData GetDataWithFilter(int userID, System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <AnnualLeaveSearchResultDTO> ();

            totalRows = 0;

            string EmployeeNM = null;
            int?   StatusID   = null;
            string CompanyNM  = null;
            string FromDate   = null;
            string ToDate     = null;
            bool?  HasLeft    = false;

            if (filters.ContainsKey("employeeNM") && filters["employeeNM"] != null && !string.IsNullOrEmpty(filters["employeeNM"].ToString()))
            {
                EmployeeNM = filters["employeeNM"].ToString();
            }
            if (filters.ContainsKey("statusID") && filters["statusID"] != null && !string.IsNullOrEmpty(filters["statusID"].ToString()))
            {
                StatusID = Convert.ToInt32(filters["statusID"].ToString());
            }
            if (filters.ContainsKey("companyNM") && filters["companyNM"] != null && !string.IsNullOrEmpty(filters["companyNM"].ToString()))
            {
                CompanyNM = filters["companyNM"].ToString();
            }
            if (filters.ContainsKey("fromDate") && filters["fromDate"] != null && !string.IsNullOrEmpty(filters["fromDate"].ToString()))
            {
                FromDate = filters["fromDate"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("toDate") && filters["toDate"] != null && !string.IsNullOrEmpty(filters["toDate"].ToString()))
            {
                ToDate = filters["toDate"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("HasLeft") && filters["HasLeft"] != null && !string.IsNullOrEmpty(filters["HasLeft"].ToString()))
            {
                HasLeft = (filters["HasLeft"].ToString() == "true") ? true : false;
            }

            DateTime?_fromDate = FromDate.ConvertStringToDateTime();
            DateTime?_toDate   = ToDate.ConvertStringToDateTime();

            //try to get data
            try
            {
                using (AnnualLeaveMngEntities context = CreateContext())
                {
                    int?companyID = frameworkFactory.GetCompanyID(userID);
                    var result    = context.AnnualLeaveMng_function_SearchAnnualLeave(EmployeeNM, StatusID, CompanyNM, _fromDate, _toDate, HasLeft, orderBy, orderDirection).Where(o => o.CompanyID == companyID).ToList();
                    totalRows = result.Count();

                    data.Data = converter.DB2DTO_AnnualLeaveSearchResult(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }