public async Task <IActionResult> ItemSearch2(DataSourceRequest command,
                                                      OI2Model model)
        {
            var(ProductItemSearchlistmodel, totalCount) = await _selectItemsServices.ProductItemSearchlistmodel(model, command.Page,
                                                                                                                command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data  = ProductItemSearchlistmodel,
                Total = totalCount
            };

            return(Json(gridModel));
        }
        public async Task <IActionResult> OI2(OI2Model model)
        {
            if (ModelState.IsValid)
            {
                var vitems = await _selectItemsServices.GetEditItem(Convert.ToInt32(model.SearchItemNumber));

                if (vitems != null && vitems.VendorID == model.VendorID)
                {
                    return(RedirectToAction("OItem", "SelectItems", new { VitemID = model.SearchItemNumber, f = "OI2" }));
                }
                else
                {
                    ModelState.AddModelError("", "The item you entered was not found.");
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> ItemSearch2(int VendorID)
        {
            if (VendorID <= 0)
            {
                return(RedirectToAction("Vendors"));
            }

            var model = new OI2Model();

            var vendor = (await _selectItemsServices.GetVendorList((int)_workContext.CurrentCustomer.ClientId)).Where(v => v.VendorId == VendorID).FirstOrDefault();

            if (vendor == null)
            {
                return(RedirectToAction("Vendors"));
            }

            model.VName    = vendor.Vname;
            model.VendorID = (int)vendor.VendorId;

            return(View(model));
        }
        public async Task <(IEnumerable <ProductSearchModel> ProductItemSearchlistmodel, int totalCount)> ProductItemSearchlistmodel(OI2Model model, int pageIndex, int pageSize)
        {
            var query = (from i in _itemRepository.Table
                         join v in _vendorRepository.Table on i.VendorId equals v.VendorId
                         where v.ClientId == (int)_workContext.CurrentCustomer.ClientId &&
                         v.VendorId == model.VendorID
                         select new ItemSearch
            {
                VItemID = i.VitemId,
                Vitem = i.Vitem,
                MfgNo = i.MfgNo,
                VDescription = i.Vdescription,
                UOM = i.Uom,
                Pkg = i.Pkg,
                SellingPrice = i.SellingPrice,
                VendorID = v.VendorId,
                VName = v.Vname
            });

            //Searching
            if (!string.IsNullOrWhiteSpace(model.SearchItemNumber))
            {
                query = query.Where(c => c.Vitem.Contains(model.SearchItemNumber) || c.VDescription.Contains(model.SearchItemNumber) || c.MfgNo.Contains(model.SearchItemNumber));
            }

            //Sorting
            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.MfgNo);
            }


            var products = query.Distinct().ToList();

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

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

            ///Add from store procedure response to model
            var productsearchlistmodel = new List <ProductSearchModel>();

            foreach (var p in products)
            {
                productsearchlistmodel.Add(new ProductSearchModel
                {
                    VItemId     = p.VItemID,
                    Item        = p.Vitem,
                    Mfg         = p.MfgNo,
                    Description = p.VDescription,
                    Unit        = p.UOM,
                    Pkg         = p.Pkg,
                    Price       = p.SellingPrice,
                    Vendor      = p.VName
                });
            }

            return(productsearchlistmodel, totalCount);
        }