public ActionResult CopySaleIncementsToSale(int selectedSaleId, int saleId, string btnIdToRefresh, string frmIdToRefresh, AUSaleList model)
        {
            //TODO: Implement permissions
            //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            //    return AccessDeniedView();


            var salefrom = _consignorService.GetSaleById(selectedSaleId);
            if (salefrom == null)
            {
                ErrorNotification("A major error occurred -sale from id from CopySaleIncementsToSale popup not found. Please contact System Support");
                return RedirectToAction("ManageSales"); //TODO FIX THIS to alert majorerror
            }

            var saleto = _consignorService.GetSaleById(saleId); //TODO: why using service to get this record.
            if (saleto == null)
            {
                ErrorNotification("A major error occurred -saleto id from CopySaleIncementsToSale popup not found. Please contact System Support");
                return RedirectToAction("ManageSales"); //TODO FIX THIS to alert majorerror
            }

            //changed so not walking the sale
            var increments = saleto.AUIncrementRecords;

           // consignor = _consignorRepo.GetById(ConsignorId);
            //doesn't work - eats itself so second iteration fails
            //foreach (var i in increments)
            //{
               
            //    var inc = _incrementRepo.GetById(i.AUIncrementID);
            //    _incrementRepo.Delete(inc);
            //}


            while (1 == 1)
            {
                var inc = increments.FirstOrDefault();
                if (inc != null)
                {
                    _incrementRepo.Delete(inc);  //these hit db right away
                }
                else
                {
                    break;
                }
            }

            //saleto.AUIncrementRecords.Clear();
            //_saleRepo.Update(saleto);

           

            foreach (var incf in salefrom.AUIncrementRecords)
            {
                var newinc = new AUIncrementRecord();
                var sale = _saleRepo.GetById(saleto.AUSaleID);
                newinc.AUSaleID = saleto.AUSaleID; //change forein key to new sale;
                newinc.CreatedBy = "Test created by";
                
                //newinc.createdon
                newinc.FromBidAmt = incf.FromBidAmt;
                newinc.ToBidAmt = incf.ToBidAmt;
                newinc.IncrementAmt = incf.IncrementAmt;


                newinc.CreatedBy = "Test";
                newinc.UpdatedBy = "Test";
                newinc.CreatedOnDT = System.DateTime.UtcNow;
                newinc.UpdatedOnDT = System.DateTime.UtcNow;


                saleto.AUIncrementRecords.Add(newinc);

               // saleto.AUIncrementRecords.Add(newinc);
               // _saleRepo.Update(saleto);


               // _incrementRepo.Insert(newinc); No Work - not null key???
               
            }
            _saleRepo.Update(saleto); //record add above does not hit db until this

            ////a vendor should have access only to his products
            //if (_workContext.CurrentVendor != null)
            //{
            //    products = products.Where(p => p.VendorId == _workContext.CurrentVendor.Id).ToList();
            //}


            //_consignorService.PublishSelectedProducts(products);


            SuccessNotification("Increments were associated to sale!!");  //seems to be nop admin convention

            ViewBag.RefreshPage = true;
            ViewBag.btnId = btnIdToRefresh; //button to click (btnRefreshIncrements)
            ViewBag.formId = frmIdToRefresh; //form to open (sale-form)


            return View("~/Views/AUConsignor/SaleIncrementCopyPopup.cshtml", model);
            //return RedirectToAction("ListLots"); //TODO FIX THIS
        }
        public ActionResult ListSales(DataSourceRequest command, AUSaleList model)
        {

            var sales = _consignorService.GetAllSales(
                saleId: model.searchAUSaleID,
                saleNbr: model.searchSaleNbr,
                saleTitle: model.searchSaleTitle,
                pageIndex: 0,
                pageSize: 500);

            //pageIndex: command.Page - 1,
            //pageSize: command.PageSize);


            var gridModel = new DataSourceResult
            {
                Data = sales.Select(x => new
                {
                    AUSaleID = x.AUSaleID,
                    SaleStoreID = x.SaleStoreID,
                    AUSaleNbr = x.AUSaleNbr,
                    SaleTitle = x.SaleTitle,
                    SaleDesc = x.SaleDesc,
                   // SaleStartDateTime = x.SaleStartDateTime,
                   // SaleEndDateTime = x.SaleEndDateTime,
                    SaleStartDateTime = _dateTimeHelper.ConvertToUserTime(x.SaleStartDateTime, DateTimeKind.Local),
                    SaleEndDateTime = _dateTimeHelper.ConvertToUserTime(x.SaleEndDateTime, DateTimeKind.Local),


                }),
                Total = sales.TotalCount
            };


            return Json(gridModel);
        }
        //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


        //Popup the sale selection popup window to copy increments from
        public ActionResult SaleIncrementCopyPopup(int saleId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
                return View("~/Administration/Views/Security/AccessDenied.cshtml");

            var model = new AUSaleList();  //using same search model as ManageSales

            //a vendor should have access only to his products. Set the indicator in the model
            //model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
            model.SaleId = saleId;

            //Populate Sales
 //don't allow select all           model.AvailableSales.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" });
            var sales = _consignorService.GetAllSales(
                 saleId: saleId,
                 saleNbr: null,
                 saleTitle: null,
                 excludeSale: true,
                 pageIndex: 0,
                 pageSize: 2147483647);
            foreach (var c in sales)
                model.AvailableSales.Add(new SelectListItem { Text = c.SaleTitle, Value = c.AUSaleID.ToString() });


            return View("~/Views/AUConsignor/SaleIncrementCopyPopup.cshtml", model);
        }