How to swap entity framework with two tables in MVC

I want to implement in paging with two tables I am trying to google but not for two tables below the code refers to http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc / sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

http://dotnetmentors.com/mvc/paging-and-sorting-in-asp-net-mvc-and-entity-framework-application.aspx

http://www.c-sharpcorner.com/UploadFile/4b0136/perform-paging-searching-sorting-in-Asp-Net-mvc-5/

My current code is as below

public class PagedProductModel
{
    public int TotalRows { get; set; }
    public IEnumerable<Product> Product { get; set; }
    public int PageSize { get; set; }
    public List< ProductVariation> ProductVariantlist { set; get; }
}

public ActionResult ProductList(int stockquantity = -1, string searchWord = null, int page = 1, string sort = "ProductID", string sortDir = "ASC")
    {
        const int pageSize = 10;
        var totalRows = CountProduct();
        bool Dir = sortDir.Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? true : false;

        var product = GetProductPage(page, pageSize, sort, Dir, searchWord, stockquantity);
        var data = new PagedProductModel()
        {
            TotalRows = totalRows,
            PageSize = pageSize,
            Product = product
        };


        return View(data);
    }

  public IEnumerable<Product> GetProductPage(int pageNumber, int pageSize, string sort, bool Dir, string searchText, int stockquantity)
    {   
        if (pageNumber < 1)
            pageNumber = 1;
        var query = (IQueryable<Product>)_objProductContext.ProductEntries.OrderByWithDirection(c => c.ProductID, Dir);
        query = filterproduct(searchText, stockquantity, query);
        return query
                .Skip((pageNumber - 1) * pageSize)
              .Take(pageSize)
                .ToList();
    }

   private static IQueryable<Product> filterproduct(string searchText, int stockquantity, IQueryable<Product> query)
    {
        if (!string.IsNullOrWhiteSpace(searchText))
        {

            if (stockquantity == -1)
            {
                query = query.Where(p => p.ProductName.Contains(searchText));
            }
            else
            {

            }

        }
        if (stockquantity != -1)
        {

            if (stockquantity == -1)
            {
                query = query.Where(p => p.ProductName.Contains(searchText));
            }
            else
            {
                ProductVariation objProductVariation = new ProductVariation();

                ProductVariationContext _contextProductVariation = new ProductVariationContext();

                query = query.Where(x => x.ProductID == objProductVariation.ProductID && objProductVariation.Quantity == stockquantity);
            }

        }



        return query;
    }

      

One product has multiple product creations

Please suggest me

thank

+3


source to share


1 answer


One way I have implemented multiple pagable grids is using KendoGrid



Connect everything using an AJAX call that returns JSON and the grid will handle the pagination.

0


source







All Articles