Пример #1
0
        public void CreateNieuweBestelling(Bestelling bestelling)
        {
            query = @"EXECUTE CreateNieuweBestelling " + bestelling.HuidigeKlant.Klantnummer + ", " + bestelling.Ophalen + ";";
            Database.Execute(query);
            query = @"SELECT dbo.GetNieuweBestellingId() AS Id;";
            DataTable result = Database.Execute(query);
            DataRow   row    = result.Rows[0];
            int       Id     = Convert.ToInt32(row["Id"].ToString());

            foreach (Product product in bestelling.Products)
            {
                query = @"EXECUTE AddProductToBestelling " + Id + ", " + product.Id + ";";
                Database.Execute(query);
            }
            foreach (Pizza pizza in bestelling.Pizzas)
            {
                if (pizza is StandaardPizza)
                {
                    StandaardPizza newPizza = (StandaardPizza)pizza;
                    query = @"EXECUTE AddStandaardPizzaToBestelling " + Id + ", " + newPizza.Id + "; ";
                    Database.Execute(query);
                }
                else if (pizza is CustomPizza)
                {
                    CustomPizza newPizza = (CustomPizza)pizza;
                    query = @"INSERT INTO CustomPizza VALUES(" + Id + ", '" + newPizza.Vorm + "', '" + newPizza.Formaat + "');";
                    Database.Execute(query);
                    foreach (Ingredient ingredient in newPizza.Ingredienten)
                    {
                        query = @"INSERT INTO CusPizIng VALUES(" + Id + ", " + ingredient.Id + ");";
                        Database.Execute(query);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Map DBPizza => APizza
        /// Uses enum to determine which crust class to return.
        /// Note: premade pizza classes have constructors to set all variables properly.
        /// Therefore, they do not need any data tobe passed innto them.
        /// Custom pizza however only has 1 constructor that requires crust, size, and toppings
        /// to be passed into them.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public APizza Map(DBPizza entity)
        {
            APizza pizza;

            switch (entity.PIZZA)
            {
            case PIZZAS.CUSTOM:
                ACrust          crust    = mapperCrust.Map(entity.DBCrust);
                ASize           size     = mapperSize.Map(entity.DBSize);
                List <ATopping> toppings = new List <ATopping>();
                entity.DBPlacedToppings.ToList().ForEach(placedTopping => toppings.Add(mapperTopping.Map(placedTopping.Topping)));

                pizza = new CustomPizza(crust, size, toppings);
                break;

            case PIZZAS.HAWAIIAN:
                pizza = new HawaiianPizza(mapperSize.Map(entity.DBSize));
                break;

            case PIZZAS.MEAT:
                pizza = new MeatPizza(mapperSize.Map(entity.DBSize));
                break;

            case PIZZAS.VEGAN:
                pizza = new VeganPizza(mapperSize.Map(entity.DBSize));
                break;

            default:
                throw new ArgumentException("Pizza not recognized. Pizza could not be mapped properly");
            }

            pizza.CalculatePrice();
            pizza.ID = entity.ID;
            return(pizza);
        }
Пример #3
0
        public CustomPizza FromCreateCustomPizzaModel(IPizzaFactoryDbContext pizzaContext, CreateCustomPizzaModel customPizzaModel)
        {
            var     ingredients = new List <Ingredient>();
            decimal price       = 2.00M;

            foreach (var item in customPizzaModel.Ingredients)
            {
                var ingredient = pizzaContext.Ingredients.Find(item);
                if (ingredient.Name != "none" && !ingredients.Contains(ingredient))
                {
                    ingredients.Add(ingredient);
                    price += ingredient.Price;
                }
            }

            CustomPizza pizza = new CustomPizza()
            {
                Name        = customPizzaModel.Name,
                Description = customPizzaModel.Description,
                Ingredients = ingredients,
                Price       = price
            };

            return(pizza);
        }
Пример #4
0
        public void Test_OrderAddPizza()
        {
            CustomPizza tempP = new CustomPizza();

            tempP.Type = "Meat Pizza";
            tempP.AddCrust(new Crust("regular", 1.0m));
            tempP.AddSize(new Size("medium", 4.0m));
            tempP.AddTopping(new Topping("beef", 0.66m));
            tempP.AddTopping(new Topping("chicken", 1.0m));
            tempP.AddTopping(new Topping("ham", 0.75m));
            tempP.AddTopping(new Topping("mushroom", 0.50m));
            tempP.AddTopping(new Topping("olive", 0.33m));

            decimal TotalPrice = 1.0m + 4.0m + 0.66m + 1.0m + 0.75m + 0.50m + 0.33m;

            var expected = "Meat Pizza : medium : regular : beef chicken ham mushroom olive - " + TotalPrice;

            Order sut = new Order();

            sut.AddPizza(tempP);

            var actual = sut.Pizzas[0].ToString();

            Assert.Equal(expected, actual);
        }
        public void AddPizza(CustomPizza pizza)
        {
            context.Add(mapper.Map(pizza));


            context.SaveChanges();
        }
Пример #6
0
 public void Delete(CustomPizza pizza)
 {
     db.CustIngredients.RemoveRange(
         db.CustIngredients.Where(custI => custI.CPId == pizza.Id)
         );
     db.CustomPizzas.Remove(pizza);
 }
Пример #7
0
        public void Test1()
        {
            //arrange
            CustomPizza p1 = new CustomPizza();

            p1.Crust = new Crust("stuffed");
            p1.Size  = new Size("large");
            Topping[] toppings = new Topping[4];
            toppings[0] = new Topping("pepperoni");
            toppings[1] = new Topping("hamburger");
            toppings[2] = new Topping("porkchop");
            toppings[3] = new Topping("bacon");
            List <Topping> t1 = new List <Topping>();

            t1.AddRange(toppings);
            p1.Toppings     = t1;
            p1.ToppingCount = toppings.Length;
            var expectedCrust        = "stuffed";
            var expectedSize         = "large";
            var expectedToppingCount = 4;
            var expectedPrice        = 9;
            //act
            var actualCrust        = p1.Crust.Name;
            var actualSize         = p1.Size.Name;
            var actualToppingCount = p1.ToppingCount;
            var actualPrice        = p1.Price();

            //assert
            Assert.True(
                expectedCrust == actualCrust && expectedSize == actualSize &&
                expectedToppingCount == actualToppingCount && expectedPrice == actualPrice);
        }
        public IHttpActionResult DeleteCustomPizza(int id)
        {
            CustomPizza customPizza = map.CustomPizzaRepo.RetrieveById(id);

            if (customPizza == null)
            {
                return(NotFound());
            }

            if (customPizza.UserId != user.UserId)
            {
                return(Unauthorized());
            }

            // Delete ingredients first - their dependencies won't let the pizza
            // be removed.
            var ingredientList = map.CustIngredientsRepo.RetrieveAll()
                                 .Where(item => item.CPId == id);

            foreach (var ingredient in ingredientList)
            {
                map.CustIngredientsRepo.Delete(ingredient);
            }
            map.CustIngredientsRepo.Save();

            // Then delete the pizza.
            map.CustomPizzaRepo.Delete(customPizza);
            map.CustomPizzaRepo.Save();

            return(Ok(customPizza));
        }
        private static void SelectToppings(Order order, CustomPizza pizza)
        {
            //Boolean MoreToppings = false;
            Console.WriteLine("Do you want to add more toppings? (Y/N)");
            var input = Console.ReadLine();

            if (input.ToLower() == "y")
            {
                DisplayToppings();

                var         ToppingSelect = Console.ReadLine();
                IRepository repository    = Dependencies.CreateRepository();
                var         holder        = repository.GetToppingByIndex(int.Parse(ToppingSelect));
                Toppings    topping       = new Toppings
                {
                    Name       = holder.Name,
                    Price      = holder.Price,
                    PizzaLogId = pizza.PizzaLogId,
                    Id         = holder.Id
                };
                pizza.AddToppings(topping);

                order.ListOfToppings.Add(holder);
                order.Cost += holder.Price;
            }



            // foreach (var item in order.ListOfCrusts)
            // {
            //     Console.WriteLine($"{item.Name} {item.Price}");
            // }
        }
Пример #10
0
        public IHttpActionResult PostCustomPizza(CustomPizza customPizza)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CustomPizzas.Add(customPizza);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CustomPizzaExists(customPizza.CustomPizzaName))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = customPizza.CustomPizzaName }, customPizza));
        }
