public List <Shifts> GetShiftMaster() { List <Shifts> lstShift = new List <Shifts>(); try { using (var context = new NLTDDbContext()) { lstShift = (from s in context.ShiftMaster.AsEnumerable() select new Shifts { ShiftId = s.ShiftID, ShiftName = s.ShiftDescription, FromTime = s.FromTime, ToTime = s.ToTime, Shift = string.Format("{0:hh\\:mm}", s.FromTime) + " - " + string.Format("{0:hh\\:mm}", s.ToTime) }).ToList(); } } catch (Exception) { throw; } return(lstShift); }
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 Shifts GetShiftMasterWithId(Int64 shiftId) { var objShifts = new Shifts(); try { using (var context = new NLTDDbContext()) { if (shiftId > 0) { objShifts = (from s in context.ShiftMaster where s.ShiftID == shiftId select new Shifts { ShiftId = s.ShiftID, ShiftName = s.ShiftDescription, FromTime = s.FromTime, ToTime = s.ToTime }).SingleOrDefault(); } } } catch (Exception) { throw; } return(objShifts); }
private List <ShiftEmployees> GetEmployees(NLTDDbContext context, Int64 UserId) { var result = new List <ShiftEmployees>(); try { var employees = (from e in context.Employee where e.ReportingToId == UserId && e.IsActive == true select new ShiftEmployees { Name = e.FirstName + " " + e.LastName, EmpId = e.EmployeeId, UserId = e.UserId }).ToList(); foreach (var employee in employees) { result.Add(employee); result.AddRange(GetEmployees(context, employee.UserId)); } } catch (Exception) { throw; } return(result); }
public List <lateAndEarlyRpt> GetLateAndEarlyEmployees(DateTime FromDate, DateTime ToDate, Int64 UserId, bool OnlyReportedToMe) { List <lateAndEarlyRpt> lateAndEarlyRpt = new List <lateAndEarlyRpt>(); try { ToDate = ToDate.AddDays(1); using (var context = new NLTDDbContext()) { List <TimeSheetModel> timeSheetModelList = new List <TimeSheetModel>(); TimeSheetDac timeSheetDac = new TimeSheetDac(); List <TimeSheetModel> timeSheetModelListTemp = timeSheetDac.GetMyTeamTimeSheet(UserId, FromDate, ToDate, OnlyReportedToMe); timeSheetModelList.AddRange(timeSheetModelListTemp); var shiftQueryModelList = (from sm in context.ShiftMaster join smp in context.ShiftMapping on sm.ShiftID equals smp.ShiftID join e in context.Employee on smp.UserID equals e.UserId where smp.UserID == UserId && smp.ShiftDate >= FromDate && smp.ShiftDate <= ToDate select new ShiftQueryModel { UserID = smp.UserID, Employeename = e.FirstName + " " + e.LastName, ShiftFromtime = sm.FromTime, ShiftTotime = sm.ToTime, ShiftDate = smp.ShiftDate, }).ToList(); } } catch (Exception) { throw; } return(lateAndEarlyRpt); }
public string SaveShiftMaster(int shiftId, string shiftName, TimeSpan fromTime, TimeSpan toTime, Int64 mgrId) { try { int isSaved = 0; using (var context = new NLTDDbContext()) { var exists = context.ShiftMaster.Where(c => c.FromTime == fromTime && c.ToTime == toTime && c.ShiftID != shiftId).ToList(); if (exists != null && exists.Count > 0) { return("Shift Already Available."); } else { var objShiftMaster = context.ShiftMaster.Where(c => c.ShiftID == shiftId).SingleOrDefault(); if (objShiftMaster != null) { objShiftMaster = context.ShiftMaster.Where(c => c.ShiftID == shiftId).Single(); objShiftMaster.ShiftID = shiftId; objShiftMaster.ShiftDescription = shiftName; objShiftMaster.FromTime = fromTime; objShiftMaster.ToTime = toTime; } else { objShiftMaster = new ShiftMaster { ShiftDescription = shiftName, FromTime = fromTime, ToTime = toTime, CreatedBy = mgrId, CreatedDate = DateTime.Now }; } context.ShiftMaster.AddOrUpdate(objShiftMaster); isSaved = context.SaveChanges(); } } return(isSaved > 0 ? "Saved" : "Failed"); } catch (Exception ex) { return(ex.Message); } }
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); }
private List <ShiftAllocation> GetShiftEmployees(NLTDDbContext context, Int64 UserId) { var result = new List <ShiftAllocation>(); try { var emp = (from e in context.Employee where e.ReportingToId == UserId && e.IsActive == true select e.UserId).ToList(); var employees = (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.ReportingToId == UserId && 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(); if (employees != null && employees.Count > 0) { result.AddRange(employees); } foreach (Int64 id in emp) { result.AddRange(GetShiftEmployees(context, id)); } } catch (Exception) { throw; } return(result); }
public List <ShiftAllocation> GetShiftDetails(NLTDDbContext context, long UserId) { var shiftDetails = (from sm in context.ShiftMapping.AsEnumerable() join s in context.ShiftMaster.AsEnumerable() on sm.ShiftID equals s.ShiftID join e in context.Employee.AsEnumerable() on sm.UserID equals e.UserId where e.UserId == UserId && e.IsActive == true && sm.ShiftDate.Year == DateTime.Now.Year select new ShiftAllocation { Month = sm.ShiftDate.ToString("MMMM"), Year = sm.ShiftDate.Year, UserId = sm.UserID, ShiftID = s.ShiftID, ShiftDate = sm.ShiftDate, FromTime = s.FromTime, ToTime = s.ToTime, ShiftName = s.ShiftDescription, ShiftMappingID = sm.ShiftMappingID }).ToList(); return(shiftDetails); }
public string SaveEmployeeShift(List <Int64> UserId, int Shift, DateTime FromDate, DateTime ToDate, Int64 MgrId) { try { int isSaved = 0; using (var context = new NLTDDbContext()) { var shiftMapping = context.ShiftMapping.Where(c => UserId.Contains(c.UserID) && (c.ShiftDate >= FromDate && c.ShiftDate <= ToDate)).ToList(); shiftMapping.ForEach(u => { u.ShiftID = Shift; u.ModifiedBy = MgrId; u.ModifiedDate = DateTime.Now; }); isSaved = context.SaveChanges(); var shiftTransaction = from id in UserId select new ShiftTransaction { ShiftID = Shift, UserId = id, CreatedBy = MgrId, Createddate = DateTime.Now, FromDate = FromDate, ToDate = ToDate }; context.ShiftTransaction.AddRange(shiftTransaction); isSaved = context.SaveChanges(); } return(isSaved > 0 ? "Saved" : "Failed"); } catch (Exception ex) { return(ex.Message); } }
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); }