public IActionResult AddPrice(PizzaPrice pizzaPrice)
 {
     pizzaRepository.AddPrice(pizzaPrice);
     return(RedirectToAction("Details", new
     {
         Id = pizzaPrice.PizzaId
     }));
 }
Exemplo n.º 2
0
        private void Test_PizzaPriceExists()
        {
            var        sut  = new PizzaPrice();
            PizzaPrice sut1 = new PizzaPrice();

            var actual = sut;

            Assert.IsType <PizzaPrice>(actual);
            Assert.Equal <decimal>(12.50M, actual.CalculatePrice("", "", 0));
        }
Exemplo n.º 3
0
        private static decimal calculateToppingsCost(OrderDTO order, PizzaPrice prices)
        {
            var cost = 0.0M;

            cost += (order.Pepperoni) ? prices.PepperoniCost : 0M;
            cost += (order.Sausage) ? prices.SausageCost : 0M;
            cost += (order.Onion) ? prices.OnionCost : 0M;
            cost += (order.Green_Pepper) ? prices.GreenPepperCost : 0M;

            return(cost);
        }
Exemplo n.º 4
0
        public static decimal CalculateCost(OrderDTO order)
        {
            decimal    cost   = 0M;
            PizzaPrice prices = getPizzaPrice();

            cost += calculateSizeCost(order, prices);
            cost += calculateCrustCost(order, prices);
            cost += calculateToppingsCost(order, prices);

            return(cost);
        }
Exemplo n.º 5
0
        public void AddPrice(PizzaPrice pizzaPrice)
        {
            //var shortPiza = Database.Pizzas
            //    .Select(x=>new { Id = x.Id, Name = x.Name })
            //    .FirstOrDefault(x => x.Id == pizzaPrice.PizzaId);
            var dbPizza = Database.Pizzas
                          .Include(x => x.PizzaPrices)
                          .FirstOrDefault(x => x.Id == pizzaPrice.PizzaId);

            dbPizza.PizzaPrices.Add(pizzaPrice);
            Database.SaveChanges();
        }
        public Task <int> SavePizzaPriceAsync(PizzaPrice pizzaPrice)
        {
            pizzaPrice.PricePerSquareInch = pizzaPrice.Price / (Math.PI * Math.Pow(pizzaPrice.Diameter / 2, 2));

            if (pizzaPrice.Id != 0)
            {
                return(database.UpdateAsync(pizzaPrice));
            }
            else
            {
                return(database.InsertAsync(pizzaPrice));
            }
        }
Exemplo n.º 7
0
        private static DTO.PricesDTO converDTOPrices(PizzaPrice prices)
        {
            DTO.PricesDTO dtoPrices = new DTO.PricesDTO();
            dtoPrices.Id = prices.Id;
            dtoPrices.Onions = prices.Onions;
            dtoPrices.Pepperoni = prices.Pepperoni;
            dtoPrices.Sausage = prices.Sausage;
            dtoPrices.GreenPeppers = prices.GreenPeppers;
            dtoPrices.PriceCrustRegular = prices.PriceCrustRegular;
            dtoPrices.PriceCrustThick = prices.PriceCrustThick;
            dtoPrices.PriceCrustThin = prices.PriceCrustThin;
            dtoPrices.PriceSizeLarge = prices.PriceSizeLarge;
            dtoPrices.PriceSizeMedium = prices.PriceSizeMedium;
            dtoPrices.PriceSizeSmall = prices.PriceSizeSmall;

            return dtoPrices;
        }
Exemplo n.º 8
0
        private static decimal calculateCrustCost(OrderDTO order, PizzaPrice prices)
        {
            decimal cost = 0.0M;

            switch (order.Crust)
            {
            case DTO.Enums.CrustType.Regular:
                cost = prices.RegularCrustCost;
                break;

            case DTO.Enums.CrustType.Thin:
                cost = prices.ThinCrustCost;
                break;

            case DTO.Enums.CrustType.Thick:
                cost = prices.ThickCrustCost;
                break;

            default:
                break;
            }
            return(cost);
        }
Exemplo n.º 9
0
        private List <PizzaPrice> GetPricesForPizza(int pizzaId)
        {
            var    list    = new List <PizzaPrice>();
            string query   = "select * from PizzaPrices where PizzaId = @pizzaId";
            var    command = new SqlCommand(query, Connection);

            command.Parameters.AddWithValue("pizzaId", pizzaId);
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    double price      = (double)reader["Price"];
                    int    size       = (int)reader["Size"];
                    var    pizzaPrice = new PizzaPrice
                    {
                        PizzaId = pizzaId,
                        Price   = price,
                        Size    = size
                    };
                    list.Add(pizzaPrice);
                }
            }
            return(list);
        }
Exemplo n.º 10
0
        private static decimal calculateSizeCost(OrderDTO order, PizzaPrice prices)
        {
            decimal cost = 0.0M;

            switch (order.Size)
            {
            case DTO.Enums.SizeType.Small:
                cost = prices.SmallSizeCost;
                break;

            case DTO.Enums.SizeType.Medium:
                cost = prices.MediumSizeCost;
                break;

            case DTO.Enums.SizeType.Large:
                cost = prices.LargeSizeCost;
                break;

            default:
                break;
            }

            return(cost);
        }
Exemplo n.º 11
0
 protected override void CalculatePrice()
 {
     Price = new PizzaPrice().CalculatePrice(PizzaCrust.Crust, PizzaSize.Size, PizzaToppings.Count);
 }
