Ejemplo n.º 1
0
 private static DeptWiseAttendanceDTO CreateAttendanceDTO(IGrouping<int, ActivityLogDTO> grp, IEnumerable<Employee> allEmployees)
 {
     var deptMembers = allEmployees.Where(e => e.Deprtment.Id == grp.First().Department.Id);
     var dto = new DeptWiseAttendanceDTO
     {
         DepartmentName = grp.First().Department.Name,
         Attendance = grp.GroupBy(gd => gd.Employee.Id)
                         .Select(empGroup => new AttendanceDTO
                         {
                             EmployeeName = empGroup.First().Employee.Name,
                             EmployeeId = empGroup.First().Employee.Id,
                             Attended = true,
                             Date = empGroup.First().TimeStamp.ToString("yyyy-MM-dd")
                         })
                         .ToList()
     };
     var absents = deptMembers.Where(m => !dto.Attendance.Any(a => a.EmployeeId == m.Id));
     var date = dto.Attendance.First().Date;
     dto.Attendance.AddRange(absents.Select(a => new AttendanceDTO
                         {
                             EmployeeName = a.Name,
                             EmployeeId = a.Id,
                             Attended = false,
                             Date = date
                         }));
     return dto;
 }
        //to be mailed in real
        void DispatchDepartmentAttendenceReport(DeptWiseAttendanceDTO logs)
        {
            var filename = string.Format("AttendenceReport_{0}_{1}.txt", logs.DepartmentName, DateTime.Now.ToString("yyyyMMdd_hhmmss"));
            var logfilepath = Path.Combine(ConfigHelper.GetHRSharedDrivePath(), filename);

            var report = new List<string>();
            report.Add("Department : " + logs.DepartmentName);
            report.Add("Date : " + DateTime.Now.ToLongDateString());
            report.Add("==========================================");
            foreach (var log in logs.Attendance)
            {
                report.Add(log.ToString());
            }

            File.WriteAllLines(logfilepath, report);
        }