public void Create(Guid auctionId, Guid productId, DateTime startTime, DateTime endTime)
        {
            if (endTime < startTime)
            {
                throw new EndTimeBeforeStartTimeException(
                    string.Format("End time {0} cannot be earlier than start time {1}", endTime, startTime));
            }
            if (endTime < DateTime.Now)
            {
                throw new EndTimeEarlierThanNowException(string.Format("End time {0} cannot be earlier than now",
                    endTime));
            }
            var product = _productRepository.Get(productId);
            if (product == null)
            {
                throw new ProductNotExistException(string.Format("Product with id {0} does not exist", productId));
            }
            if (product.IsSold)
            {
                throw new ProductIsSoldException(product.Name);
            }
            if (_auctionRespository.GetAuctions().Any(a => a.IsActive && a.Product.Id == productId))
            {
                throw new ProductHasActiveAuctionException(product.Name);
            }

            var auction = new Auction
            {
                Id = auctionId,
                AcceptedPrice = product.GetStartPrice() * (decimal)1.5,
                Product = product,
                StartTime = startTime,
                EndTime = endTime,
                IsActive = startTime < DateTime.Now
            };
            _auctionRespository.AddAuction(auction);
        }
        private static void SetUpDatabase()
        {
            var db = new EFContext();
            var customerFacade = new CustomerFacade(new CustomerRepository(db), new AddressRepository(db), null,
                new PasswordHandler());

            var productRepository = new ProductRepository(db);
            var productFacade = new ProductFacade(productRepository);
            var auctionFacade = new AuctionFacade(new AuctionRepository(db), productRepository);

            var customerId = Guid.NewGuid();
            customerFacade.Add(customerId, "Elin", "Danielsson",
                new List<Address>()
                {
                    new Address
                    {
                        AddressType = AddressType.Home,
                        City = "Nykvarn",
                        Country = "Sweden",
                        Id = Guid.NewGuid(),
                        PostalCode = "15531",
                        Street = "Skärarevägen 8"
                    }
                }, "elin", "elin", "*****@*****.**");

            var adminId = Guid.NewGuid();
            customerFacade.Add(adminId, "Gunnar", "Karlsson",
                new List<Address>()
                {
                    new Address
                    {
                        AddressType = AddressType.Work,
                        City = "Stockholm",
                        Country = "Sweden",
                        Id = Guid.NewGuid(),
                        PostalCode = "12345",
                        Street = "Gatan 1"
                    }
                }, "admin", "admin", "*****@*****.**");

            IProductFactory prodcuFactory = new ProductFactory();

            Supplier supplier = new Supplier
            {
                Id = Guid.NewGuid(),
                Name = "Elin"
            };
            var product = prodcuFactory.Create(ProductType.Antique, Guid.NewGuid(), "Vas", 22, 300, supplier) as AntiqueProduct;
            product.TimeEpoch = TimeEpoch.Baroque;

            Customer customer = customerFacade.Get(customerId);

            IList<Bid> bids = new List<Bid>
            {
                new Bid {Amount = 400, Id = Guid.NewGuid(), Customer = customer, Time = DateTime.Now}
            };

            Auction auction = new Auction()
            {
                AcceptedPrice = product.GetStartPrice() * (decimal)1.5,
                Product = product,
                Id = Guid.NewGuid(),
                Bids = bids,
                StartTime = DateTime.Now.AddHours(-2),
                EndTime = DateTime.Now.AddDays(7)
            };

            db.Suppliers.Add(supplier);
            db.AntiqueProducts.Add(product);
            db.Bids.AddRange(bids);
            db.Auctions.Add(auction);
        }
 public void AddAuction(Auction auction)
 {
     auctions.Add(auction);
 }