public void PizzaIngredientsToPizzaIngredientTest()
        {
            PizzaIngredients pizzaIngredients = new PizzaIngredients
            {
                Id           = 1,
                PizzaId      = 1,
                IngredientId = 1,
                Ingredient   = new Ingredients
                {
                    Id             = 1,
                    Name           = "Name",
                    Price          = 1,
                    IngredientType = new IngredientTypes
                    {
                        Id   = 1,
                        Name = "Name",
                    }
                }
            };

            PizzaIngredient pizzaIngredient = mapper.MapPizzaIngredient(pizzaIngredients);

            Assert.Equal(pizzaIngredients.Id, pizzaIngredient.Id);
            Assert.Equal(pizzaIngredients.PizzaId, pizzaIngredient.PizzaId);
            Assert.Equal(pizzaIngredients.IngredientId, pizzaIngredient.IngredientId);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,PizzaId,IngredientId")] PizzaIngredient pizzaIngredient)
        {
            if (id != pizzaIngredient.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pizzaIngredient);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PizzaIngredientExists(pizzaIngredient.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IngredientId"] = new SelectList(_context.Ingredients, "Id", "Name", pizzaIngredient.IngredientId);
            ViewData["PizzaId"]      = new SelectList(_context.Pizzas, "Id", "Crust", pizzaIngredient.PizzaId);
            return(View(pizzaIngredient));
        }
        public void Add(PizzaIngredient PizzaIngredient)
        {
            if (PizzaIngredient is null)
            {
                //log it!

                throw new ArgumentNullException("Cannot add null Pizza Ingredient");
            }
            else
            {
                if (GetPizzaIngredientById(PizzaIngredient.Id) != null) //if given Pizza Ingredient is already in db
                {
                    throw new ArgumentOutOfRangeException("Pizza Ingredient with given id already exists.");
                }
                else
                {
                    try
                    {
                        _dbContext.PizzaIngredient.Add(PizzaIngredient); //add to local _dbContext
                        _dbContext.Entry(PizzaIngredient.Ingredient).State = EntityState.Unchanged;
                        _dbContext.Entry(PizzaIngredient.Pizza).State      = EntityState.Unchanged;
                        _dbContext.SaveChanges();  //run _dbContext.savechanges() to run the appropriate insert, adding it to db
                    }
                    catch (DbUpdateException)
                    {
                        //log it!

                        throw;
                    }
                }
            }
        }
示例#4
0
        public ReadPizzaDTO CreatePizza(CreatePizzaDTO dto)
        {
            // crear pizza
            var pizza = new Pizza();

            pizza.Id               = Guid.NewGuid();
            pizza.Name             = dto.Name;
            pizza.PizzaIngredients = new List <PizzaIngredient>();
            pizza.Comments         = new List <Comment>();
            // add pizza ingredients
            foreach (var ingredientId in dto.Ingredients)
            {
                var ingredient = _context.Ingredient.Find(ingredientId);
                // createPizzaIngredient
                var pizzaIngredient = new PizzaIngredient();
                pizzaIngredient.Pizza        = pizza;
                pizzaIngredient.Ingredient   = ingredient;
                pizzaIngredient.PizzaId      = pizza.Id;
                pizzaIngredient.IngredientId = ingredient.Id;
                //
                pizza.PizzaIngredients.Add(pizzaIngredient);
            }
            // var pizza = _cretePizza(dto);
            // _addPizzaIngredients(pizza, dto.Ingredients)
            _context.Pizza.Add(pizza);
            _context.SaveChanges();
            _context.Dispose();
            return(_createReadPizzaDTO(pizza));
        }
示例#5
0
 public Entities.PizzaIngredients MapPizzaIngredient(PizzaIngredient pizzaIngredient)
 {
     return(new Entities.PizzaIngredients
     {
         Id = pizzaIngredient.Id,
         PizzaId = pizzaIngredient.PizzaId,
         IngredientId = pizzaIngredient.IngredientId,
     });
 }
        // dont think we need this
        public async Task AddPizzaIngredientAsync(PizzaIngredient pizzaIngredient)
        {
            PizzaIngredient newPizzaIngredient = (await GetPizzaIngredientsAsync(pizzaId: pizzaIngredient.PizzaId, IngredientId: pizzaIngredient.IngredientId)).FirstOrDefault();

            if (newPizzaIngredient == null)
            {
                pizzaIngredient.Id = 0;
                await _context.AddAsync(_mapper.MapPizzaIngredient(pizzaIngredient));
            }
        }
示例#7
0
 public void AddIngredients(Pizza pizza, ICollection <Guid> ingredients)
 {
     foreach (Guid ingredientId in ingredients)
     {
         var ingredient      = _ingredientService.FindById(ingredientId);
         var pizzaIngredient = new PizzaIngredient()
         {
             Pizza        = pizza,
             PizzaId      = pizza.Id,
             Ingredient   = ingredient,
             IngredientId = ingredient.Id
         };
         pizza.PizzaIngredients.Add(pizzaIngredient);
     }
 }
        public void PizzaIngredientToPizzaIngredientsTest()
        {
            PizzaIngredient pizzaIngredient = new PizzaIngredient
            {
                Id           = 1,
                PizzaId      = 1,
                IngredientId = 1,
            };

            PizzaIngredients pizzaIngredients = mapper.MapPizzaIngredient(pizzaIngredient);

            Assert.Equal(pizzaIngredient.Id, pizzaIngredients.Id);
            Assert.Equal(pizzaIngredient.PizzaId, pizzaIngredients.PizzaId);
            Assert.Equal(pizzaIngredient.IngredientId, pizzaIngredients.IngredientId);
        }
 public void IngredientId_property_Test(int input, bool type)
 {
     if (!type)
     {
         Assert.Throws <ArgumentException>(() => new PizzaIngredient {
             IngredientId = input
         });
     }
     else
     {
         PizzaIngredient test = new PizzaIngredient();
         test.IngredientId = input;
         Assert.Equal(input, test.IngredientId);
     }
 }
        private void AddIngredients(object sender, RoutedEventArgs e)
        {
            btnCalc.IsEnabled = true;
            PizzaIngredient ingredient = (sender as Button).DataContext as PizzaIngredient;

            mwvm.AddIngredient(ingredient);
            try
            {
                datagrid.Items.Refresh();
                datagrid2.Items.Refresh();
            }
            catch (Exception)
            {
                MessageBox.Show("Error");
            }
        }
示例#11
0
    private List <PizzaIngredient> PickTopping(List <PizzaIngredient> ingredientList)
    {
        if (ingredientList.Count == 0)
        {
            dont = true;
            return(ingredientList);
        }

        int rand = UnityEngine.Random.Range(0, ingredientList.Count);

        pickedTopping = ingredientList[rand];

        ingredientList.Remove(pickedTopping);

        return(ingredientList);
    }
示例#12
0
 public static void SetPizzaIngredientByIds(dom.Pizza p, int lastID)
 {
     foreach (var top in p.Toppings)
     {
         var _db     = new PizzaStoreDbContext();
         var topping = _db.Ingredient.Where(i => (i.Name).ToLower() == top.ToLower()).FirstOrDefault();
         if (topping != null)
         {
             var pipair = new PizzaIngredient()
             {
                 PizzaId = lastID, IngredientId = topping.IngredientId
             };
             _db.PizzaIngredient.Add(pipair);
             _db.SaveChanges();
         }
     }
 }
示例#13
0
    private void CreateNewUI(PizzaIngredient addedIngredient)
    {
        // instantiate UI
        var newIngredient = Instantiate(ingredientUI, ingredientUITransform.position, ingredientUITransform.rotation, ingredientUITransform);

        // add new UI to list of UI for updating
        ingredientUIList.Add(newIngredient);
        uniqueIngredientCounts.Add(1);

        // update text with info
        var ingredientTexts = newIngredient.GetComponentsInChildren <TMP_Text>();

        ingredientTexts[0].text = addedIngredient.GetIngredientName();
        ingredientTexts[1].text = "x" + uniqueIngredientCounts[ingredientUIList.IndexOf(newIngredient)];

        newIngredient.GetComponentInChildren <Image>().sprite = addedIngredient.GetIngredientIcon();
    }
示例#14
0
    private void UpdateCanvas(PizzaIngredient addedIngredient)
    {
        // checks if added ingredient already has UI
        foreach (var uiElement in ingredientUIList)
        {
            var ingredientTexts = uiElement.GetComponentsInChildren <TMP_Text>();
            if (addedIngredient.GetIngredientName() == ingredientTexts[0].text)
            {
                ++uniqueIngredientCounts[ingredientUIList.IndexOf(uiElement)];
                ingredientTexts[1].text = "x" + uniqueIngredientCounts[ingredientUIList.IndexOf(uiElement)];
                return;
            }
        }

        // if there is no UI create one
        CreateNewUI(addedIngredient);
    }
示例#15
0
    public override void TurnOnUpgrade()
    {
        PizzaIngredient ingredient = GetComponent <PizzaIngredientSpawner>().pizzaIngredientToSpawn.GetComponent <IngredientHitEffect>().spawnObjectOnCollision.GetComponent <PizzaIngredient>();

        switch (ingredient.tier)
        {
        case 1:
            FindObjectOfType <OrderCreation>().tierOneIngredients.Add(ingredient);
            break;

        case 2:
            FindObjectOfType <OrderCreation>().tierTwoIngredients.Add(ingredient);
            break;

        case 3:
            FindObjectOfType <OrderCreation>().tierThreeIngredients.Add(ingredient);
            break;

        default:
            Debug.LogWarning($"Ingredient's tier value, {ingredient.tier} is not supported.");
            break;
        }
    }
示例#16
0
        public ActionResult Create(PizzaViewModel collection)
        {
            try
            {
                var pizza = new Pizza(collection.Name, collection.Price)
                {
                    Id = collection.Id,
                };


                Repo.Add(pizza);

                for (var i = 0; i < collection.Ingredients.Count; i++)
                {
                    if (collection.Ingredients[i].Checked)
                    {
                        var pizzaingredient = new PizzaIngredient(collection.IngredientsAmount[i].Quantity)
                        {
                            Ingredient = new Ingredient(collection.Ingredients[i].Name)
                            {
                                Id = collection.Ingredients[i].Id
                            },
                            Pizza = pizza
                        };

                        Repo.Add(pizzaingredient);
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                _logger.LogTrace(e, "Create pizza error.");
                return(View(collection));
            }
        }
示例#17
0
 public Task AddPizzaIngredientAsync(PizzaIngredient pizzaIngredient)
 {
     throw new NotImplementedException();
 }
 public PizzaIngredients MapPizzaIngredient(PizzaIngredient pizzaIngredient)
 {
     return(new PizzaIngredients());
 }
示例#19
0
        public PizzaDto SavePizza(PizzaDto newPizza)
        {
            Pizza pizza = _pizzaRepository.GetPizza(newPizza.Id) ?? new Pizza {
            };

            pizza.Name        = newPizza.Name;
            pizza.Description = newPizza.Description;
            pizza.ImgPath     = newPizza.ImgPath;
            if (pizza.PizzaIngredients != null)
            {
                for (int i = 0; i < pizza.PizzaIngredients.Count; i++)
                {
                    IngredientDto ingredientData = newPizza.Ingredients.Find(value => value.Id == pizza.PizzaIngredients.ElementAt(i).Id);
                    if (ingredientData == null)
                    {
                        _pizzaIngredientRepository.Delete(pizza.PizzaIngredients.ElementAt(i).Id);
                    }
                    else
                    {
                        PizzaIngredient pizzaIngredient = _pizzaIngredientRepository.GetItem(pizza.PizzaIngredients.ElementAt(i).Id);
                        pizzaIngredient.IngredientId = ingredientData.Id;
                        pizzaIngredient.Ingredient   = null;
                        _pizzaIngredientRepository.Save(pizzaIngredient);
                    }
                }
            }
            if (pizza.Prices != null)
            {
                for (int i = 0; i < pizza.Prices.Count; i++)
                {
                    PriceDto priceData = newPizza.Prices.Find(value => value.Id == pizza.Prices.ElementAt(i).Id);
                    if (priceData == null)
                    {
                        _priceRepository.Delete(pizza.Prices.ElementAt(i).Id);
                    }
                    else
                    {
                        Price price = _priceRepository.GetItem(pizza.Prices.ElementAt(i).Id);
                        price.DoughThickness = priceData.DoughThickness;
                        price.Size           = priceData.Size;
                        price.Weight         = priceData.Weight;
                        price.Cost           = priceData.Cost;
                        _priceRepository.Save(price);
                    }
                }
            }
            pizza = _pizzaRepository.Save(pizza);
            foreach (IngredientDto ingredient in newPizza.Ingredients)
            {
                PizzaIngredient pizzaIngredient = null;
                if (pizza.PizzaIngredients != null)
                {
                    pizzaIngredient = pizza.PizzaIngredients.Where(value => value.IngredientId == ingredient.Id).FirstOrDefault();
                }
                if (pizzaIngredient == null)
                {
                    PizzaIngredient newPizzaIngredient = new PizzaIngredient
                    {
                        IngredientId = ingredient.Id,
                        PizzaId      = pizza.Id
                    };
                    _pizzaIngredientRepository.Save(newPizzaIngredient);
                }
            }
            foreach (PriceDto price in newPizza.Prices)
            {
                Price oldPrice = _priceRepository.GetItem(price.Id);
                if (oldPrice == null)
                {
                    Price newPrice = new Price
                    {
                        Id             = 0,
                        DoughThickness = price.DoughThickness,
                        Size           = price.Size,
                        Cost           = price.Cost,
                        Weight         = price.Weight,
                        PizzaId        = pizza.Id,
                    };
                    _priceRepository.Save(newPrice);
                }
            }
            pizza = _pizzaRepository.GetPizza(pizza.Id);
            return(ConvertPizza(pizza));
        }
示例#20
0
 public void AddPizzaIngredient(PizzaIngredient newIngredient)
 {
     ingredientsOnPizza.Add(newIngredient);
     UpdateCanvas(newIngredient);
 }
 internal void AddIngredient(PizzaIngredient ingredient)
 {
     Pizza.TotalPrice += ingredient.Price;
     AddedIngredients.Add(ingredient);
 }