private void UpdateRecipiesSource()
    {
        if (Recipies != null)
        {
            Recipies.Clear();
        }
        else
        {
            Recipies = new ObservableCollection <RecipeListViewDto>();
        }

        List <RecipeListViewDto> newEntries;

        if (!string.IsNullOrWhiteSpace(FilterText))
        {
            Expression <Func <Recipe, bool> > filterExpression = recipeFiltrator.Instance.Value.GetExpression(FilterText);
            newEntries = recipeService.GetMapped <RecipeListViewDto>(clientsidePredicate: filterExpression.Compile());
        }
        else
        {
            newEntries = recipeService.GetProjected <RecipeListViewDto>();
        }

        Recipies.AddRange(newEntries);

        if (RecipiesSource.View is ListCollectionView listCollectionView)
        {
            RecipiesNotFound = listCollectionView.IsEmpty;
        }
    }
        public void controlla_Recipies_EditTest()
        {
            // Arrange
            RecipiesController controller = new RecipiesController();

            //Act
            //id della recipies che ha come descrizione "recipiesFotTestCreate"
            var idrecipiesBeforeEdit = from s in db.Recipies
                                       .Where(x => x.Description.Equals("recipiesFotTestCreate"))
                                       select s.ID;

            //creo recipies modificato Rate da 0 a 3
            Recipies recipiesFotTestEdit = new Recipies()
            {
                ID          = idrecipiesBeforeEdit.FirstOrDefault(),
                Description = "recipiesFotTestCreate",
                UserId      = "1fe90eaa-4178-4b7f-8cb1-d38daaeadf95",
                Rate        = 3
            };


            //chiamo il controller per modificare
            ActionResult result = controller.Edit(recipiesFotTestEdit);

            //rileggo rate dopo edit
            var quantityAfterEdit = from s in db.Recipies
                                    .Where(x => x.Description.Equals("recipiesFotTestCreate"))
                                    select s.Rate;

            // Assert
            //mi che Rate=3
            Assert.AreEqual(3, quantityAfterEdit.FirstOrDefault());
        }
Beispiel #3
0
        static RecipeFactory()
        {
            Recipies granolaBarRec = new Recipies(1, "Granola Bar");

            granolaBarRec.AddIngridient(9007, 1);
            granolaBarRec.AddIngridient(9008, 1);
            granolaBarRec.AddIngridient(9009, 1);
            granolaBarRec.AddOutputItem(2001, 1);

            recipies.Add(granolaBarRec);
        }
Beispiel #4
0
 public ActionResult Edit([Bind(Include = "ID,Description,Rate,UserId")] Recipies recipies)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipies).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", recipies.UserId);
     return(View(recipies));
 }
Beispiel #5
0
        // GET: Recipies/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recipies recipies = db.Recipies.Find(id);

            if (recipies == null)
            {
                return(HttpNotFound());
            }
            return(View(recipies));
        }
Beispiel #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            Recipies recipies = db.Recipies.Find(id);
            //cancella tutti gli ingredienti correlati
            var items = db.IngredientRecipe.Where(item => item.IdRecipes == id);

            foreach (var item in items)
            {
                db.IngredientRecipe.Remove(item);
            }

            db.Recipies.Remove(recipies);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #7
0
 private void AddOutput(Recipies recipie)
 {
     if (recipie.output0 != null)
     {
         inventoryOutput.AddItem(recipie.output0.createItem(), recipie.o0amount);
     }
     if (recipie.output1 != null)
     {
         inventoryOutput.AddItem(recipie.output1.createItem(), recipie.o1amount);
     }
     if (recipie.output2 != null)
     {
         inventoryOutput.AddItem(recipie.output2.createItem(), recipie.o2amount);
     }
     if (recipie.output3 != null)
     {
         inventoryOutput.AddItem(recipie.output3.createItem(), recipie.o3amount);
     }
     animator2.SetBool("isWorking", false);
 }
Beispiel #8
0
        // GET: Recipies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recipies recipies = db.Recipies.Find(id);

            if (recipies == null)
            {
                return(HttpNotFound());
            }
            var userID = User.Identity.GetUserId();

            if (User.Identity.GetUserName().Equals(ConfigurationManager.AppSettings["SuperUser"]))
            {
                ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", recipies.UserId);
            }
            else
            {
                ViewBag.UserId = new SelectList(db.AspNetUsers.Where(x => x.Id == userID), "Id", "Email", recipies.UserId);
            }
            return(View(recipies));
        }
        public void controlla_Recipies_CreateTest()
        {
            // Arrange
            RecipiesController controller = new RecipiesController();

            //Act
            //rilancio la creazione della recpies che ha come descrizione "recipiesFotTestCreate" e utente SuperUser

            Recipies repciesFotTestCreate = new Recipies()
            {
                Description = "recipiesFotTestCreate",
                UserId      = "1fe90eaa-4178-4b7f-8cb1-d38daaeadf95"
            };

            ActionResult result = controller.Create(repciesFotTestCreate);

            var idrepciesFotTestCreate = from s in db.Recipies
                                         .Where(x => x.Description.Equals("recipiesFotTestCreate"))
                                         select s.ID;

            // Assert
            //mi aspetto, che la selzione in base alla descrizione mi restituisca un ID
            Assert.IsNotNull(idrepciesFotTestCreate.FirstOrDefault());
        }