Пример #11
0
        public APizza Map(Pizza model)
        {
            APizza pizza;

            switch (model.PizzaType)
            {
            case Entities.PIZZA_TYPE.Meat:
                pizza = new MeatPizza();
                break;

            case Entities.PIZZA_TYPE.Vegan:
                pizza = new VeganPizza();
                break;

            case Entities.PIZZA_TYPE.Custom:
                pizza = new CustomPizza();
                break;

            default:
                throw new ArgumentException("PizzaMapper encountered an unknown type when mapping from DB Model to Domain Model");
            }

            pizza.Crust = crustMapper.Map(model.Crust);
            pizza.Size  = sizeMapper.Map(model.Size);
            List <Domain.Models.Topping> toppings = new List <Domain.Models.Topping>();

            model.Toppings.ForEach(topping => toppings.Add(toppingMapper.Map(topping)));
            pizza.Toppings = toppings;
            //pizza.Price = model.Price;
            return(pizza);
        }
Пример #12
0
        static CustomPizza MakePizza(User u, CustomPizza p1)
        {
            Console.WriteLine(
                "What type of crust would you like? (stuffed,pan,hand)");
            Crust c = new Crust(Console.ReadLine());

            p1.Crust = c;
            Console.WriteLine("What size? (small/medium/large)");
            Size s = new Size(Console.ReadLine());

            p1.Size = s;
            Topping[] toppings = new Topping[4];
            for (int i = 0; i < 4; ++i)
            {
                Console.WriteLine("What are you toppings? (2 min, 5 max)");
                string test = Console.ReadLine();
                if (test == "")
                {
                    i = 5;
                }
                else
                {
                    toppings[i] = new Topping(test);
                    p1.Toppings.Add(toppings[i]);
                }
            }
            p1.ToppingCount = p1.Toppings.Count;
            return(p1);
        }
