public QueryResult<CommoditySupplierListingViewModel> Query(QueryCommoditySupplier query)
         {
             var queryResult = _commoditySupplierRepository.Query(query);

             var result = new QueryResult<CommoditySupplierListingViewModel>();

             result.Data = queryResult.Data.Select(Map).ToList();
             result.Count = queryResult.Count;

             return result;
         }
        public ActionResult ListCommoditySuppliers(Boolean? showInactive, int page = 1, int itemsperpage = 10, string srchParam = "")
        {
            try
            {
                if (itemsperpage != null)
                {
                    ViewModelBase.ItemsPerPage = itemsperpage;
                }
                bool showinactive = false;
                if (showInactive != null)
                    showinactive = (bool) showInactive;

                ViewBag.showInactive = showinactive;
                if (TempData["msg"] != null)
                {
                    ViewBag.msg = TempData["msg"].ToString();
                    TempData["msg"] = null;
                }
                ViewBag.srchParam = srchParam;
                int currentPageIndex = page < 0 ? 0 : page - 1;
                int take = itemsperpage;
                int skip = take*currentPageIndex;
                var query=new QueryCommoditySupplier(){ShowInactive = showinactive,Name = srchParam, Skip = skip, Take = take};

                var ls = _commoditySupplierViewModelBuilder.Query(query);
                var data = ls.Data;
                var count = ls.Count;

               return View(data.ToPagedList(currentPageIndex, ViewModelBase.ItemsPerPage, count));
            }
            catch (Exception ex)
            {
                _log.Debug("Failed to list hubs " + ex.Message);
                _log.Error("Failed to list hubs" + ex.ToString());
                return View();
            }
        }
        protected override void Load(bool isFirstLoad = false)
        {
            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    delegate
                        {
                            if (isFirstLoad)
                                Setup();
                            using (var c = NestedContainer)
                            {
                                
                                var query = new QueryCommoditySupplier();
                                query.Skip = ItemsPerPage*(CurrentPage-1);
                                query.Take = ItemsPerPage;
                                query.ShowInactive = ShowInactive;

                                if (!string.IsNullOrWhiteSpace(SearchText))
                                    query.Name = SearchText;

                                var rawList = Using<ICommoditySupplierRepository>(c).Query(query);
                                var data = rawList.Data.OfType<CommoditySupplier>();

                                _pagedCommoditySuppliers = new PagenatedList<CommoditySupplier>(data.AsQueryable(),
                                                                                          CurrentPage,
                                                                                          ItemsPerPage,
                                                                                          rawList.Count,true);

                                CommoditySuppliersList.Clear();
                                int rownumber = 0;
                                _pagedCommoditySuppliers.Select((n, i) => Map(n, i + 1)).ToList().ForEach(
                                    n =>
                                        {
                                            if (n != null)
                                                CommoditySuppliersList.Add(new VMCommoditySupplier
                                                    {
                                                        SupplierId = n.CommoditySupplier.Id,
                                                        CostCenterCode = n.CommoditySupplier.CostCentreCode ?? "",
                                                        Name = n.CommoditySupplier.Name??"",
                                                        AccountName = n.CommoditySupplier.AccountName??"",
                                                        AccountNo = n.CommoditySupplier.AccountNo??"",
                                                        Bank =n.CommoditySupplier.BankId!=Guid.Empty? Using<IBankRepository>(c).GetById(n.CommoditySupplier.BankId).Name:"",
                                                        BankBranch =n.CommoditySupplier.BankBranchId!=Guid.Empty? Using<IBankBranchRepository>(c).GetById( n.CommoditySupplier.BankBranchId).Name:"",
                                                        Status=n.CommoditySupplier._Status,
                                                        Action=n.CommoditySupplier._Status==EntityStatus.Active?"Deactivate":"Activate",
                                                        RowNumber=++rownumber
                                                    });
                                        });
                                UpdatePagenationControl();
                            }
                        }));
        }