public ActionResult ListCommodityProducers(Guid? CommoditySupplierId, Boolean? showInactive, string srchParam, int page = 1, int itemsperpage = 10)
        {
            if (CommoditySupplierId != null)
            {
                ViewBag.CommoditySupplierId = CommoditySupplierId;
                commoditySupplier = CommoditySupplierId.Value;
            }
            try
            {
                if (itemsperpage != null)
                {
                    ViewModelBase.ItemsPerPage = itemsperpage;
                }
                bool showinactive = true;
                if (showInactive != null)
                    showinactive = (bool)showInactive;

                ViewBag.showInactive = showinactive;
                if (TempData["msg"] != null)
                {
                    ViewBag.msg = TempData["msg"].ToString();
                    TempData["msg"] = null;
                }
                ViewBag.SearchText = srchParam;

                int currentPageIndex = page < 0 ? 0 : page - 1;
                int take = itemsperpage;
                int skip = take*currentPageIndex;

                var query = new QueryCommodityProducer(){ShowInactive = showinactive, SupplierId = commoditySupplier, Name = srchParam, Skip = skip};
                
                var ls = _commodityProducerViewModelBuilder.Query(query);
                var data = ls.Data;
                var count = ls.Count;

                var supplier =_commoditySupplierRepository.GetById(commoditySupplier) as CommoditySupplier;
                if (supplier != null) ViewBag.CommoditySupplierType = supplier.CommoditySupplierType;
                
                return View(data.ToPagedList(currentPageIndex, ViewModelBase.ItemsPerPage));
            }
            catch (Exception ex)
            {
                _log.Debug("Failed to list commodity types " + ex.Message);
                _log.Error("Failed to list commodity types" + ex.ToString());
                return View();
            }
        }
        protected override void Load(bool isFirstLoad = false)
        {
            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    delegate
                    {
                        if (isFirstLoad)
                            LoadMemberFarms();
                        using (var c = NestedContainer)
                        {
                            var query = new QueryCommodityProducer();
                            query.Take = ItemsPerPage;
                            query.Skip = ItemsPerPage*(CurrentPage - 1);
                            query.SupplierId = SupplierId;
                            query.ShowInactive = ShowInactive;

                            if (!string.IsNullOrWhiteSpace(SearchText))
                                query.Name = SearchText;
                            var rawList = Using<ICommodityProducerRepository>(c).Query(query);

                            _pagedCommodityProducers = new PagenatedList<CommodityProducer>(rawList.Data.OfType<CommodityProducer>().AsQueryable(),
                                                                                      CurrentPage,
                                                                                      ItemsPerPage,
                                                                                      rawList.Count,true);
                            ListOfCommodityProducers.Clear();
                            int rownumber = 0;
                            _pagedCommodityProducers.ToList().ForEach(n =>
                                                                   ListOfCommodityProducers.Add(new VmCommodityProducer
                                                                   {
                                                                       Id = n.Id,
                                                                       Code = n.Code,
                                                                       Acrage = n.Acrage,
                                                                       Name = n.Name,
                                                                       RegNo = n.RegNo,
                                                                       PhysicalAddress = n.PhysicalAddress,
                                                                       Description = n.Description,
                                                                       Status=n._Status,
                                                                       Action=n._Status==EntityStatus.Active?"Deactivate":"Activate",
                                                                       RowNumber = ++rownumber
                                                                   }));
                            UpdatePagenationControl();
                        }
                    }));
        }