public ActionResult Index(Users users, HttpPostedFileBase upload)
        {
            string userkey = ConfigurationManager.AppSettings["userkey"];
            string EPCOSS  = ConfigurationManager.AppSettings["EPCOSS"];

            ViewBag.EPCOSS = EPCOSS;
            string uid         = ConfigurationManager.AppSettings["uid"];
            string EMPLOYER_ID = (string)Session["EMPLOYER_ID"];
            string LoginUser   = (string)Session["LoginSAPID"];
            //Session.Remove("StatusMsg");

            DataTable dt = new DataTable();

            if (upload != null && upload.ContentLength > 0)
            {
                if (upload.FileName.EndsWith(".csv"))
                {
                    StreamReader streamCsv = new StreamReader(upload.InputStream);
                    string       csvDataLine = ""; int CurrentLine = 0; int statusLine = 0;
                    string[]     ScheduleData = null;
                    //string listCreated = "";

                    dt.Columns.Add("S/N", typeof(string));
                    dt.Columns.Add("Client Name", typeof(string));
                    dt.Columns.Add("RSAPIN", typeof(string));
                    dt.Columns.Add("Employee Mandatory", typeof(string));
                    dt.Columns.Add("Employer Mandatory", typeof(string));
                    dt.Columns.Add("Employee VC", typeof(string));
                    dt.Columns.Add("Employer VC", typeof(string));
                    dt.Columns.Add("Total", typeof(string));
                    dt.Columns.Add("Error Status", typeof(string));
                    dt.Columns.Add("Comment", typeof(string));

                    csvDataLine = streamCsv.ReadLine();
                    Employer.Employer employer = new Employer.Employer();
                    try
                    {
                        while ((csvDataLine = streamCsv.ReadLine()) != null)
                        {
                            if (CurrentLine != 1)
                            {
                                ScheduleData = csvDataLine.Split(',');
                                var validationStatus = employer.ValidateSchedule(ScheduleData[1], ScheduleData[2], ScheduleData[3], ScheduleData[4], ScheduleData[5], ScheduleData[6], ScheduleData[7], EMPLOYER_ID, userkey, uid);
                                var statusMessage    = validationStatus.Split('~');
                                if (statusMessage[9] == "true")
                                {
                                    statusLine += 1;
                                }
                                dt.Rows.Add(ScheduleData[0], ScheduleData[1], ScheduleData[2], ScheduleData[3], ScheduleData[4], ScheduleData[5], ScheduleData[6], ScheduleData[7], statusMessage[9], statusMessage[10]);
                            }
                        }
                        dt.Rows.Add();
                        dt.Rows.Add("Error Count", statusLine);
                        CurrentLine += 1;

                        Session["StatusMsg"] = statusLine;

                        WriteExcelWithNPOI(dt, "xlsx");
                        return(RedirectToAction("Index"));
                        //return View();
                    }
                    catch (Exception ex)
                    {
                        LogError logerror = new LogError();
                        logerror.ErrorLog("", LoginUser, "", "Schedules/Index", "Schedules", "Index", "ValidateSchedule Error", ex.Message.ToString(), 0);
                        TempData["error"] = ex.Message.ToString();
                        return(View());
                    }
                }
                else
                {
                    TempData["error"] = "Invalid File Type (Only accepts .csv filetype)";
                    return(View());
                }
            }
            else
            {
                TempData["error"] = "Invalid File Type (Only accepts .csv filetype)";
                return(View());
            }
        }
        public JsonResult ValidateAESSchedules()
        {
            string userkey     = ConfigurationManager.AppSettings["userkey"];
            string uid         = ConfigurationManager.AppSettings["uid"];
            string EMPLOYER_ID = (string)Session["EMPLOYER_ID"];
            string LoginUser   = (string)Session["LoginSAPID"];

            var file = Request.Files["UploadedImage"];

            DataTable dt = new DataTable();

            if (file != null && file.ContentLength > 0)
            {
                if (file.FileName.EndsWith(".csv"))
                {
                    StreamReader streamCsv = new StreamReader(file.InputStream);
                    string       csvDataLine = ""; int CurrentLine = 0;
                    string[]     ScheduleData = null;
                    //string listCreated = "";

                    dt.Columns.Add("S/N", typeof(string));
                    dt.Columns.Add("Client Name", typeof(string));
                    dt.Columns.Add("RSAPIN", typeof(string));
                    dt.Columns.Add("Employee Mandatory", typeof(string));
                    dt.Columns.Add("Employer Mandatory", typeof(string));
                    dt.Columns.Add("Employee VC", typeof(string));
                    dt.Columns.Add("Employer VC", typeof(string));
                    dt.Columns.Add("Total", typeof(string));
                    dt.Columns.Add("Error Status", typeof(string));
                    dt.Columns.Add("Comment", typeof(string));

                    csvDataLine = streamCsv.ReadLine();
                    Employer.Employer employer = new Employer.Employer();
                    try
                    {
                        while ((csvDataLine = streamCsv.ReadLine()) != null)
                        {
                            if (CurrentLine != 1)
                            {
                                ScheduleData = csvDataLine.Split(',');
                                var validationStatus = employer.ValidateSchedule(ScheduleData[1], ScheduleData[2], ScheduleData[3], ScheduleData[4], ScheduleData[5], ScheduleData[6], ScheduleData[7], EMPLOYER_ID, userkey, uid);
                                var statusMessage    = validationStatus.Split('~');
                                if (statusMessage[9] == "true")
                                {
                                    return(Json(new { data = "Schedules Is faulty " }, JsonRequestBehavior.AllowGet));
                                }
                                //dt.Rows.Add(ScheduleData[0], ScheduleData[1], ScheduleData[2], ScheduleData[3], ScheduleData[4], ScheduleData[5], ScheduleData[6], ScheduleData[7], statusMessage[9], statusMessage[10]);
                            }
                        }
                        CurrentLine += 1;
                        //ViewBag.dat = dt;
                        //WriteExcelWithNPOI(dt, "xlsx");

                        return(Json(new { data = "Schedule Validation successful" }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception ex)
                    {
                        LogError logerror = new LogError();
                        logerror.ErrorLog("", LoginUser, "", "Schedules/Index", "Schedules", "Index", "ValidateSchedule Error", ex.Message.ToString(), 0);
                        return(Json(new { data = ex.Message.ToString() }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { data = "Invalid File Type (Only accepts .csv filetype" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { data = "Invalid File Type (Only accepts .csv filetype" }, JsonRequestBehavior.AllowGet));
            }
        }