public System.Web.Mvc.JsonResult GetData6000(ViewModels.General.InputGridViewModel inputViewModel) { System.Threading.Thread.Sleep(2000); ViewModels.General.JsonResultForGridViewModel <Models.Person> result = new ViewModels.General.JsonResultForGridViewModel <Models.Person>(); try { var data = People .AsQueryable(); // Where int count = data.Count(); data = data .OrderBy(current => current.FirstName) ; var partialResult = data .Skip(inputViewModel.Skip) .Take(inputViewModel.Take) .ToList() ; result.Count = count; result.Items = partialResult; result.IsSuccess = true; } catch // (System.Exception ex) { // Log(ex) result.Count = 0; result.Items = null; result.IsSuccess = false; result.ClearNotHiddenMessages(); result.AddErrorMessage("Unexpected Error!"); } finally { } return(new Infrastructure.JsonNetResult { Data = result, }); }
public System.Web.Mvc.JsonResult GetData (ViewModels.LearningDtxGridVue.InputGetDataViewModel inputViewModel) { System.Threading.Thread.Sleep(500); ViewModels.General.JsonResultForGridViewModel <Models.Person> result = new ViewModels.General.JsonResultForGridViewModel <Models.Person>(); try { var data = People .AsQueryable(); if (string.IsNullOrWhiteSpace(inputViewModel.FirstName) == false) { data = data .Where(current => current.FirstName.Contains(inputViewModel.FirstName)) ; } if (string.IsNullOrWhiteSpace(inputViewModel.LastName) == false) { data = data .Where(current => current.LastName.Contains(inputViewModel.LastName)) ; } int count = data.Count(); //if (string.IsNullOrWhiteSpace(inputViewModel.SortFieldName)) //{ // data = // data // .OrderByDescending(current => current.InsertDateTime); //} //else //{ // switch (inputViewModel.SortFieldName.ToUpper()) // { // case "ISACTIVE": // { // if (inputViewModel.SortDirection == "0") // { // data = // data // .OrderBy(current => current.IsActive); // } // else // { // data = // data // .OrderByDescending(current => current.IsActive); // } // break; // } // case "AGE": // { // if (inputViewModel.SortDirection == "0") // { // data = // data // .OrderBy(current => current.Age); // } // else // { // data = // data // .OrderByDescending(current => current.Age); // } // break; // } // case "SALARY": // { // if (inputViewModel.SortDirection == "0") // { // data = // data // .OrderBy(current => current.Salary); // } // else // { // data = // data // .OrderByDescending(current => current.Salary); // } // break; // } // case "FIRSTNAME": // { // if (inputViewModel.SortDirection == "0") // { // data = // data // .OrderBy(current => current.FirstName); // } // else // { // data = // data // .OrderByDescending(current => current.FirstName); // } // break; // } // case "LASTNAME": // { // if (inputViewModel.SortDirection == "0") // { // data = // data // .OrderBy(current => current.LastName); // } // else // { // data = // data // .OrderByDescending(current => current.LastName); // } // break; // } // default: // { // data = // data // .OrderBy(current => current.InsertDateTime); // break; // } // } //} if (string.IsNullOrWhiteSpace(inputViewModel.SortFieldName)) { data = data .OrderByDescending(current => current.InsertDateTime); } else { if (inputViewModel.SortDirection == "0") { data = data .OrderBy(current => current.GetPropertyValue(inputViewModel.SortFieldName)); } else { data = data .OrderByDescending(current => current.GetPropertyValue(inputViewModel.SortFieldName)); } } var partialResult = data .Skip(inputViewModel.Skip) .Take(inputViewModel.Take) .ToList() ; result.Count = count; result.Items = partialResult; result.IsSuccess = true; //result.AddErrorMessage("Error (1)!"); //result.AddHiddenMessage("Hidden (1)!"); //result.AddHiddenMessage("Hidden (2)!"); //result.AddInformationMessage("Information (1)!"); //result.AddInformationMessage("Information (2)!"); //result.AddInformationMessage("Information (3)!"); } catch (System.Exception ex) { // Log(ex) result.Count = 0; result.Items = null; result.IsSuccess = false; result.ClearNotHiddenMessages(); result.AddHiddenMessage(ex.Message); result.AddErrorMessage("Unexpected Error!"); } finally { } return(new Infrastructure.JsonNetResult { Data = result, }); }