Exemplo n.º 12
0
        public void GetMenu()
        {
            var pizzaList           = new List <Pizza>();
            var pizzaPriceList      = new List <PizzaPrice>();
            var ingredientPriceList = new List <IngredientPrice>();

            Pizza pizza1 = new Pizza {
                Name = "Pizza1"
            };
            Pizza pizza2 = new Pizza {
                Name = "Pizza2"
            };

            Ingredient ingredient1 = new Ingredient {
                Name = "Ingredient 1"
            };
            Ingredient ingredient2 = new Ingredient {
                Name = "Ingredient 2"
            };

            pizza1.Ingredients.Add(new PizzaIngredient {
                Pizza = pizza1, Ingredient = ingredient1, IngredientId = ingredient1.Id
            });
            pizza1.Ingredients.Add(new PizzaIngredient {
                Pizza = pizza1, Ingredient = ingredient2, IngredientId = ingredient2.Id
            });

            pizzaList.Add(pizza1);
            pizzaList.Add(pizza2);

            IngredientPrice ingredientPrice = new IngredientPrice {
                Date = new DateTime(2018, 01, 01), Ingredient = ingredient1, Price = 10
            };
            IngredientPrice ingredientPrice2 = new IngredientPrice {
                Date = new DateTime(2019, 01, 01), Ingredient = ingredient1, Price = 15
            };

            PizzaPrice pizzaPrice = new PizzaPrice {
                Date = new DateTime(2018, 01, 01), Pizza = pizza1, Price = 100
            };
            PizzaPrice pizzaPrice2 = new PizzaPrice {
                Date = new DateTime(2018, 01, 01), Pizza = pizza2, Price = 110
            };

            pizzaPriceList.Add(pizzaPrice);
            pizzaPriceList.Add(pizzaPrice2);

            ingredientPriceList.Add(ingredientPrice);
            ingredientPriceList.Add(ingredientPrice2);

            Mapper.Reset();
            Mapper.Initialize(cfg => cfg.AddProfile <AutoMapperProfile>());

            var mock = new Mock <IDataAccess>();

            mock.Setup(r => r.Pizzas.GetAll()).Returns(pizzaList);

            mock.Setup(m => m.PizzaPrices.Get(It.IsAny <Expression <Func <PizzaPrice, bool> > >())).Returns <Expression <Func <PizzaPrice, bool> > >((func) =>
            {
                return(pizzaPriceList.Where(func.Compile()).ToList());
            });

            mock.Setup(m => m.IngredientPrices.Get(It.IsAny <Expression <Func <IngredientPrice, bool> > >())).Returns <Expression <Func <IngredientPrice, bool> > >((func) =>
            {
                return(ingredientPriceList.Where(func.Compile()).ToList());
            });

            DataController controller = new DataController(mock.Object, null);

            var result = controller.GetMenu();

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));

            Assert.IsNotNull(((OkObjectResult)result).Value);

            Assert.AreEqual(((ICollection <PizzaViewModel>)((OkObjectResult)result).Value).Count, 2);
        }
 public void AddPrice(PizzaPrice pizzaPrice)
 {
     throw new System.NotImplementedException();
 }
 public Task <int> DeletePizzaPriceAsync(PizzaPrice pizzaPrice)
 {
     return(database.DeleteAsync(pizzaPrice));
 }
 public async Task EditPizzaPriceAsync(PizzaPrice pizzaPrice)
 {
     _ = await _navigationService.Navigate <PizzaPriceEditViewModel, PizzaPrice>(pizzaPrice);
 }
Exemplo n.º 16
0
        public void UnitOfWorkTests()
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Test;Trusted_Connection=True;");

            ApplicationDbContext context = new ApplicationDbContext(optionsBuilder.Options);

            context.Database.EnsureCreated();

            UnitOfWork unit = new UnitOfWork(context);

            Pizza pizza1 = new Pizza {
                Name = "Pizza1"
            };
            Pizza pizza2 = new Pizza {
                Name = "Pizza2"
            };

            Ingredient ingredient1 = new Ingredient {
                Name = "Ingredient 1"
            };
            Ingredient ingredient2 = new Ingredient {
                Name = "Ingredient 2"
            };

            IngredientPrice ingredientPrice = new IngredientPrice {
                Date = new DateTime(2018, 01, 01), Ingredient = ingredient1, Price = 10
            };
            IngredientPrice ingredientPrice2 = new IngredientPrice {
                Date = new DateTime(2019, 01, 01), Ingredient = ingredient1, Price = 15
            };

            PizzaPrice pizzaPrice = new PizzaPrice {
                Date = new DateTime(2018, 01, 01), Pizza = pizza1, Price = 100
            };
            PizzaPrice pizzaPrice2 = new PizzaPrice {
                Date = new DateTime(2018, 01, 01), Pizza = pizza2, Price = 110
            };

            unit.Ingredients.Create(ingredient1);
            unit.Ingredients.Create(ingredient2);

            unit.SaveChanges();

            pizza1.Ingredients.Add(new PizzaIngredient {
                Pizza = pizza1, Ingredient = ingredient1, IngredientId = ingredient1.Id
            });
            pizza1.Ingredients.Add(new PizzaIngredient {
                Pizza = pizza1, Ingredient = ingredient2, IngredientId = ingredient2.Id
            });

            pizza2.Ingredients.Add(new PizzaIngredient {
                Pizza = pizza2, Ingredient = ingredient1, IngredientId = ingredient1.Id
            });

            unit.Pizzas.Create(pizza1);
            unit.Pizzas.Create(pizza2);

            unit.IngredientPrices.Create(ingredientPrice);
            unit.IngredientPrices.Create(ingredientPrice2);

            unit.PizzaPrices.Create(pizzaPrice);
            unit.PizzaPrices.Create(pizzaPrice2);

            unit.SaveChanges();

            var pizzaList = (List <Pizza>)unit.Pizzas.GetAll();

            Assert.AreEqual(pizzaList.Count, 2);
            Assert.AreEqual(pizzaList[0].Ingredients.Count, 2);
        }