Exemplo n.º 1
0
        public ActionResult ConfiguracionOrden()
        {
            try
            {
                var draw  = HttpContext.Request.Form["draw"];
                var start = Request.Form["start"];
                // Paging Length 10,20
                var length = Request.Form["length"];
                // Sort Column Name
                var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"];
                // Sort Column Direction ( asc ,desc)
                var sortColumnDirection = Request.Form["order[0][dir]"];
                // Search Value from (Search box)
                var searchValue = Request.Form["search[value]"];

                //Paging Size (10,20,50,100)
                int pageSize = length != null?Convert.ToInt32(length) : 0;

                int skip = start != null?Convert.ToInt32(start) : 0;

                int recordsTotal = 0;

                ManagerUser mang          = new ManagerUser();
                var         agenteSession = Session["LoginCredentials"] as List <dto_Configuracion>;
                var         bucket        = mang.AsignaConfiguracion();

                // Getting all Customer data
                var customerData = (from tempcustomer in bucket
                                    select new
                {
                    id = tempcustomer.Id.ToString(),
                    Nombre = tempcustomer.Nombre.ToString()
                });

                if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection)))
                {
                    switch (sortColumn)
                    {
                    case "Id":
                        if (sortColumnDirection == "desc")
                        {
                            customerData = (from foobars in customerData
                                            orderby foobars.id descending
                                            select foobars
                                            );
                        }
                        else
                        {
                            customerData = (from foobars in customerData
                                            orderby foobars.id ascending
                                            select foobars
                                            );
                        }
                        break;

                    case "Nombre":
                        if (sortColumnDirection == "desc")
                        {
                            customerData = (from foobars in customerData
                                            orderby foobars.Nombre descending
                                            select foobars
                                            );
                        }
                        else
                        {
                            customerData = (from foobars in customerData
                                            orderby foobars.Nombre ascending
                                            select foobars
                                            );
                        }
                        break;
                    }
                    //customerData = customerData.OrderBy(x =>x.cod_agente);
                }
                //Search
                if (!string.IsNullOrEmpty(searchValue))
                {
                    customerData = customerData.Where(m => m.id.ToLower().Contains(searchValue.ToLower()) || m.Nombre.ToLower().Contains(searchValue.ToLower()));
                }

                //total number of rows count
                recordsTotal = customerData.Count();
                //Paging
                var data = customerData.Skip(skip).Take(pageSize).ToList();

                return(Json(new { draw = draw, recordsFiltered = customerData.Count(), recordsTotal = customerData.Count(), data = data }));
            }
            catch (Exception ex)
            {
                throw;
            }
        }