public ActionResult UpdateSaleIncrement(AUIncrementRecord increment)
        {
            //TODO: AUTHORIZE
            //if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            //    return AccessDeniedView();


            _incrementRepo.Update(increment);


            return new NullJsonResult();
        }
        public ActionResult CreateSaleIncrement(AUIncrementRecord increment)  //this reference is injected by autofac (the repo is part of dbcontext)
        {


            var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer();
            increment.CreatedBy = CurrentCustomer.Username;
            increment.UpdatedBy = CurrentCustomer.Username;

            increment.CreatedOnDT = System.DateTime.UtcNow;
            increment.UpdatedOnDT = System.DateTime.UtcNow;

            var sale = _saleRepo.GetById(increment.AUSaleID);
            sale.AUIncrementRecords.Add(increment);
            _saleRepo.Update(sale);
            _eventPublisher.EntityInserted(increment);  //publish event that increment inserted to flush cache in C:\Users\Nicholas\Documents\My Documents\NopCommerce\Plugins\Nop.Plugin.Misc.AUConsignor\Infrastructure\AUConsignorCacheEventConsumer.cs
            SuccessNotification("Increment Added!", false);
            return new NullJsonResult();
        }
        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
        }
       // [ChildActionOnly]
        public ActionResult ManageSaleIncrements(int saleID = 0)
        {
            //put SaleIsPublished into ViewBag so view can hide the increment edit/delete buttons if published
            var sale = _saleRepo.GetById(saleID);
            ViewBag.SaleIsPublished = sale.SaleIsPublished;

            AUIncrementRecord increment = new AUIncrementRecord();
            increment.AUSaleID = saleID;
            increment.AUIncrementID = 0;

            ////%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            //session.AvailableAddresses.Add(new SelectListItem { Text = _localizationService.GetResource("Plugins.Misc.AUConsignor.SelectAddressMsg"), Value = "0" });
            //foreach (var c in _consignorService.GetAllAUAddresses())
            //{
            //    session.AvailableAddresses.Add(new SelectListItem
            //    {
            //        Text = c.Address1 + ", " + c.Address2 + ", " + c.City,
            //        Value = c.AUAddressID.ToString(),
            //        Selected = c.AUAddressID == session.AUAddressID
            //    });
            //}


            return View("~/Views/AUConsignor/ManageSaleIncrements.cshtml", increment);
        }