public JsonResult GetCategory(DTParameters param) { CategoryPageStore category = new CategoryPageStore(); category.PageIndex = param.Start / param.Length + 1; category.PageSize = param.Length; if (param.Search.Value == null) { category.Search = "%%"; } else { category.Search = "%" + param.Search.Value + "%"; } category.Order = param.SortOrder; CategoryPageStore categories = new CategoryModel().GetCategoryByPage(category.Search, category.Order, category.PageIndex, category.PageSize); DTResult <CategoryDTO> final = new DTResult <CategoryDTO>() { draw = param.Draw, data = categories.Categories.ToList(), recordsFiltered = categories.RecordCount, recordsTotal = categories.Categories.Count }; return(Json(final)); }
public CategoryPageStore GetCategoryByPage(string search, string order, int pageIndex, int pageSize) { CategoryPageStore category = new CategoryPageStore(); category.PageIndex = pageIndex; category.PageSize = pageSize; category.Search = search; category.Order = order; SqlParameter paramPageSearch = new SqlParameter("@PageSearch", search); SqlParameter paramOrderColumn = new SqlParameter("@SortOrder", order); SqlParameter paramPageIndex = new SqlParameter("@PageIndex", pageIndex); SqlParameter paramPageSize = new SqlParameter("@PageSize", pageSize); SqlParameter paramRecordCount = new SqlParameter("@RecordCount", category.RecordCount); paramRecordCount.Direction = ParameterDirection.Output; var listResult = db.Database.SqlQuery <CategoryDTO>("EXEC [dbo].[usp_MaintainCategoryPage] @PageSearch, @SortOrder, @PageIndex, @PageSize, @RecordCount = @RecordCount OUTPUT", paramPageSearch, paramOrderColumn, paramPageIndex, paramPageSize, paramRecordCount).ToList(); category.RecordCount = (int)paramRecordCount.Value; category.Categories = listResult.Select(e => new CategoryDTO() { CategoryID = e.CategoryID, CategoryName = e.CategoryName, Description = e.Description, Picture = e.Picture, CategoryImage = e.CategoryImage }).ToList(); return(category); }