Example #1
0
        public ActionResult ExportPermissionsExcel(PermissionQueryModel qryMdl, string RequestLevelPerson)
        {
            IList <PermissionDetailsModel> LeaveRequests = null;

            DateTime?startDateFormatted = null;
            DateTime?endDateFormatted   = null;
            string   startDate          = qryMdl.DateRange.Substring(0, 10);
            string   endDate            = qryMdl.DateRange.Substring(12);

            if (startDate != "")
            {
                try
                {
                    startDateFormatted = DateTime.Parse(startDate, new CultureInfo("en-GB", true));
                    endDateFormatted   = DateTime.Parse(endDate, new CultureInfo("en-GB", true));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            using (var client = new LeaveClient())
            {
                LeaveRequests = client.GetPermissionDetail(qryMdl.SearchUserID, RequestLevelPerson, startDateFormatted, endDateFormatted, qryMdl.OnlyReportedToMe, UserId);
            }
            List <PermissionDetailsModel> excelData = new List <PermissionDetailsModel>();

            excelData = LeaveRequests.ToList();
            if (excelData.Count > 0)
            {
                string[] columns     = { "EmpId", "Name", "Month", "PermissionType", "PermissionDate", "TimeFrom", "TimeTo", "Duration", "Reason", "Status", "ApproverComments" };
                byte[]   filecontent = ExcelExportHelper.ExportPermissionsExcel(excelData, "", false, columns);
                return(File(filecontent, ExcelExportHelper.ExcelContentType, "PermissionsReport_" + System.DateTime.Now + ".xlsx"));
            }
            else
            {
                ViewBag.RequestLevelPerson = RequestLevelPerson;
                qryMdl.ErrorMsg            = "Excel file is not generated as no data returned.";
                return(View("DatewisePermissions", qryMdl));
            }
        }