public ActionResult Create(CreateProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var supplier = _productFacade.GetSuppliers().FirstOrDefault(s => s.Id == model.SupplierId);
                if (supplier == null)
                {
                    supplier = new Supplier { Id = Guid.NewGuid(), Name = model.SupplierName };
                }

                var product = _productFactory.Create((ProductType)model.ProductTypeId, Guid.NewGuid(), model.Name,
                    model.Provision, model.StartPrice, supplier);

                switch ((ProductType)model.ProductTypeId)
                {
                    case ProductType.Antique:
                        (product as AntiqueProduct).TimeEpoch = (TimeEpoch)model.TimeEpochId;
                        break;
                    case ProductType.Mass:
                    case ProductType.Modern:
                        var designer = _productFacade.GetDesigners().FirstOrDefault(d => d.Id == model.DesignerId);
                        if (designer == null)
                        {
                            designer = new Designer { Id = Guid.NewGuid(), Name = model.DesignerName };
                        }
                        (product as DesignerProduct).Designer = designer;
                        break;
                    default:
                        break;
                }
                _productFacade.Add(product);
            }
            return RedirectToAction("Index");
        }
 public Product Create(ProductType productType, Guid productId, string name, decimal provision, 
     decimal startprice, Supplier supplier)
 {
     switch (productType)
     {
         case ProductType.Antique:
             return new AntiqueProduct
             {
                 Id = productId,
                 Name = name,
                 Provision = provision,
                 StartPrice = startprice,
                 Supplier = supplier
             };
         case ProductType.Mass:
             return new MassProduct
             {
                 Id = productId,
                 Name = name,
                 Provision = provision,
                 StartPrice = startprice,
                 Supplier = supplier
             };
         case ProductType.Modern:
             return new ModernProduct
             {
                 Id = productId,
                 Name = name,
                 Provision = provision,
                 StartPrice = startprice,
                 Supplier = supplier
             };
         default:
             return null;
     }
 }
        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);
        }