Example #1
0
        public ActionResult ExportAttendanceToExcel(EmployeeAttendanceQueryModel EmployeeAttendanceQueryModelObj, string RequestLevelPerson)
        {
            List <EmployeeAttendanceModel> excelData = GetEmployeeAttendanceList(EmployeeAttendanceQueryModelObj.UserID.ToString(), (EmployeeAttendanceQueryModelObj.FromDate == DateTime.MinValue ? "" : EmployeeAttendanceQueryModelObj.FromDate.ToString()),
                                                                                 (EmployeeAttendanceQueryModelObj.ToDate == DateTime.MinValue ? "" : EmployeeAttendanceQueryModelObj.ToDate.ToString()), RequestLevelPerson, EmployeeAttendanceQueryModelObj.DirectEmployees, true).ToList();

            if (excelData.Count > 0)
            {
                List <string> columns = new List <string>()
                {
                    "AttendanceDate", "InOutTime", "InOut", "Name", "BreakDuration"
                };
                // string fileName = "Attendance.xlsx";
                string fileName = string.Format("Attendance_{0}{1}", DateTime.Now.ToString("ddMMyyyyHHmmss"), ".xlsx");
                if (EmployeeAttendanceQueryModelObj.RequestLevelPerson == "My")
                {
                    columns = new List <string>()
                    {
                        "AttendanceDate", "InOutTime", "InOut", "BreakDuration"
                    };
                }

                byte[] filecontent = ExcelExportHelper.ExportExcelAttendance(excelData, "", false, columns.ToArray());
                return(File(filecontent, ExcelExportHelper.ExcelContentType, fileName));
            }
            else
            {
                ViewBag.RequestLevelPerson = RequestLevelPerson;
                EmployeeAttendanceQueryModel data = new EmployeeAttendanceQueryModel
                {
                    ErrorMsg = "Excel file is not generated as no data returned."
                };
                return(View("~/Views/Attendance/MyAttendance.cshtml", data));
            }
        }