Exemplo n.º 1
0
        public ActionResult LoadDaywiseLeaves(Int64?paramUserId, string FromDate, string ToDate, bool IsLeaveOnly, bool OnlyReportedToMe, string reqUsr, bool DonotShowRejected)
        {
            DateTime?startDateFormatted = null;
            DateTime?endDateFormatted   = null;

            if (FromDate != null)
            {
                if (FromDate.Trim() != "")
                {
                    startDateFormatted = DateTime.ParseExact(FromDate, "d-M-yyyy", CultureInfo.InvariantCulture);
                    endDateFormatted   = DateTime.ParseExact(ToDate, "d-M-yyyy", CultureInfo.InvariantCulture);
                }
            }
            if (FromDate == "" || ToDate == "")
            {
                startDateFormatted = System.DateTime.Now.Date;
                endDateFormatted   = System.DateTime.Now.Date;
            }
            IList <DaywiseLeaveDtlModel> LeaveRequests = null;

            using (var client = new LeaveClient())
            {
                LeaveRequests = client.GetDaywiseLeaveDtl(startDateFormatted, endDateFormatted, IsLeaveOnly, UserId, OnlyReportedToMe, paramUserId, reqUsr, DonotShowRejected);
            }
            for (int i = 0; i < LeaveRequests.Count; i++)
            {
                if (LeaveRequests[i].LeaveReason != null)
                {
                    if (LeaveRequests[i].LeaveReason.Length > 12)
                    {
                        LeaveRequests[i].ReasonShort = LeaveRequests[i].LeaveReason.Substring(0, 12) + "...";
                    }
                    else
                    {
                        LeaveRequests[i].ReasonShort = LeaveRequests[i].LeaveReason;
                    }
                }
                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;
                    }
                }
            }
            return(PartialView("DaywiseLeaveDateRangeDtlPartial", LeaveRequests));
        }
Exemplo n.º 2
0
        public ActionResult ExportToExcel(DaywiseLeaveQueryModel data, string RequestLevelPerson)
        {
            IList <DaywiseLeaveDtlModel> LeaveRequests = null;
            string   startDate          = data.DateRange.Substring(0, 10);
            string   endDate            = data.DateRange.Substring(12);
            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;
                }
            }
            using (var client = new LeaveClient())
            {
                LeaveRequests = client.GetDaywiseLeaveDtl(startDateFormatted, endDateFormatted, data.IsLeaveOnly, UserId, data.OnlyReportedToMe, data.SearchUserID, RequestLevelPerson, data.DonotShowRejected);
            }
            List <DaywiseLeaveDtlModel> excelData = new List <DaywiseLeaveDtlModel>();

            excelData = LeaveRequests.ToList();
            if (excelData.Count > 0)
            {
                string[] columns     = { "Emp Id", "Name", "Request Type", "Leave Balance", "Request Date", "Part Of Day", "Duration", "Status", "Reason", "Approver Comments" };
                byte[]   filecontent = ExcelExportHelper.ExportExcel(excelData, "", false, columns);
                return(File(filecontent, ExcelExportHelper.ExcelContentType, "DaywiseReport_" + System.DateTime.Now + ".xlsx"));
            }
            else
            {
                ViewBag.RequestLevelPerson = RequestLevelPerson;
                data.ErrorMsg = "Excel file is not generated as no data returned.";
                return(View("DaywiseLeaveDateRangeView", data));
            }
        }