public JsonResult GetEmployers([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)
        {
            string userkey   = ConfigurationManager.AppSettings["userkey"];
            string uid       = ConfigurationManager.AppSettings["uid"];
            string LoginUser = (string)Session["LoginSAPID"];
            string RoleID    = (string)Session["RoleID"];
            string WebUserID = (string)Session["WebUserID"];

            try
            {
                if (RoleID == "1")
                {
                    Employer.Employer employer = new Employer.Employer();
                    DataTable         dt       = employer.FetchCompanies("YES", LoginUser);
                    dt.TableName = "Employer";

                    List <Employers> employerList = new List <Employers>();
                    int startRec = requestModel.Start;
                    int pageSize = requestModel.Length;


                    List <Employers> employerCount = (from DataRow dr in dt.Rows
                                                      select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString(),
                        CompanyName = dr["Company Name"].ToString(),
                    }).ToList();

                    employerList = (from DataRow dr in dt.Rows
                                    select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString(),
                        CompanyName = dr["Company Name"].ToString(),
                        Address1 = dr["Address1"].ToString(),
                        Address2 = dr["Address2"].ToString(),
                        State = dr["State"].ToString(),
                        Email = dr["Email"].ToString(),
                        RelationshipManager = dr["Relationship Manager"].ToString(),
                        RMName = dr["RM Name"].ToString()
                    }).Skip(startRec).Take(pageSize).ToList();

                    var totalCount    = employerCount.Count();
                    var filteredCount = employerList.Count();

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

                        employerCount = (from DataRow dr in dt.Rows
                                         where dr["EmployerID"].ToString().ToLower().Contains(value) || dr["Company Name"].ToString().ToLower().Contains(value) ||
                                         dr["Email"].ToString().ToLower().Contains(value) || dr["Relationship Manager"].ToString().ToLower().Contains(value) ||
                                         dr["RM Name"].ToString().ToLower().Contains(value)
                                         select new Employers()
                        {
                            EmployerID = dr["EmployerID"].ToString(),
                            CompanyName = dr["Company Name"].ToString(),
                        }).ToList();

                        employerList = (from DataRow dr in dt.Rows
                                        where dr["EmployerID"].ToString().ToLower().Contains(value) || dr["Company Name"].ToString().ToLower().Contains(value) ||
                                        dr["Email"].ToString().ToLower().Contains(value) || dr["Relationship Manager"].ToString().ToLower().Contains(value) ||
                                        dr["RM Name"].ToString().ToLower().Contains(value)
                                        select new Employers()
                        {
                            EmployerID = dr["EmployerID"].ToString(),
                            CompanyName = dr["Company Name"].ToString(),
                            Address1 = dr["Address1"].ToString(),
                            Address2 = dr["Address2"].ToString(),
                            State = dr["State"].ToString(),
                            Email = dr["Email"].ToString(),
                            RelationshipManager = dr["Relationship Manager"].ToString(),
                            RMName = dr["RM Name"].ToString()
                        }).Skip(startRec).Take(pageSize).ToList();

                        totalCount    = employerCount.Count();
                        filteredCount = employerList.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 = employerList.Select(emList => new
                    {
                        EmployerID          = emList.EmployerID,
                        CompanyName         = emList.CompanyName,
                        Address1            = emList.Address1,
                        Address2            = emList.Address2,
                        State               = emList.State,
                        Email               = emList.Email,
                        RelationshipManager = emList.RelationshipManager,
                        RMName              = emList.RMName
                    }).OrderBy(orderByString == string.Empty ? "EmployerID asc" : orderByString).ToList();

                    return(Json(new DataTablesResponse(requestModel.Draw, data, totalCount, totalCount), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    Employer.Employer employer = new Employer.Employer();
                    DataTable         dt       = employer.FetchCompanies("All", "");
                    dt.TableName = "Employer";

                    List <Employers> employerList = new List <Employers>();
                    int startRec = requestModel.Start;
                    int pageSize = requestModel.Length;


                    List <Employers> employerCount = (from DataRow dr in dt.Rows
                                                      select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString(),
                        CompanyName = dr["Company Name"].ToString(),
                    }).ToList();

                    employerList = (from DataRow dr in dt.Rows
                                    select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString(),
                        CompanyName = dr["Company Name"].ToString(),
                        Address1 = dr["Address1"].ToString(),
                        Address2 = dr["Address2"].ToString(),
                        State = dr["State"].ToString(),
                        Email = dr["Email"].ToString(),
                        RelationshipManager = dr["Relationship Manager"].ToString(),
                        RMName = dr["RM Name"].ToString()
                    }).Skip(startRec).Take(pageSize).ToList();

                    var totalCount    = employerCount.Count();
                    var filteredCount = employerList.Count();

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

                        employerCount = (from DataRow dr in dt.Rows
                                         where dr["EmployerID"].ToString().ToLower().Contains(value) || dr["Company Name"].ToString().ToLower().Contains(value) ||
                                         dr["Email"].ToString().ToLower().Contains(value) || dr["Relationship Manager"].ToString().ToLower().Contains(value) ||
                                         dr["RM Name"].ToString().ToLower().Contains(value)
                                         select new Employers()
                        {
                            EmployerID = dr["EmployerID"].ToString(),
                            CompanyName = dr["Company Name"].ToString(),
                        }).ToList();

                        employerList = (from DataRow dr in dt.Rows
                                        where dr["EmployerID"].ToString().ToLower().Contains(value) || dr["Company Name"].ToString().ToLower().Contains(value) ||
                                        dr["Email"].ToString().ToLower().Contains(value) || dr["Relationship Manager"].ToString().ToLower().Contains(value) ||
                                        dr["RM Name"].ToString().ToLower().Contains(value)
                                        select new Employers()
                        {
                            EmployerID = dr["EmployerID"].ToString(),
                            CompanyName = dr["Company Name"].ToString(),
                            Address1 = dr["Address1"].ToString(),
                            Address2 = dr["Address2"].ToString(),
                            State = dr["State"].ToString(),
                            Email = dr["Email"].ToString(),
                            RelationshipManager = dr["Relationship Manager"].ToString(),
                            RMName = dr["RM Name"].ToString()
                        }).Skip(startRec).Take(pageSize).ToList();

                        totalCount    = employerCount.Count();
                        filteredCount = employerList.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 = employerList.Select(emList => new
                    {
                        EmployerID          = emList.EmployerID,
                        CompanyName         = emList.CompanyName,
                        Address1            = emList.Address1,
                        Address2            = emList.Address2,
                        State               = emList.State,
                        Email               = emList.Email,
                        RelationshipManager = emList.RelationshipManager,
                        RMName              = emList.RMName
                    }).OrderBy(orderByString == string.Empty ? "EmployerID asc" : orderByString).ToList();

                    return(Json(new DataTablesResponse(requestModel.Draw, data, totalCount, totalCount), JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                LogError logerror = new LogError();
                logerror.ErrorLog("", LoginUser, "", "Employer/GetEmployers", "Employer", "GetEmployers", "GetEmployers Error", ex.Message.ToString(), 0);
                throw new Exception(ex.Message.ToString());
            }
        }
示例#2
0
        public JsonResult GetEmployersList(string Prefix)
        {
            string userkey   = ConfigurationManager.AppSettings["userkey"];
            string uid       = ConfigurationManager.AppSettings["uid"];
            string LoginUser = (string)Session["LoginSAPID"];
            string RoleID    = (string)Session["RoleID"];
            string WebUserID = (string)Session["WebUserID"];

            try
            {
                if (RoleID == "1")
                {
                    Employer.Employer employer = new Employer.Employer();
                    DataTable         dt       = employer.FetchCompanies("Yes", LoginUser);
                    dt.TableName = "Employer";

                    //Note : you can bind same list from database
                    List <Employers> employers = (from DataRow dr in dt.Rows
                                                  select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString().ToUpper(),
                        CompanyName = dr["Company Name"].ToString().ToUpper(),
                    }).ToList();

                    //Searching records from list using LINQ query
                    var employersList = (from DataRow dr in dt.Rows
                                         where dr["Company Name"].ToString().ToUpper().StartsWith(Prefix.ToUpper())
                                         select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString().ToUpper(),
                        CompanyName = dr["Company Name"].ToString().ToUpper(),
                    }).ToList();
                    return(Json(new { data = employersList }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    Employer.Employer employer = new Employer.Employer();
                    DataTable         dt       = employer.FetchCompanies("All", "");
                    dt.TableName = "Employer";

                    //Note : you can bind same list from database
                    List <Employers> employers = (from DataRow dr in dt.Rows
                                                  select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString().ToUpper(),
                        CompanyName = dr["Company Name"].ToString().ToUpper(),
                    }).ToList();

                    //Searching records from list using LINQ query
                    var employersList = (from DataRow dr in dt.Rows
                                         where dr["Company Name"].ToString().ToUpper().StartsWith(Prefix.ToUpper())
                                         select new Employers()
                    {
                        EmployerID = dr["EmployerID"].ToString().ToUpper(),
                        CompanyName = dr["Company Name"].ToString().ToUpper(),
                    }).ToList();
                    return(Json(new { data = employersList }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                LogError logerror = new LogError();
                logerror.ErrorLog("", LoginUser, "", "Employer/GetEmployers", "Employer", "GetEmployers", "GetEmployers Error", ex.Message.ToString(), 0);
                throw new Exception(ex.Message.ToString());
            }
        }