예제 #1
0
        public JsonResult GetBatchDetails([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel, String batchId, String addressId)
        {
            string LoginUser   = (string)Session["LoginSAPID"];
            string userkey     = ConfigurationManager.AppSettings["userkey"];
            string uid         = ConfigurationManager.AppSettings["uid"];
            string CompanyName = (string)Session["CompanyName"];
            string WebUserID   = (string)Session["WebUserID"];
            string EMPLOYER_ID = (string)Session["EMPLOYER_ID"];

            string _access_key = ConfigurationManager.AppSettings["Salt"];

            try
            {
                Employer.Employer employer = new Employer.Employer();

                string dBatchId   = CryptoEngine.DecryptString(batchId, _access_key);
                string dAddressId = CryptoEngine.DecryptString(addressId, _access_key);

                DataTable dt = employer.FetchPINsBatch(CompanyName, EMPLOYER_ID, dBatchId, dAddressId, userkey, uid);
                dt.TableName = "PinsBatch";
                dt.Columns.ToString();

                List <CompanyEmployee> pins = new List <CompanyEmployee>();
                int startRec = requestModel.Start;
                int pageSize = requestModel.Length;

                List <CompanyEmployee> pinCount = (from DataRow dr in dt.Rows
                                                   select new CompanyEmployee()
                {
                    PIN = dr["P_I_N"].ToString(),
                }).ToList();

                pins = (from DataRow dr in dt.Rows
                        select new CompanyEmployee()
                {
                    PIN = dr["P_I_N"].ToString(),
                    FirstName = dr["First Name"].ToString(),
                    LastName = dr["Last Name"].ToString(),
                    MiddleName = dr["Middle Names"].ToString()
                }).Skip(startRec).Take(pageSize).ToList();

                var totalCount    = pinCount.Count();
                var filteredCount = pins.Count();

                if (requestModel.Search.Value != string.Empty)
                {
                    var value = requestModel.Search.Value.ToLower().Trim();

                    pinCount = (from DataRow dr in dt.Rows
                                where dr["P_I_N"].ToString().ToLower().Contains(value) || dr["First Name"].ToString().ToLower().Contains(value) || dr["Last Name"].ToString().ToLower().Contains(value) || dr["Middle Names"].ToString().ToLower().Contains(value)
                                select new CompanyEmployee()
                    {
                        PIN = dr["Category ID"].ToString(),
                    }).ToList();

                    pins = (from DataRow dr in dt.Rows
                            where dr["P_I_N"].ToString().ToLower().Contains(value) || dr["First Name"].ToString().ToLower().Contains(value) || dr["Last Name"].ToString().ToLower().Contains(value) || dr["Middle Names"].ToString().ToLower().Contains(value)
                            select new CompanyEmployee()
                    {
                        PIN = dr["P_I_N"].ToString(),
                        FirstName = dr["First Name"].ToString(),
                        LastName = dr["Last Name"].ToString(),
                        MiddleName = dr["Middle Names"].ToString()
                    }).Skip(startRec).Take(pageSize).ToList();

                    totalCount    = pinCount.Count();
                    filteredCount = pins.Count();
                }

                var sortedColumns = requestModel.Columns.GetSortedColumns();
                var orderByString = String.Empty;

                foreach (var column in sortedColumns)
                {
                    orderByString += orderByString != String.Empty ? "," : "";
                    orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc");
                }

                var data = pins.Select(emList => new
                {
                    PIN        = emList.PIN,
                    FirstName  = emList.FirstName,
                    LastName   = emList.LastName,
                    MiddleName = emList.MiddleName
                }).ToList();

                return(Json(new DataTablesResponse(requestModel.Draw, data, totalCount, totalCount), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogError logerror = new LogError();
                logerror.ErrorLog("", LoginUser, "", "StatementOptions/GetBatchDetails", "StatementOptions", "GetBatchDetails", "FetchPINsBatch Error", ex.Message.ToString(), 0);
                return(Json(new { data = "Error has occured" }, JsonRequestBehavior.AllowGet));
            }
        }