public List <ShiftEmployees> GetShiftDetailsForUsers(Int64 UserId, string RequestMenuUser) { var lstShiftEmployees = new List <ShiftEmployees>(); try { using (var context = new NLTDDbContext()) { EmployeeDac employeeDac = new EmployeeDac(); string leadRole = employeeDac.GetEmployeeRole(UserId); if (leadRole == "ADMIN" || leadRole == "HR") { lstShiftEmployees = (from e in context.Employee where e.IsActive == true select new ShiftEmployees { Name = e.FirstName + " " + e.LastName, EmpId = e.EmployeeId, UserId = e.UserId }).ToList(); } else { lstShiftEmployees = GetEmployees(context, UserId); } } } catch (Exception) { throw; } return(lstShiftEmployees); }
public List <ShiftAllocation> GetShiftAllocation(Int64 UserId, string RequestMenuUser) { List <ShiftAllocation> lstShiftAllocation = new List <ShiftAllocation>(); try { using (var context = new NLTDDbContext()) { if (RequestMenuUser == "Admin") { EmployeeDac employeeDac = new EmployeeDac(); string leadRole = employeeDac.GetEmployeeRole(UserId); if (leadRole == "ADMIN" || leadRole == "HR") { lstShiftAllocation = (from sm in context.ShiftMapping join s in context.ShiftMaster on sm.ShiftID equals s.ShiftID join e in context.Employee on sm.UserID equals e.UserId where e.IsActive == true select new ShiftAllocation { Name = e.FirstName + " " + e.LastName, EmpId = e.EmployeeId, UserId = sm.UserID, ShiftID = s.ShiftID, ShiftDate = sm.ShiftDate, FromTime = s.FromTime, ToTime = s.ToTime, ShiftName = s.ShiftDescription, IsActive = e.IsActive, ShiftMappingID = sm.ShiftMappingID }).ToList(); } } else { lstShiftAllocation = GetShiftEmployees(context, UserId); } } } catch (Exception) { throw; } return(lstShiftAllocation); }
public List <TimeSheetModel> GetMyTeamTimeSheet(Int64 UserID, DateTime FromDate, DateTime ToDate, bool myDirectEmployees) { List <TimeSheetModel> timeSheetModelList = new List <TimeSheetModel>(); EmployeeDac employeeDac = new EmployeeDac(); string leadRole = employeeDac.GetEmployeeRole(UserID); try { List <EmployeeProfile> employeeProfileListUnderManager = employeeDac.GetReportingEmployeeProfile(UserID, leadRole, myDirectEmployees).OrderBy(m => m.FirstName).ToList(); for (int i = 0; i < employeeProfileListUnderManager.Count; i++) { List <TimeSheetModel> timeSheetModelListTemp = GetMyTimeSheet(employeeProfileListUnderManager[i].UserId, FromDate, ToDate); timeSheetModelList.AddRange(timeSheetModelListTemp); } return(timeSheetModelList); } catch (Exception) { throw; } }
public List <NoOfLateInMonth> GetLateReport(Int64 UserID, DateTime FromDate, DateTime ToDate, bool myDirectEmployees) { List <ReportLateMonth> reportLateMonthlst = new List <ReportLateMonth>(); List <NoOfLateInMonth> noOfLateInMonth = new List <NoOfLateInMonth>(); // To Get all the employee profile under the manager or lead EmployeeDac employeeDac = new EmployeeDac(); string leadRole = employeeDac.GetEmployeeRole(UserID); // To get the employee role, whether he is the Team lead or HR Or admin try { List <EmployeeProfile> employeesUnderManager = employeeDac.GetReportingEmployeeProfile(UserID, leadRole, myDirectEmployees).OrderBy(m => m.FirstName).ToList(); for (int i = 0; i < employeesUnderManager.Count; i++) { string Name = employeesUnderManager[i].FirstName + " " + employeesUnderManager[i].LastName; List <ReportLateMonth> reportLateMonth = GetMyTimeSheet(employeesUnderManager[i].UserId, FromDate, ToDate, employeesUnderManager[i].ReportedToName, Name, employeesUnderManager[i].EmployeeId); reportLateMonthlst.AddRange(reportLateMonth); } noOfLateInMonth = (from p in reportLateMonthlst where p.LateEntry != null group p by new { p.UserID, p.Name, p.ReportingTo, p.EmpId } into g select new NoOfLateInMonth { Name = g.Key.Name, UserID = g.Key.UserID, ReportingTo = g.Key.ReportingTo, EmpId = g.Key.EmpId, NoOfLate = g.Count() }).ToList(); return(noOfLateInMonth); } catch (Exception) { throw; } }
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); }
public string UpdateLeaveBalance(List <EmployeeLeaveBalanceDetails> empLeaveBalanceDetails, Int64 LoginUserId, bool isElCredit = false) { try { int isSaved = 0; using (var context = new NLTDDbContext()) { EmployeeDac employeeDac = new EmployeeDac(); string userRole = string.Empty; if (LoginUserId != 0) { userRole = employeeDac.GetEmployeeRole(LoginUserId); } else { userRole = "System"; } if (userRole == "HR" || userRole == "System") { using (var transaction = context.Database.BeginTransaction()) { int creditYear = Convert.ToDateTime(context.LeaveType.Where(x => x.Type == "Earned Leave").FirstOrDefault().lastCreditRun).Year; foreach (var item in empLeaveBalanceDetails) { if (item.NoOfDays > 0) { EmployeeLeaveBalance leaveBalance; if (isElCredit == false) { leaveBalance = context.EmployeeLeaveBalance.Where(x => x.UserId == item.UserId && x.LeaveTypeId == item.LeaveTypeId && x.LeaveBalanceId == item.LeaveBalanceId && x.Year == DateTime.Now.Year).FirstOrDefault(); } else { leaveBalance = context.EmployeeLeaveBalance.Where(x => x.UserId == item.UserId && x.LeaveTypeId == item.LeaveTypeId && x.LeaveBalanceId == item.LeaveBalanceId && x.Year == creditYear).FirstOrDefault(); } if (leaveBalance != null) { leaveBalance.TotalDays = item.CreditOrDebit == "C" ? (leaveBalance.TotalDays + item.NoOfDays) : (leaveBalance.TotalDays - item.NoOfDays); leaveBalance.ModifiedBy = LoginUserId; leaveBalance.ModifiedOn = DateTime.Now; leaveBalance.BalanceDays = item.TotalDays; isSaved = context.SaveChanges(); } else { leaveBalance = new EmployeeLeaveBalance { UserId = Convert.ToInt64(item.UserId) }; if (isElCredit == false) { leaveBalance.Year = DateTime.Now.Year; } else { leaveBalance.Year = creditYear; } leaveBalance.LeaveTypeId = Convert.ToInt64(item.LeaveTypeId); leaveBalance.TotalDays = item.TotalDays; leaveBalance.LeaveTakenDays = 0; leaveBalance.PendingApprovalDays = 0; leaveBalance.BalanceDays = item.TotalDays; leaveBalance.CreatedBy = LoginUserId; leaveBalance.CreatedOn = DateTime.Now; leaveBalance.ModifiedBy = LoginUserId; leaveBalance.ModifiedOn = DateTime.Now; context.EmployeeLeaveBalance.Add(leaveBalance); isSaved = context.SaveChanges(); } LeaveTransactionHistory leaveTransactionHistory = new LeaveTransactionHistory { UserId = Convert.ToInt64(item.UserId), LeaveTypeId = Convert.ToInt64(item.LeaveTypeId), LeaveId = -1, TransactionDate = DateTime.Now, TransactionType = item.CreditOrDebit, NumberOfDays = item.NoOfDays, TransactionBy = LoginUserId, Remarks = item.Remarks }; context.LeaveTransactionHistory.Add(leaveTransactionHistory); isSaved = context.SaveChanges(); if (isSaved > 0) { continue; } else { break; } } } if (isSaved > 0 && isElCredit == true) { var leaveType = context.LeaveType.Where(x => x.Type.ToUpper() == "EARNED LEAVE").FirstOrDefault(); if (leaveType != null) { leaveType.lastCreditRun = System.DateTime.Now; leaveType.ModifiedBy = LoginUserId; leaveType.Modifiedon = System.DateTime.Now; isSaved = context.SaveChanges(); } } if (isSaved > 0) { transaction.Commit(); } else { transaction.Rollback(); } } } else { return("Need Role"); } } if (isSaved > 0) { return("Saved"); } else { return("Failed"); } } catch (Exception ex) { return(ex.Message); } }