Пример #13
0
        public IHttpActionResult PutCustomPizza(string id, CustomPizza customPizza)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customPizza.CustomPizzaName)
            {
                return(BadRequest());
            }

            db.Entry(customPizza).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomPizzaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #14
0
        /// <summary>
        /// Map DBPizza => APizza
        /// Uses enum to determine which crust class to return.
        /// Note: premade pizza classes have constructors to set all variables properly.
        /// Therefore, they do not need any data tobe passed innto them.
        /// Custom pizza however only has 1 constructor that requires crust, size, and toppings
        /// to be passed into them.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public APizza Map(DBPizza entity)
        {
            APizza pizza;

            switch (entity.PIZZA)
            {
            case Entities.EntityModels.PIZZAS.CUSTOM:
                Crust          crust    = mapperCrust.Map(entity.DBCrust);
                Size           size     = mapperSize.Map(entity.DBSize);
                List <Topping> toppings = new List <Topping>();
                entity.DBToppings.ForEach(Topping => toppings.Add(mapperTopping.Map(Topping)));

                pizza = new CustomPizza(crust, size, toppings);
                break;

            case Entities.EntityModels.PIZZAS.HAWAIIAN:
                pizza = new HawaiianPizza();
                break;

            case Entities.EntityModels.PIZZAS.MEAT:
                pizza = new MeatPizza();
                break;

            case Entities.EntityModels.PIZZAS.VEGAN:
                pizza = new VeganPizza();
                break;

            default:
                throw new ArgumentException("Size not recognized. Size could not be mapped properly");
            }

            return(pizza);
        }
Пример #15
0
        private static CustomPizza MakeCustomPizza()
        {
            var cp = new CustomPizza();

            cp.Toppings = GetToppings();
            _pizzaSingleton.AddPizza(cp);
            return(cp);
        }
Пример #16
0
        public void Test_CustomPizzaSize()
        {
            var sut = new CustomPizza();

            var actual = sut.Size;

            Assert.NotEmpty(actual);
        }
Пример #17
0
        public void Test_PizzaOrderTotal()
        {
            var sut = new CustomPizza();

            var actual = sut.TotalOrderedPizzas;

            Assert.NotEmpty(actual.ToString());
        }
Пример #18
0
        public void Test_PizzaToppings()
        {
            var sut = new CustomPizza();

            var actual = sut.Toppings;

            Assert.Empty(actual);
        }
Пример #19
0
        public void Test_CustomPizza()
        {
            var sut = new CustomPizza();

            string actual = sut.ToString();

            Assert.NotNull(actual);
        }
Пример #20
0
        public void Test_ToppingsStrings()
        {
            var sut = new CustomPizza();

            List <string> actual = sut.ToppingStrings();

            Assert.IsType <List <string> >(actual);
        }
Пример #21
0
        public void Test_PizzaName()
        {
            var sut = new CustomPizza();

            var actual = sut.Name;

            Assert.NotEmpty(actual.ToString());
        }
