Exemplo n.º 1
0
        public ActionResult GetPermissionDetail(Int64?paramUserId, string reqUsr, string startDate, string endDate, bool OnlyReportedToMe)
        {
            IList <PermissionDetailsModel> LeaveRequests = null;
            DateTime?startDateFormatted = null;
            DateTime?endDateFormatted   = null;

            if (startDate != "")
            {
                try
                {
                    startDateFormatted = DateTime.Parse(startDate, new CultureInfo("en-GB", true));
                    endDateFormatted   = DateTime.Parse(endDate, new CultureInfo("en-GB", true));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            if (startDate == "" || endDate == "")
            {
                startDateFormatted = System.DateTime.Now.Date;
                endDateFormatted   = System.DateTime.Now.Date;
            }
            using (var client = new LeaveClient())
            {
                LeaveRequests = client.GetPermissionDetail(paramUserId, reqUsr, startDateFormatted, endDateFormatted, OnlyReportedToMe, UserId);
            }
            for (int i = 0; i < LeaveRequests.Count; i++)
            {
                if (LeaveRequests[i].Reason != null)
                {
                    if (LeaveRequests[i].Reason.Length > 12)
                    {
                        LeaveRequests[i].ReasonShort = LeaveRequests[i].Reason.Substring(0, 12) + "...";
                    }
                    else
                    {
                        LeaveRequests[i].ReasonShort = LeaveRequests[i].Reason;
                    }
                }
                if (LeaveRequests[i].ApproverComments != null)
                {
                    if (LeaveRequests[i].ApproverComments.Length > 12)
                    {
                        LeaveRequests[i].CommentsShort = LeaveRequests[i].ApproverComments.Substring(0, 12) + "...";
                    }
                    else
                    {
                        LeaveRequests[i].CommentsShort = LeaveRequests[i].ApproverComments;
                    }
                }
                if (LeaveRequests[i].PermissionType.Contains('-'))
                {
                    string[] strPermissionType = LeaveRequests[i].PermissionType.Split('-');
                    LeaveRequests[i].PermissionType = strPermissionType[1].ToString().Trim();
                }
            }
            return(PartialView("ViewPermissionDetailPartial", LeaveRequests));
        }
Exemplo n.º 2
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));
            }
        }