public async Task <IActionResult> FavouriteItems(DataSourceRequest command,
                                                         FavoriteItemListModel model)
        {
            var(favoriteitemListModel, totalCount) = await _selectItemsServices.PrepareFavoriteItemListModel(model, command.Page, command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data  = favoriteitemListModel.ToList(),
                Total = totalCount
            };

            return(Json(gridModel));
        }
        public async Task <IActionResult> FavoriteItems()
        {
            FavoriteItemListModel model = new FavoriteItemListModel();

            ///Dropdownlist
            var costCenters = await _costCenterService.SelectCostCenter((int)_workContext.CurrentCustomer.ClientId,
                                                                        (int)_workContext.CurrentCustomer.UserType,
                                                                        _workContext.CurrentCustomer.LogonId);

            foreach (var item in costCenters)
            {
                model.AvailableCostCenter.Add(new SelectListItem {
                    Text = item.Both, Value = item.Sid.ToString()
                });
            }

            return(View(model));
        }
        public async Task <(IEnumerable <FavoriteItem> favoriteItemsModel, int totalCount)> PrepareFavoriteItemListModel(FavoriteItemListModel model, int pageIndex, int pageSize)
        {
            if (string.IsNullOrEmpty(model.SearchCriteria))
            {
                model.SearchCriteria = "";
            }

            var query = (from b in _bosoRepository.Table
                         join i in _itemRepository.Table on b.VitemId equals i.VitemId
                         join v in _vendorRepository.Table on i.VendorId equals v.VendorId into gf
                         from g in gf
                         where b.LogonId == (int)_workContext.CurrentCustomer.LogonId &&
                         (i.Vitem.Contains(model.SearchCriteria) ||
                          g.Vname.Contains(model.SearchCriteria))
                         select new FavoriteItem
            {
                bosoid = b.Bosoid,
                category = (b.Category ?? "unselected"),
                vitem = i.Vitem,
                vitemid = i.VitemId,
                vdescription = i.Vdescription,
                uom = i.Uom,
                pkg = i.Pkg,
                sellingPrice = i.SellingPrice,
                vname = g.Vname
            }).Distinct();

            //Sorting
            if (model.SortBy == 4)
            {
                query = query.OrderBy(c => c.category);
            }

            if (model.SortBy == 2)
            {
                query = query.OrderBy(c => c.vdescription);
            }

            if (model.SortBy == 1)
            {
                query = query.OrderBy(c => c.vitem);
            }

            if (model.SortBy == 3)
            {
                query = query.OrderBy(c => c.vname);
            }

            var favoriteItemsListModel = query.ToList();

            int totalCount = favoriteItemsListModel.Count;
            int pageOffSet = (Convert.ToInt32(pageIndex) - 1) * 10;

            favoriteItemsListModel = favoriteItemsListModel.Skip(pageOffSet).Take(Convert.ToInt32(pageSize)).ToList();

            return(favoriteItemsListModel, totalCount);
        }