public ActionResult ConsignmentConsignorAddPopup(string selectedIds, int consignmentId, string btnIdToRefresh, string frmIdToRefresh, AUConsignorList model)
        {
            //TODO: Implement permissions
            //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            //    return AccessDeniedView();


            var consignment = _consignorService.GetConsignmentById(consignmentId);
            if (consignment == null)
            {
                ErrorNotification("A major error occurred -consignment id from ConsignmentConsignorAddPopup not found. Please contact System Support");
                return RedirectToAction("ManageConsignors");
            }

            //TODO: Finish this - Need to get the lot info to ensure not already sold and unpublished
            var consignors = new List<AUConsignorRecord>();
            if (selectedIds != null)
            {
                consignors.AddRange(_consignorService.GetConsignorsByConsignorIds(selectedIds));
            }

            foreach (var c in consignors)
            {
                var cc = c.AUConsignmentRecords.FirstOrDefault(x => x.AUConsignmentID == consignment.AUConsignmentID);
                if (cc == null) //Consignment exists but the junction AUConsignorConsignment record doesn't
                {
                    var consignorconsignment = new AUConsignorConsignmentRecord
                    {
                        AUConsignmentID = consignment.AUConsignmentID,
                        AUConsignorID = c.AUConsignorID,
                        Term = "RemoveField"
                    };
                    _consignorService.InsertConsignorConsignment(consignorconsignment);
                }
                //else                                            //Sale exists and the junction AUSaleLot record does as well, so update it
                //{
                //    sl.AUSaleID = sale.AUSaleID;
                //    sl.AULotID = lot.AULotID;
                //    sl.LotNbr = LotNbr;
                //    sl.SaleIsActive = sale.SaleIsActive;
                //    sl.DisplayOrder = DisplayOrder;
                //    _consignorService.UpdateSaleLot(sl);
                //}
            }


            ////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("Lots were associated to sale!!");  //seems to be nop admin convention

            ViewBag.RefreshPage = true;
            ViewBag.btnId = btnIdToRefresh;
            ViewBag.formId = frmIdToRefresh;
            return View("~/Views/AUConsignor/ConsignmentConsignorsPopup.cshtml", model);
            //return RedirectToAction("ListLots"); //TODO FIX THIS
        }
        /// <summary>
        /// Inserts an AUConsignorConsignment
        /// </summary>
        /// <param name="consignorconsignment">AUConsignorConsignmentRecord</param>
        public virtual void InsertConsignorConsignment(AUConsignorConsignmentRecord consignorconsignment)
        {
            if (consignorconsignment == null)
                throw new ArgumentNullException("consignorconsignment");

            //insert
            _consignorconsignmentRepo.Insert(consignorconsignment);

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

            ////event notification
            //_eventPublisher.EntityInserted(product);
        }
        public ActionResult CreateUpdateConsignment(AUCombConsignorConsignment r2)
        {
            if (ModelState.IsValid)
            {
                AUConsignmentRecord consignment = _consignmentRepo.GetById(r2.AUConsignmentRecord.AUConsignmentID);

                //DEBUG TO SEE IF r1 IS AVAILABLE
                //TRY THIS WAY FIRST - NOT SURE BECAUSE MIGHT BE ABLE TO USE r1
                //MIGHT BE BEST ANYWAY TO ENSURE CORD STILL THERE
                //no  good !! could not instantiate
                //AUConsignorRecord consignor = _consignorRepo.GetById(r1.AUConsignorID);

                //string x = "not there";

                //if (RouteData.Values["ConsignmentId"] != null)
                //{
                //    x = RouteData.Values["ConsignmentId"].ToString();
                //}

                //if (consignor == null)
                //{
                //    //place error handling here
                //}

                if (consignment == null)
                {

                    //this worked but trying after insert
                    //AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord();
                    //testc.AUConsignorID = 1;
                    ////testc.AUConsignmentID = 1;
                    //testc.AUConsignmentID = r2.AUConsignmentID; //already known?
                    //testc.Term = "F**k";
                    //r2.AUConsignorRecords.Add(testc);

                    //no good - can't update 2 entities
                    //r2.AUConsignmentRecord.CreatedOnDT = System.DateTime.UtcNow;
                    //r2.AUConsignmentRecord.UpdatedOnDT = System.DateTime.UtcNow;
                    //_combinedRepo.Insert(r2);

                    //try this first
                    var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer();
                    r2.AUConsignmentRecord.CreatedBy = CurrentCustomer.Username;
                    r2.AUConsignmentRecord.UpdatedBy = CurrentCustomer.Username;
                    r2.AUConsignmentRecord.CreatedOnDT = System.DateTime.UtcNow;
                    r2.AUConsignmentRecord.UpdatedOnDT = System.DateTime.UtcNow;
                    _consignmentRepo.Insert(r2.AUConsignmentRecord);

                    //try this second
                    //AUConsignmentRecord consignment2 = new AUConsignmentRecord() { ConsignmentDesc = "Test" };
                    //consignment2.CreatedOnDT = System.DateTime.UtcNow;
                    //consignment2.UpdatedOnDT = System.DateTime.UtcNow;
                    //consignment2.ConsignmentDate = r2.AUConsignmentRecord.ConsignmentDate;
                    //consignment2.ConsignmentDesc = r2.AUConsignmentRecord.ConsignmentDesc;
                    //_consignmentRepo.Insert(consignment2);



                    /*
                    consignment.ConsignmentDate = r2.AUConsignmentRecord.ConsignmentDate;
                    consignment.ConsignmentDesc = r2.AUConsignmentRecord.ConsignmentDesc;
                    _consignmentRepo.Insert(consignment);
                    */


                    //try 1
                    AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord();
                    testc.AUConsignmentID = r2.AUConsignmentRecord.AUConsignmentID;
                    testc.AUConsignorID = r2.AUConsignorRecord.AUConsignorID;
                    testc.Term = "Help!";
                    r2.AUConsignmentRecord.AUConsignorRecords.Add(testc);
                    _consignmentRepo.Update(r2.AUConsignmentRecord);

                    ////try 2
                    //AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord();
                    //testc.AUConsignmentID = consignment2.AUConsignmentID;
                    //testc.AUConsignorID = r2.AUConsignorRecord.AUConsignorID;
                    //testc.Term = "Help!";
                    //consignment2.AUConsignorRecords.Add(testc);
                    //_consignmentRepo.Update(consignment2);



                    //var toUpdate = r2.AUConsignorRecords.First();
                    //toUpdate.AUConsignmentID = r2.AUConsignmentID;
                    //_consignmentRepo.Update(r2);

                    /*   worked
                    //fails because trying to insert AUConsignor again
                    AUConsignorConsignmentRecord testc = new AUConsignorConsignmentRecord();
                    //AUConsignmentRecord consignment2 = _consignmentRepo.GetById(r2.AUConsignmentID);
                    //testc.AUConsignorID = 1; WORKED
                    testc.AUConsignorID = consignor.AUConsignorID;
                    testc.AUConsignmentID = r2.AUConsignmentID;
                    testc.Term = "F**k";
                    r2.AUConsignorRecords.Add(testc);
                    _consignmentRepo.Update(r2);
                    */

                    //No Good - tried to insert AUConsignor again
                    //AUcc.AUConsignorID = 1;
                    //AUcc.AUConsignmentID = r2.AUConsignmentID;
                    //_consignorconsignmentRepo.Insert(AUcc);




                    //test shit out
                    //AUConsignorRecord c2 = new AUConsignorRecord();
                    //c2.LastName = "consignor Last Name";
                    //c2.AUConsignorID = 1;

                    //**************************************
                    //can only insert the same type passed in
                    //this is f*****g up consignment id for some reason
                    //*************************************************
                    //AUConsignmentRecord c2 = new AUConsignmentRecord();
                    //c2.AUConsignmentID = 99;
                    //c2.ConsignmentDesc = "This is the first internally generated consignment";
                    //_consignmentRepo.Insert(c2);



                    SuccessNotification("Consignment Created Successfully!");
                    return RedirectToRoute(new
                    {
                        Action = "CreateUpdateConsignment",
                        Controller = "AUConsignor",
                        ConsignorId = r2.AUConsignorRecord.AUConsignorID,
                        ConsignmentId = r2.AUConsignmentRecord.AUConsignmentID
                    });
                }
                else
                {

                    //use latest data in consignment rather that stale R2
                    var CurrentCustomer = _authenticationService.GetAuthenticatedCustomer();
                    consignment.UpdatedBy = CurrentCustomer.Username;
                    consignment.UpdatedOnDT = System.DateTime.UtcNow;
                    consignment.ConsignmentDate = r2.AUConsignmentRecord.ConsignmentDate;
                    consignment.ConsignmentDesc = r2.AUConsignmentRecord.ConsignmentDesc;


                    //System.DateTime? cDate = null;
                    //try
                    //{
                    //    cDate = new DateTime(model.DateOfBirthYear.Value, model.DateOfBirthMonth.Value, model.DateOfBirthDay.Value);
                    //}
                    //catch { }


                    r2.AUConsignmentRecord.UpdatedOnDT = consignment.UpdatedOnDT;
                    r2.AUConsignmentRecord.UpdatedBy = consignment.UpdatedBy;

                    //test
                    //AUConsignorRecord c2 = new AUConsignorRecord();
                    //c2.LastName = "consignor Last Name";
                    //c2.AUConsignorID = 1;

                    //consignment.AUConsignorRecords.Add(c2);
                    //ViewBag.RowsAffected = db.Database.ExecuteSqlCommand("UPDATE Course SET Credits = Credits * {0}", multiplier);


                    _consignmentRepo.Update(consignment);

                    //can only insert the same type passed in
                    //AUConsignmentRecord c2 = new AUConsignmentRecord();
                    //c2.AUConsignmentID = 99;
                    //c2.ConsignmentDesc = "This is the second updated description";
                    //_consignmentRepo.Update(c2);


                    //AUConsignorRecord c2 = new AUConsignorRecord();
                    //c2.LastName = "consignor New Last Name";
                    //c2.AUConsignorID = 1;
                    //_consignmentRepo.Insert();



                    _cacheManager.Clear();
                    SuccessNotification("Changed Saved!");
                    //return View(consignment); //now with customer view engine
                    return View("~/Views/AUConsignor/CreateUpdateConsignment.cshtml", r2); //not hit first time??
                    //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml", slider);
                }
            }
            else
            {
                //invalid model will show "default" error messages driven by record annotation/decorations
                var errors = ModelState.Values.SelectMany(v => v.Errors);
                return View("~/Views/AUConsignor/CreateUpdateConsignment.cshtml", r2);
                //return View();
                //return View("~/Views/PromoSlider/CreateUpdatePromoSlider.cshtml"); //not hit first time?
                //return View("~/Plugins/Widgets.PromoSlider/Views/PromoSlider/CreateUpdatePromoSlider.cshtml");
            }
        }