Beispiel #10
0
    private bool Output(Recipies recipie)
    {
        int freeSlots = 4;
        //int outputSlots = 0;

        List <ItemObject> listOutput = new List <ItemObject>();

        if (recipie.output0 != null)
        {
            listOutput.Add(recipie.output0);
        }
        if (recipie.output1 != null)
        {
            listOutput.Add(recipie.output1);
        }
        if (recipie.output2 != null)
        {
            listOutput.Add(recipie.output2);
        }
        if (recipie.output3 != null)
        {
            listOutput.Add(recipie.output3);
        }

        List <ItemObject> listInv2 = new List <ItemObject>();
        List <ItemObject> listInv  = new List <ItemObject>();

        for (int i = 0; i < 4; i++)
        {
            if (inventoryOutput.GetSlots[i].item.Id != -1)
            {
                freeSlots--;
            }
            listInv.Add(inventoryOutput.GetSlots[i].ItemObject);
            listInv2.Add(inventory.GetSlots[i].ItemObject);
        }

        if (!listInv2.Contains(recipie.input0))
        {
            return(false);
        }
        if (!listInv2.Contains(recipie.input1))
        {
            return(false);
        }
        if (!listInv2.Contains(recipie.flaskSlot))
        {
            return(false);
        }



        //Debug.Log(freeSlots);

        foreach (var i in listOutput)
        {
            if (listInv.Contains(i))
            {
                //Debug.Log("id: " + i.Id);
                freeSlots++;
            }
        }



        //Debug.Log("free slots= " +freeSlots);

        if (listOutput.Count <= freeSlots)
        {
            if (recipie.input0 != null)
            {
                inventory.ConsumeFromInventory(recipie.input0.createItem(), 1);
                inventory.GetSlots[0].UpdateSlot();
            }
            if (recipie.input1 != null)
            {
                inventory.ConsumeFromInventory(recipie.input1.createItem(), 1);
                inventory.GetSlots[1].UpdateSlot();
            }
            if (recipie.flaskSlot != null)
            {
                inventory.ConsumeFromInventory(recipie.flaskSlot.createItem(), 1);
                inventory.GetSlots[2].UpdateSlot();
            }
            AddOutput(recipie);
            return(true);
        }
        return(false);
    }
Beispiel #11
0
 public void CraftCall(Recipies recpie)
 {
     GameObject.FindGameObjectWithTag("Inventory").GetComponent <CraftingV2>().Craft(recpie);
 }
    public void Craft(Recipies obj)
    {
        bool[] collectedReources;
        collectedReources = new bool[obj.requiredResources.Length];

        if (Bag.Count == 0)
        {
            Debug.Log("Your Inventory is empty");
        }

        else
        {
            for (int i = 0; i < Bag.Count; i++)
            {
                for (int j = 0; j < obj.requiredResources.Length; j++)
                {
                    if (Bag[i].item.typeOfResource == obj.requiredResources[j].requiredResource.typeOfResource)
                    {
                        if (Bag[i].amount >= obj.requiredResources[j].requiredAmount)
                        {
                            collectedReources[j] = true;
                        }
                        else
                        {
                            collectedReources[j] = false;
                        }
                    }
                }
            }


            for (int i = 0; i < Bag.Count; i++)
            {
                for (int j = 0; j < obj.requiredResources.Length; j++)
                {
                    if (Bag[i].item.typeOfResource == obj.requiredResources[j].requiredResource.typeOfResource)
                    {
                        if (Bag[i].amount >= obj.requiredResources[j].requiredAmount)
                        {
                            for (int k = 0; k < collectedReources.Length; k++)
                            {
                                if (collectedReources[k] == false)
                                {
                                    break;
                                }
                                if (k == collectedReources.Length - 1 && collectedReources[k] == true)
                                {
                                    Bag[i].amount -= obj.requiredResources[j].requiredAmount;
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < collectedReources.Length; i++)
            {
                if (collectedReources[i] == false)
                {
                    break;
                }
                if (i == collectedReources.Length - 1 && collectedReources[i] == true)
                {
                    craftedObj = Instantiate(obj.craftable);
                }
            }

            if (craftedObj == null)
            {
                Debug.Log("Crafting : " + obj.craftable.name + " : failed.");
            }
        }

        player.transform.GetComponent <PlayerStats>().InventoryStatus = false;
    }