public virtual void DeleteSaleLotByLotId(int lotId, int saleId)
        {

         if (lotId == 0)
             throw new ArgumentNullException("lotId");
         if (saleId == 0)
             throw new ArgumentNullException("saleId");

         var query = from l in _salelotRepo.Table
                     //orderby l.Id
                     //where !p.Deleted &&
                     where l.AULotID == lotId && l.AUSaleID == saleId
                     select l;
         var salelot = query.FirstOrDefault();


         var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer();


         AULotActivityRecord activity = new AULotActivityRecord();
         activity.AULotId = salelot.AULotID;
         activity.AUProductId = salelot.AUProductId;
         activity.Sku = salelot.Sku;
         activity.ChangeEntity = "Sale";
         activity.OriginalId = salelot.AUSaleID;
         activity.OriginalValue = salelot.AUSaleRecord.AUSaleNbr;
         activity.NewId = null;
         activity.NewValue = null;
         activity.StoreId = 1;           //TODO: need to get store shit correct
         activity.UpdatedBy = CurrentCustomer.Username;
         activity.UpdatedOnDT = System.DateTime.UtcNow;

        
         //pulled from http://www.nopcommerce.com/boards/t/30961/how-to-get-hold-of-the-dbcontext-of-nop-to-allow-bulktinsert-extension.aspx
         //pulled from https://efbulkinsert.codeplex.com/documentation?referringTitle=Home
         //pulled from https://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.complete(v=vs.110).aspx
         using (var myObjectContext = EngineContext.Current.Resolve<AUConsignorObjectContext>())
         {
             try
             {
                 using (var transactionScope = new TransactionScope())
                 {
                     if (salelot.SaleIsAwarded)
                     {
                         salelot.IsHistory = true;
                         _salelotRepo.Update(salelot);
                         activity.ChangeCode = "RH";        //removed but history kept
                     }
                     else
                     {
                         _salelotRepo.Delete(salelot);
                         activity.ChangeCode = "RM";        //removed but history kept
                     }

                     _lotactivityRepo.Insert(activity);

                     myObjectContext.SaveChanges();
                     transactionScope.Complete();
                 }
             }
             catch (TransactionAbortedException ex)
             {
                 throw new NopException(ex.Message);
             }
             catch (ApplicationException ex)
             {
                 throw new NopException(ex.Message);
             }
         }
            





        // return lot;

        }
        public virtual void MoveSaleLot(AUSaleLotRecord oldsalelot, AUSaleLotRecord newsalelot)
        {

            if (oldsalelot == null)
                throw new ArgumentNullException("old salelot");
            if (newsalelot == null)
                throw new ArgumentNullException("new salelot");


            //insert
            //_salelotRepo.Insert(salelot);

            //TODO: ADD LOT CACHE CONTROL AND PUBLISHING
            ////clear cache
            //_cacheManager.RemoveByPattern(PRODUCTS_PATTERN_KEY);

            ////event notification
            //_eventPublisher.EntityInserted(product);

            var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer();


            AULotActivityRecord activity = new AULotActivityRecord();
            activity.AULotId = oldsalelot.AULotID;
            activity.AUProductId = oldsalelot.AUProductId;
            activity.Sku = oldsalelot.Sku;
            activity.OriginalId = oldsalelot.AUSaleID;
            activity.OriginalValue = oldsalelot.AUSaleRecord.AUSaleNbr;
            activity.NewId = newsalelot.AUSaleID;
            activity.ChangeEntity = "Sale";
            //moveLotHistory.ChangeCode = "MV";
            activity.StoreId = 1;           //TODO: need to get store shit correct
            activity.UpdatedBy = CurrentCustomer.Username;
            activity.UpdatedOnDT = System.DateTime.UtcNow;


            //pulled from http://www.nopcommerce.com/boards/t/30961/how-to-get-hold-of-the-dbcontext-of-nop-to-allow-bulktinsert-extension.aspx
            //pulled from https://efbulkinsert.codeplex.com/documentation?referringTitle=Home
            //pulled from https://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.complete(v=vs.110).aspx
            using (var myObjectContext = EngineContext.Current.Resolve<AUConsignorObjectContext>())
            //using (var leaseObjectContext = this._dbContext)
            {
                try
                {
                    using (var transactionScope = new TransactionScope())
                    {

                        //------------------------------------

                        if (oldsalelot.SaleIsAwarded)
                        {
                            oldsalelot.IsHistory = true;
                            _salelotRepo.Update(oldsalelot);
                            activity.ChangeCode = "MH";        //removed after sale closed but no bids - but history junction kept for historical views of sale
                        }
                        else
                        {
                            _salelotRepo.Delete(oldsalelot);
                            activity.ChangeCode = "MV";        //removed before bids and sale closed - no history needed - like it never existsed 
                        }

                        _salelotRepo.Insert(newsalelot);
                        activity.NewValue = newsalelot.AUSaleRecord.AUSaleNbr;  //need to do this after store newsalelot


                        _lotactivityRepo.Insert(activity);

                        myObjectContext.SaveChanges();
                        transactionScope.Complete();
                    }
                }
                catch (TransactionAbortedException ex)
                {
                    throw new NopException(ex.Message);
                }
                catch (ApplicationException ex)
                {
                    throw new NopException(ex.Message);
                }
            }
        }
        /// <summary>
        /// Updates an AUSaleLot
        /// </summary>
        /// <param name="salelot">AUSaleLotRecord</param>
        public virtual void UpdateConsignmentLot(AUConsignmentLotRecord consignmentlot, int origConsignmentId)
        {
            if (consignmentlot == null)
                throw new ArgumentNullException("consignmentlot");

            var origConsignment = _consignmentRepo.GetById(origConsignmentId);


            var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer();


            AULotActivityRecord activity = new AULotActivityRecord();
            activity.AULotId = consignmentlot.AULotID;
            activity.AUProductId = consignmentlot.AULotRecord.AUProductID;
            activity.Sku = consignmentlot.AULotRecord.Sku;
            activity.ChangeEntity = "Consignment";
            activity.OriginalId = origConsignmentId;
            activity.OriginalValue = origConsignment.ConsignmentDesc;
            activity.NewId = consignmentlot.AUConsignmentID;
            activity.ChangeCode = "MC";
            activity.StoreId = 1;           //TODO: need to get store shit correct
            activity.UpdatedBy = CurrentCustomer.Username;
            activity.UpdatedOnDT = System.DateTime.UtcNow;




            //pulled from http://www.nopcommerce.com/boards/t/30961/how-to-get-hold-of-the-dbcontext-of-nop-to-allow-bulktinsert-extension.aspx
            //pulled from https://efbulkinsert.codeplex.com/documentation?referringTitle=Home
            //pulled from https://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.complete(v=vs.110).aspx
            using (var myObjectContext = EngineContext.Current.Resolve<AUConsignorObjectContext>())
            //using (var leaseObjectContext = this._dbContext)
            {
                try
                {
                    using (var transactionScope = new TransactionScope())
                    {
                        _consignmentlotRepo.Update(consignmentlot);
                        activity.NewValue = consignmentlot.AUConsignmentRecord.ConsignmentDesc;  //wait till update consignmentlot to get value

                        _lotactivityRepo.Insert(activity);

                        myObjectContext.SaveChanges();
                        transactionScope.Complete();
                    }
                }
                catch (TransactionAbortedException ex)
                {
                    throw new NopException(ex.Message);
                }
                catch (ApplicationException ex)
                {
                    throw new NopException(ex.Message);
                }
            }











            //TODO: ADD LOT CACHE CONTROL AND PUBLISHING
            ////clear cache
            //_cacheManager.RemoveByPattern(PRODUCTS_PATTERN_KEY);

            ////event notification
            //_eventPublisher.EntityInserted(product);
        }
        /// <summary>
        /// Inserts an AUSaleLot
        /// </summary>
        /// <param name="salelot">AUSaleLotRecord</param>
        public virtual void InsertSaleLot(AUSaleLotRecord newsalelot)
        {
            if (newsalelot == null)
                throw new ArgumentNullException("salelot");

            //TODO: ADD LOT CACHE CONTROL AND PUBLISHING
            ////clear cache
            //_cacheManager.RemoveByPattern(PRODUCTS_PATTERN_KEY);

            ////event notification
            //_eventPublisher.EntityInserted(product);

            

            var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer();


            AULotActivityRecord activity = new AULotActivityRecord();
            activity.AULotId = newsalelot.AULotID;
            activity.AUProductId = newsalelot.AUProductId;
            activity.Sku = newsalelot.Sku;
            //moveLotHistory.OriginalSaleId = oldsalelot.AUSaleID;
            activity.NewId = newsalelot.AUSaleID;
            activity.ChangeEntity = "Sale";
            activity.ChangeCode = "NS";
            activity.StoreId = 1;           //TODO: need to get store shit correct
            activity.UpdatedBy = CurrentCustomer.Username;
            activity.UpdatedOnDT = System.DateTime.UtcNow;




            //pulled from http://www.nopcommerce.com/boards/t/30961/how-to-get-hold-of-the-dbcontext-of-nop-to-allow-bulktinsert-extension.aspx
            //pulled from https://efbulkinsert.codeplex.com/documentation?referringTitle=Home
            //pulled from https://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.complete(v=vs.110).aspx
            using (var myObjectContext = EngineContext.Current.Resolve<AUConsignorObjectContext>())
            //using (var leaseObjectContext = this._dbContext)
            
            { 
                try 
                {
                    using  (var transactionScope = new TransactionScope())
                    {
                        _salelotRepo.Insert(newsalelot);
                        activity.NewValue = newsalelot.AUSaleRecord.AUSaleNbr; //need to wait until store salelot before this is available

                        _lotactivityRepo.Insert(activity);

                    myObjectContext.SaveChanges();
                    transactionScope.Complete();
                    }
                }
                catch (TransactionAbortedException ex)
                {
                   throw new NopException(ex.Message);
                }
                catch (ApplicationException ex)
                {
                    throw new NopException(ex.Message);
                }
            }
            

            ////////var ctx = GetContext()

            ////////var context = new 
            ////////using (var ctx = GetContext())
            ////////{
            ////////    using (var transactionScope = new TransactionScope())
            ////////    {
            ////////        // some stuff in dbcontext

            ////////        ctx.BulkInsert(entities);

            ////////        ctx.SaveChanges();
            ////////        transactionScope.Complete();
            ////////    }
            ////////}


        }