public void InsertAuction(Auction Auction)
        {
            if (Auction == null)
                throw new ArgumentNullException("Auction");

            _auctionRepo.Insert(Auction);
            _eventPublisher.EntityInserted(Auction);
        }
        public void UpdateAuction(Auction Auction)
        {
            if (Auction == null)
                throw new ArgumentNullException("Auction");

            _auctionRepo.Update(Auction);
            _eventPublisher.EntityUpdated(Auction);
        }
 public Bid GetHighestBidForAuction(Auction auction)
 {
     return auction.Bids.OrderBy(b => b.Amount).LastOrDefault();
 }
        protected virtual void PrepareAuctionModel(AuctionModel model, Auction auction,
            bool setPredefinedValues, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            //if (auction != null)
            //{
            //    var parentGroupedProduct = _productService.GetProductById(auction.ParentGroupedProductId);
            //    if (parentGroupedProduct != null)
            //    {
            //        model.AssociatedToProductId = auction.ParentGroupedProductId;
            //        model.AssociatedToProductName = parentGroupedProduct.Name;
            //    }
            //}

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            //model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name;
            //model.BaseDimensionIn = _measureService.GetMeasureDimensionById(_measureSettings.BaseDimensionId).Name;
            if (auction != null)
            {
                model.CreatedOn = _dateTimeHelper.ConvertToUserTime(auction.CreatedOnUtc, DateTimeKind.Utc);
                model.UpdatedOn = _dateTimeHelper.ConvertToUserTime(auction.UpdatedOnUtc, DateTimeKind.Utc);
            }

            ////little performance hack here
            ////there's no need to load attributes, categories, manufacturers when creating a new product
            ////anyway they're not used (you need to save a product before you map add them)
            //if (auction != null)
            //{
            //    foreach (var productAttribute in _productAttributeService.GetAllProductAttributes())
            //    {
            //        model.AvailableProductAttributes.Add(new SelectListItem
            //        {
            //            Text = productAttribute.Name,
            //            Value = productAttribute.Id.ToString()
            //        });
            //    }
            //    foreach (var manufacturer in _manufacturerService.GetAllManufacturers(showHidden: true))
            //    {
            //        model.AvailableManufacturers.Add(new SelectListItem
            //        {
            //            Text = manufacturer.Name,
            //            Value = manufacturer.Id.ToString()
            //        });
            //    }
            //    var allCategories = _categoryService.GetAllCategories(showHidden: true);
            //    foreach (var category in allCategories)
            //    {
            //        model.AvailableCategories.Add(new SelectListItem
            //        {
            //            Text = category.GetFormattedBreadCrumb(allCategories),
            //            Value = category.Id.ToString()
            //        });
            //    }
            //}

            ////copy product
            //if (auction != null)
            //{
            //    model.CopyProductModel.Id = auction.Id;
            //    model.CopyProductModel.Name = "Copy of " + auction.Name;
            //    model.CopyProductModel.Published = true;
            //    model.CopyProductModel.CopyImages = true;
            //}

            ////templates
            //var templates = _productTemplateService.GetAllProductTemplates();
            //foreach (var template in templates)
            //{
            //    model.AvailableProductTemplates.Add(new SelectListItem
            //    {
            //        Text = template.Name,
            //        Value = template.Id.ToString()
            //    });
            //}

            //vendors
            //model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
            model.AvailableVendors.Add(new SelectListItem
            {
                Text = _localizationService.GetResource("Admin.Catalog.Products.Fields.Vendor.None"),
                Value = "0"
            });
            var vendors = _vendorService.GetAllVendors(showHidden: true);
            foreach (var vendor in vendors)
            {
                model.AvailableVendors.Add(new SelectListItem
                {
                    Text = vendor.Name,
                    Value = vendor.Id.ToString()
                });
            }

            ////delivery dates
            //model.AvailableDeliveryDates.Add(new SelectListItem
            //{
            //    Text = _localizationService.GetResource("Admin.Catalog.Products.Fields.DeliveryDate.None"),
            //    Value = "0"
            //});
            //var deliveryDates = _shippingService.GetAllDeliveryDates();
            //foreach (var deliveryDate in deliveryDates)
            //{
            //    model.AvailableDeliveryDates.Add(new SelectListItem
            //    {
            //        Text = deliveryDate.Name,
            //        Value = deliveryDate.Id.ToString()
            //    });
            //}

            ////warehouses
            //var warehouses = _shippingService.GetAllWarehouses();
            //model.AvailableWarehouses.Add(new SelectListItem
            //{
            //    Text = _localizationService.GetResource("Admin.Catalog.Products.Fields.Warehouse.None"),
            //    Value = "0"
            //});
            //foreach (var warehouse in warehouses)
            //{
            //    model.AvailableWarehouses.Add(new SelectListItem
            //    {
            //        Text = warehouse.Name,
            //        Value = warehouse.Id.ToString()
            //    });
            //}

            ////multiple warehouses
            //foreach (var warehouse in warehouses)
            //{
            //    var pwiModel = new ProductModel.ProductWarehouseInventoryModel
            //    {
            //        WarehouseId = warehouse.Id,
            //        WarehouseName = warehouse.Name
            //    };
            //    if (auction != null)
            //    {
            //        var pwi = auction.ProductWarehouseInventory.FirstOrDefault(x => x.WarehouseId == warehouse.Id);
            //        if (pwi != null)
            //        {
            //            pwiModel.WarehouseUsed = true;
            //            pwiModel.StockQuantity = pwi.StockQuantity;
            //            pwiModel.ReservedQuantity = pwi.ReservedQuantity;
            //            pwiModel.PlannedQuantity = _shipmentService.GetQuantityInShipments(auction, pwi.WarehouseId, true, true);
            //        }
            //    }
            //    model.ProductWarehouseInventoryModels.Add(pwiModel);
            //}

            ////product tags
            //if (auction != null)
            //{
            //    var result = new StringBuilder();
            //    for (int i = 0; i < auction.ProductTags.Count; i++)
            //    {
            //        var pt = auction.ProductTags.ToList()[i];
            //        result.Append(pt.Name);
            //        if (i != auction.ProductTags.Count - 1)
            //            result.Append(", ");
            //    }
            //    model.ProductTags = result.ToString();
            //}

            ////tax categories
            //var taxCategories = _taxCategoryService.GetAllTaxCategories();
            //model.AvailableTaxCategories.Add(new SelectListItem { Text = "---", Value = "0" });
            //foreach (var tc in taxCategories)
            //    model.AvailableTaxCategories.Add(new SelectListItem { Text = tc.Name, Value = tc.Id.ToString(), Selected = auction != null && !setPredefinedValues && tc.Id == auction.TaxCategoryId });

            ////baseprice units
            //var measureWeights = _measureService.GetAllMeasureWeights();
            //foreach (var mw in measureWeights)
            //    model.AvailableBasepriceUnits.Add(new SelectListItem { Text = mw.Name, Value = mw.Id.ToString(), Selected = auction != null && !setPredefinedValues && mw.Id == auction.BasepriceUnitId });
            //foreach (var mw in measureWeights)
            //    model.AvailableBasepriceBaseUnits.Add(new SelectListItem { Text = mw.Name, Value = mw.Id.ToString(), Selected = auction != null && !setPredefinedValues && mw.Id == auction.BasepriceBaseUnitId });

            ////specification attributes
            //var specificationAttributes = _specificationAttributeService.GetSpecificationAttributes();
            //for (int i = 0; i < specificationAttributes.Count; i++)
            //{
            //    var sa = specificationAttributes[i];
            //    model.AddSpecificationAttributeModel.AvailableAttributes.Add(new SelectListItem { Text = sa.Name, Value = sa.Id.ToString() });
            //    if (i == 0)
            //    {
            //        //attribute options
            //        foreach (var sao in _specificationAttributeService.GetSpecificationAttributeOptionsBySpecificationAttribute(sa.Id))
            //            model.AddSpecificationAttributeModel.AvailableOptions.Add(new SelectListItem { Text = sao.Name, Value = sao.Id.ToString() });
            //    }
            //}
            ////default specs values
            //model.AddSpecificationAttributeModel.ShowOnProductPage = true;

            ////discounts
            //model.AvailableDiscounts = _discountService
            //    .GetAllDiscounts(DiscountType.AssignedToSkus, showHidden: true)
            //    .Select(d => d.ToModel())
            //    .ToList();
            //if (!excludeProperties && auction != null)
            //{
            //    model.SelectedDiscountIds = auction.AppliedDiscounts.Select(d => d.Id).ToArray();
            //}

            ////default values
            //if (setPredefinedValues)
            //{
            //    model.MaximumCustomerEnteredPrice = 1000;
            //    model.MaxNumberOfDownloads = 10;
            //    model.RecurringCycleLength = 100;
            //    model.RecurringTotalCycles = 10;
            //    model.RentalPriceLength = 1;
            //    model.StockQuantity = 10000;
            //    model.NotifyAdminForQuantityBelow = 1;
            //    model.OrderMinimumQuantity = 1;
            //    model.OrderMaximumQuantity = 10000;

            //    model.UnlimitedDownloads = true;
            //    model.IsShipEnabled = true;
            //    model.AllowCustomerReviews = true;
            //    model.Published = true;
            //    model.VisibleIndividually = true;
            //}
        }