Пример #22
0
        public void Test_CustomPizza()
        {
            var sut = new CustomPizza();

            Assert.NotNull(sut.Crust);
            Assert.NotNull(sut.Size);
            Assert.NotNull(sut.Toppings);
        }
Пример #23
0
        public void Test_CustomIsCorrect()
        {
            var sut = new CustomPizza(new CheesePizza());

            Console.WriteLine("Cheese base:", sut.Name, sut.Size, sut.Crust, sut.Sauce, sut.ToppingsString(), sut.Price);
            var sut1 = new CustomPizza(new PestoPizza());

            Console.WriteLine("Pesto base:", sut1.Name, sut1.Size, sut1.Crust, sut1.Sauce, sut1.ToppingsString(), sut1.Price);
        }
Пример #24
0
        public static void SeedData()
        {
            // For some reason EF doesn't like this
            // if a command runs that doesn't update a row
            // EF will completely error out and stop all transactionsg
            //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Toppings_ToppingType on dbo.Toppings SET ( IGNORE_DUP_KEY = ON )");
            //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Crusts_CrustType on dbo.Crusts SET ( IGNORE_DUP_KEY = ON )");
            //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Stores_Name on dbo.Stores SET ( IGNORE_DUP_KEY = ON )");
            //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Sizes_SizeType on dbo.Sizes SET ( IGNORE_DUP_KEY = ON )");
            //_context.Database.ExecuteSqlRaw("ALTER INDEX IX_Customers_Name on dbo.Customers SET ( IGNORE_DUP_KEY = ON )");

            OrderRepository orderRepository = new OrderRepository(DbContextSingleton.Instance.Context);
            Customer        cust            = new Customer("Nick");

            AStore store = new NewYorkStore();

            store.Name = "Test New York Store";

            Order order = new Order();

            order.Store    = store;
            order.Customer = cust;

            APizza pizza = new CustomPizza();

            pizza.Crust    = new DeepDishCrust();
            pizza.Size     = new SmallSize();
            pizza.Toppings = new List <Topping>();
            pizza.Toppings.Add(new BaconTopping());
            pizza.Toppings.Add(new PepperoniTopping());

            order.Pizzas = new List <APizza>()
            {
                pizza,
                new VeganPizza(),
                new MeatPizza()
            };

            orderRepository.Add(order);

            pizza.Size     = new LargeSize();
            pizza.Toppings = new List <Topping>();
            pizza.Toppings.Add(new BaconTopping());
            pizza.Toppings.Add(new OnionTopping());
            order.Store.Name = "Test Store 2";
            orderRepository.Add(order);


            /*
             * public Store Store { get; set; }
             * public Customer Customer { get; set; }
             * public List<Pizza> Pizzas { get; set; }
             * public decimal TotalPrice { get; set; }
             * public DateTime OrderTime { get; set; }
             *
             */
        }
Пример #25
0
        public void Test_CreateCustomPizzaDefaultCrust()
        {
            var sut      = new CustomPizza();
            var expected = new Crust("", 0m).Name;

            var actual = sut.Crust.Name;

            Assert.Equal(expected, actual);
        }
Пример #26
0
        public void Test_CreateCustomPizzaDefaultToppings()
        {
            var sut      = new CustomPizza();
            var expected = new Size("", 0m).Name;

            var actual = sut.Size.Name;

            Assert.Equal(expected, actual);
        }
Пример #27
0
        public void Test_CreateCustomPizzaName()
        {
            var sut      = new CustomPizza();
            var expected = "Custom Pizza";

            var actual = sut.Type;

            Assert.Equal(expected, actual);
        }
Пример #28
0
        private static CustomPizza SelectCrust(CustomPizza customPizza)
        {
            string input = System.Console.ReadLine();
            int    index = int.Parse(input);
            Crust  crust = _crustSingleton.Crusts[index - 1];

            customPizza.Crust = crust;
            return(customPizza);
        }
Пример #29
0
        public CustomPizza AddCustomPizza()
        {
            // CustomPizza thePizza = new CustomPizza();
            APizza      thePizzaProduct = pizzaFactory.Create <CustomPizza>();
            CustomPizza thePizza        = (CustomPizza)thePizzaProduct;

            thePizza.BuildPizza();
            return(thePizza);
        }
Пример #30
0
        public void Test_CustomPizza()
        {
            //arrange
            var sut = new CustomPizza();

            //act

            //assert
            Assert.True(sut.name.Equals("Custom Pizza"));
        }