Example #1
0
 public string ReportingToName(Int64 userId)
 {
     using (var dac = new EmployeeDac())
     {
         return(dac.ReportingToName(userId));
     }
 }
Example #2
0
        public EmpShift GetEmployeeShiftDetails(Int64 UserId, string RequestMenuUser, long LeaduserId)
        {
            EmpShift retModel = new EmpShift();

            try
            {
                using (var context = new NLTDDbContext())
                {
                    EmployeeDac employeeDac = new EmployeeDac();
                    long        userId = 0; string EmpId = "";
                    string      Name = "";

                    if (RequestMenuUser != "My")
                    {
                        var empPrf = context.Employee
                                     .Where(x => x.UserId == UserId)
                                     .FirstOrDefault();
                        if (empPrf != null)
                        {
                            userId = empPrf.UserId;
                            EmpId  = empPrf.EmployeeId;
                            Name   = empPrf.FirstName + " " + empPrf.LastName;
                        }
                    }
                    else
                    {
                        var empPrf = context.Employee.Where(x => (x.UserId) == LeaduserId).FirstOrDefault();
                        if (empPrf != null)
                        {
                            userId = empPrf.UserId;
                            EmpId  = empPrf.EmployeeId;
                            Name   = empPrf.FirstName + " " + empPrf.LastName;
                        }
                    }

                    if (userId > 0 || (RequestMenuUser == "My" && LeaduserId > 0))
                    {
                        string ReportingTo = (RequestMenuUser == "My" && LeaduserId > 0) ? employeeDac.ReportingToName(LeaduserId) : employeeDac.ReportingToName(userId);

                        string leadRole = employeeDac.GetEmployeeRole(LeaduserId);

                        List <ShiftAllocation> shiftDetails = new List <ShiftAllocation>();
                        if (RequestMenuUser == "My")
                        {
                            shiftDetails = GetShiftDetails(context, LeaduserId);
                        }
                        else if (leadRole == "ADMIN" || leadRole == "HR")
                        {
                            shiftDetails = GetShiftDetails(context, userId);
                        }
                        else if (RequestMenuUser == "Team")
                        {
                            var user = (from e in context.Employee
                                        where e.ReportingToId == LeaduserId
                                        select e).ToList();

                            var found = LeaveTransactionHistoryDac.FindControlRecursively(user, userId);
                            if (found != null)
                            {
                                shiftDetails = GetShiftDetails(context, userId);
                            }
                        }

                        var groupedLeaveList = shiftDetails.GroupBy(u => u.Month)
                                               .Select(grp => new { Month = grp.Key, shiftAllocation = grp.ToList() })
                                               .ToList();

                        List <ShiftDetail> lstshiftDetails = (from gv in groupedLeaveList
                                                              select new ShiftDetail
                        {
                            Month = gv.Month,
                            shiftAllocation = gv.shiftAllocation
                        }).ToList();
                        retModel.shiftDetail = lstshiftDetails;
                        retModel.ReportingTo = ReportingTo;

                        var lstShift = context.ShiftMaster.AsEnumerable().OrderBy(x => x.FromTime).Select(s => new Shifts
                        {
                            ShiftId   = s.ShiftID,
                            ShiftName = string.Format("{0:hh\\:mm}", s.FromTime) + " - " + string.Format("{0:hh\\:mm}", s.ToTime),
                        }).ToList();

                        retModel.Shifts = lstShift;
                    }

                    retModel.Name   = Name;
                    retModel.EmpId  = EmpId;
                    retModel.UserId = userId;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(retModel);
        }
        public IList <LeaveTransactionDetail> GetTransactionLog(string Name, string RequestMenuUser, long leadUserId)
        {
            IList <LeaveTransactionDetail> retModel = new List <LeaveTransactionDetail>();
            LeaveDac      lv      = new LeaveDac();
            IList <Int64> empList = lv.GetEmployeesReporting(leadUserId);

            try
            {
                using (var context = new NLTDDbContext())
                {
                    EmployeeDac employeeDac = new EmployeeDac();
                    long        userId      = 0;

                    if (RequestMenuUser != "My")
                    {
                        userId = employeeDac.GetUserId(Name);
                    }

                    if (userId > 0 || (RequestMenuUser == "My" && leadUserId > 0))
                    {
                        string ReportingTo = (RequestMenuUser == "My" && leadUserId > 0) ? employeeDac.ReportingToName(leadUserId) : employeeDac.ReportingToName(userId);

                        List <LeaveTransactionHistoryModel> transactionDetails = new List <LeaveTransactionHistoryModel>();
                        if (RequestMenuUser == "My")
                        {
                            transactionDetails = GetTransactionDetails(context, leadUserId);
                        }
                        if (RequestMenuUser == "Team")
                        {
                            string leadRole = employeeDac.GetEmployeeRole(leadUserId);

                            if (leadRole == "ADMIN" || leadRole == "HR")
                            {
                                transactionDetails = GetTransactionDetails(context, userId);
                            }
                            else
                            {
                                var user = empList.Where(x => x == userId).FirstOrDefault();

                                if (user > 0)
                                {
                                    transactionDetails = GetTransactionDetails(context, userId);
                                }
                            }
                        }

                        var groupedLeaveList = transactionDetails.GroupBy(u => u.LeaveTypeId)
                                               .Select(grp => new { LeaveTypeId = grp.Key, leaveTransactionHistoryModel = grp.ToList() })
                                               .ToList();

                        retModel = (from gv in groupedLeaveList
                                    select new LeaveTransactionDetail
                        {
                            ReportingTo = ReportingTo,
                            LeaveTypeId = gv.LeaveTypeId,
                            LeaveType = gv.leaveTransactionHistoryModel[0].Type,
                            leaveTransactionHistoryModel = gv.leaveTransactionHistoryModel
                        }).ToList();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(retModel);
        }