protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request.Cookies["RecipeID"] != null)
         {
             string      RecipeID = Server.HtmlEncode(Request.Cookies["RecipeID"].Value);
             RecipeModel item     = new RecipeModel();
             recipe      Recipes  = new recipe();
             Recipes = item.GetRecipeByRecipeID(Convert.ToInt32(RecipeID));
             //lblData.Text += string.Format("Recipe Name:{0}</br>Description: {1}</br>Submitted By: {2}</br>Category: {3}</br>Cooking time(mins): {4}</br>Number of serving: {5} </br>",
             //    Recipes.Name, Recipes.Description, Recipes.SubmitedBy,Recipes.Category, Recipes.CookingTime, Recipes.Serving);
             txtName.Text                = Recipes.Name;
             txtDescription.Text         = Recipes.Description;
             lblSubmitedBy.Text          = Recipes.SubmittedBy;
             DropDownList1.SelectedValue = Recipes.Category;
             txtTime.Text                = Recipes.PrepTime.ToString();
             txtNumOfServing.Text        = Recipes.Servings.ToString();
             IngredientModel         item2   = new IngredientModel();
             RecipeIngredientModel   item1   = new RecipeIngredientModel();
             List <recipeingredient> combine = new List <recipeingredient>();
             combine = item1.getIngredientDetailByRecipeID(Convert.ToInt32(RecipeID));
             int i = 1;
             grd.DataSource = GetTableWithInitialData(item1, item2, RecipeID); // get first initial data
             grd.DataBind();
             //foreach(var x in combine)
             //{
             //    lblData1.Text += string.Format("{3}. {0} {1} {2}</br>", item2.getIngredientByID(x.Ingredient), x.quantity, x.UnitOfMeasure, i);
             //    i++;
             //}
         }
     }
 }
        public ActionResult <RecipeIngredientModel> AddIngredient(RecipeIngredientModel newIngredient)
        {
            var ingredient = this.mapper.Map <RecipeIngredient>(newIngredient);

            this.ingredientsRepository.AddIngredient(ingredient);

            return(Created("", this.mapper.Map <RecipeIngredientModel>(ingredient)));
        }
    /// <summary>
    ///  Ilir Method
    /// </summary>
    ///
    public DataTable GetTableWithInitialData(RecipeIngredientModel item1, IngredientModel item2, string RecipeID) // this might be your sp for select
    {
        DataTable table = new DataTable();

        table.Columns.Add("Ingredient", typeof(string));
        table.Columns.Add("Unit", typeof(string));
        table.Columns.Add("Quantity", typeof(string));
        List <recipeingredient> combine = new List <recipeingredient>();

        combine = item1.getIngredientDetailByRecipeID(Convert.ToInt32(RecipeID));
        foreach (var x in combine)
        {
            // lblData1.Text += string.Format("<strong>Name: {0}</strong> </br> Quantity: {1} </br> Unit of Measure: {2}</br></br>", item2.getIngredientByID(x.Ingredient), x.Quantity, x.UM);
            table.Rows.Add(item2.getIngredientByID(x.Ingredient), x.UM, x.Quantity.ToString());
        }
        //table.Rows.Add("Carrot", "KG", "1.5");

        return(table);
    }
Example #4
0
        /// <summary>Create a recipe item model.</summary>
        /// <param name="id">The item id.</param>
        /// <param name="ingredient">The recipe ingredient model for the item.</param>
        /// <returns>The equivalent item entry model, or <c>null</c> for a category with no matching items.</returns>
        private RecipeItemEntry TryCreateItemEntry(int id, RecipeIngredientModel ingredient)
        {
            // from category
            if (id < 0)
            {
                Item input = this.GameHelper.GetObjectsByCategory(id).FirstOrDefault();
                if (input == null)
                {
                    return(null);
                }

                return(this.CreateItemEntry(
                           name: input.getCategoryName(),
                           minCount: ingredient.Count,
                           maxCount: ingredient.Count
                           ));
            }

            // from item
            {
                Item input = this.GameHelper.GetObjectBySpriteIndex(id);

                if (input is SObject obj)
                {
                    if (ingredient.PreservedParentSheetIndex != null)
                    {
                        obj.preservedParentSheetIndex.Value = ingredient.PreservedParentSheetIndex.Value;
                    }
                    if (ingredient.PreserveType != null)
                    {
                        obj.preserve.Value = ingredient.PreserveType.Value;
                    }
                }

                return(this.CreateItemEntry(
                           name: input?.DisplayName,
                           item: input,
                           minCount: ingredient.Count,
                           maxCount: ingredient.Count
                           ));
            }
        }
        /*********
        ** Private methods
        *********/
        /// <summary>Get the recipe entries.</summary>
        /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param>
        /// <param name="inputItem">The input ingredient item.</param>
        /// <param name="recipes">The recipe to list.</param>
        private IEnumerable <Entry> GetRecipeEntries(GameHelper gameHelper, Item inputItem, IEnumerable <RecipeModel> recipes)
        {
            foreach (RecipeModel recipe in recipes)
            {
                Item                  output       = recipe.CreateItem(inputItem);
                SpriteInfo            customSprite = gameHelper.GetSprite(output);
                RecipeIngredientModel ingredient   =
                    recipe.Ingredients.FirstOrDefault(p => p.ID == inputItem.ParentSheetIndex && p.Matches(inputItem))
                    ?? recipe.Ingredients.FirstOrDefault(p => p.ID == inputItem.Category && p.Matches(inputItem));

                yield return(new Entry
                {
                    Name = output.DisplayName,
                    Type = recipe.DisplayType,
                    IsKnown = !recipe.MustBeLearned || recipe.KnowsRecipe(Game1.player),
                    NumberRequired = ingredient?.Count ?? 1,
                    Sprite = customSprite
                });
            }
        }
Example #6
0
        /// <summary>Get the recipes for which an item is needed.</summary>
        /// <param name="item">The item.</param>
        public IEnumerable <RecipeModel> GetRecipesForIngredient(Item item)
        {
            // ignore invalid ingredients
            if (item.GetItemType() != ItemType.Object)
            {
                return(Enumerable.Empty <RecipeModel>());
            }

            // from cached recipes
            var recipes = new List <RecipeModel>();

            foreach (RecipeModel recipe in this.GetRecipes())
            {
                if (!recipe.Ingredients.Any(p => p.Matches(item)))
                {
                    continue;
                }
                if (recipe.ExceptIngredients.Any(p => p.Matches(item)))
                {
                    continue;
                }

                recipes.Add(recipe);
            }

            // resolve conflicts from mods like Producer Framework Mod: if multiple recipes take the
            // same item as input, ID takes precedence over category. This only occurs with mod recipes,
            // since there are no such conflicts in the vanilla recipes.
            recipes.RemoveAll(recipe =>
            {
                RecipeIngredientModel ingredient = recipe.Ingredients.FirstOrDefault();
                return
                (ingredient?.ID < 0 &&
                 recipes.Any(other => other.Ingredients.FirstOrDefault()?.ID == item.ParentSheetIndex && other.DisplayType == recipe.DisplayType));
            });

            // from tailor recipes
            recipes.AddRange(this.GetTailorRecipes(item));

            return(recipes);
        }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["RecipeID"] != null)
        {
            int RecipeID = Convert.ToInt32(Server.HtmlEncode(Request.Cookies["RecipeID"].Value));
            using (COMP229S17S2Entities dbConnection = new COMP229S17S2Entities())
            {
                /*
                 * recipe deletedRecipe = (from recipeRecords in dbConnection.recipes
                 *                      where recipeRecords.ID == RecipeID
                 *                      select recipeRecords).FirstOrDefault();
                 *
                 * dbConnection.recipes.Remove(deletedRecipe);
                 * dbConnection.SaveChanges();
                 * Response.Redirect("~/pages/Recipes.aspx");
                 */

                RecipeIngredientModel a = new RecipeIngredientModel();
                List <int>            b = a.getReInIDbyRecipe(RecipeID);
                for (int i = 0; i < b.Count; i++)
                {
                    int c = b[i];
                    recipeingredient combine = (from mix in dbConnection.recipeingredients
                                                where mix.ID == c
                                                select mix).FirstOrDefault();
                    dbConnection.recipeingredients.Remove(combine);
                    dbConnection.SaveChanges();
                }
                recipe deletedRecipe = (from recipeRecords in dbConnection.recipes
                                        where recipeRecords.ID == RecipeID
                                        select recipeRecords).FirstOrDefault();

                dbConnection.recipes.Remove(deletedRecipe);
                dbConnection.SaveChanges();
                Response.Redirect("Recipes.aspx");
            }
        }
    }
Example #8
0
        /// <summary>Get the recipes for which an item is needed.</summary>
        /// <param name="item">The item.</param>
        public IEnumerable <RecipeModel> GetRecipesForIngredient(Item item)
        {
            // ignore invalid ingredients
            if (item is Furniture || item is Ring || item is Boots || item is MeleeWeapon || item is Hat || (item as SObject)?.bigCraftable.Value == true)
            {
                yield break;
            }

            // from cached recipes
            foreach (var recipe in this.GetRecipes())
            {
                if (!recipe.Ingredients.Any(p => p.Matches(item)))
                {
                    continue;
                }
                if (recipe.ExceptIngredients.Any(p => p.Matches(item)))
                {
                    continue;
                }

                yield return(recipe);
            }

            // from tailor recipes
            List <TailorItemRecipe> tailorRecipes = Game1.temporaryContent.Load <List <TailorItemRecipe> >("Data\\TailoringRecipes");

            foreach (TailorItemRecipe recipe in tailorRecipes)
            {
                if (recipe.FirstItemTags?.All(item.HasContextTag) == false && recipe.SecondItemTags?.All(item.HasContextTag) == false)
                {
                    continue; // needs all tags for one of the recipe slots
                }
                RecipeIngredientModel ingredient = new RecipeIngredientModel(item.ParentSheetIndex, 1);
                Item Output(Item input) => new Clothing(recipe.CraftedItemID);

                yield return(new RecipeModel(null, RecipeType.TailorInput, "Tailoring", new[] { ingredient }, Output, mustBeLearned: false, outputItemIndex: recipe.CraftedItemID, isForMachine: _ => false));
            }
        }
Example #9
0
        public async Task <IHttpActionResult> PutRecipeIngredient(int id, RecipeIngredientModel recipeIngredientModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != recipeIngredientModel.Id)
            {
                return(BadRequest());
            }

            var recipeIngredient = _recipeIngredientService.GetRecipeIngredientById(id);

            ObjectFactory.Parse(recipeIngredientModel, recipeIngredient);

            _recipeIngredientService.Update(recipeIngredient);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeIngredientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #10
0
    List <recipe> GetRecipesSubmittedBy_Category_Ingredient(string submittedby, string category, string ingredient)
    {
        IngredientModel       inModel   = new IngredientModel();
        RecipeIngredientModel reInModel = new RecipeIngredientModel();
        RecipeModel           reModel   = new RecipeModel();

        using (COMP229S17S2Entities dbConnection = new COMP229S17S2Entities())
        {
            if (submittedby == "All")
            {
                if (category == "All")
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                result.Add(a[0]);
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
                else
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    where x.Category == category
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                foreach (recipe x in a)
                                {
                                    if (x.Category == category)
                                    {
                                        result.Add(a[0]);
                                    }
                                }
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
            }
            else
            {
                if (category == "All")
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    where x.SubmittedBy == submittedby
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                foreach (recipe x in a)
                                {
                                    if (x.SubmittedBy == submittedby)
                                    {
                                        result.Add(a[0]);
                                    }
                                }
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
                else
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    where x.Category == category && x.SubmittedBy == submittedby
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                foreach (recipe x in a)
                                {
                                    if (x.SubmittedBy == submittedby && x.Category == category)
                                    {
                                        result.Add(a[0]);
                                    }
                                }
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
            }
        }
    }
Example #11
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            recipe recipeItem = new recipe();
            recipeItem.Name        = txtName.Text;
            recipeItem.SubmittedBy = txtSubmit.Text;
            recipeItem.PrepTime    = Convert.ToInt32(txtTime.Text);
            recipeItem.Servings    = Convert.ToInt32(txtServings.Text);
            recipeItem.Description = txtDescription.Text;
            recipeItem.Category    = txtCategory.Text;


            RecipeModel recipeModel = new RecipeModel();
            recipeModel.InsertRecipe(recipeItem);



            int ingamount = Convert.ToInt32(numberIngredients.SelectedValue);

            IngredientModel       ingModel = new IngredientModel();
            ingredient            ingItem;
            RecipeIngredientModel recIngModel = new RecipeIngredientModel();
            recipeingredient      recIngItem;

            string[] ingredName = { ingredientName1.Text, ingredientName2.Text, ingredientName3.Text,  ingredientName4.Text,  ingredientName5.Text,  ingredientName6.Text,  ingredientName7.Text,
                                    ingredientName8.Text, ingredientName9.Text, ingredientName10.Text, ingredientName11.Text, ingredientName12.Text, ingredientName13.Text, ingredientName14.Text, ingredientName15.Text };

            string[] unitType = { units1.Text,  units2.Text,  units3.Text, units4.Text, units5.Text, units6.Text, units7.Text, units8.Text, units9.Text, units10.Text, units11.Text, units12.Text,
                                  units13.Text, units14.Text, units15.Text };

            string[] ingQuant = { ingredientQuantity1.Text,  ingredientQuantity2.Text, ingredientQuantity3.Text, ingredientQuantity4.Text,  ingredientQuantity5.Text,  ingredientQuantity6.Text,
                                  ingredientQuantity7.Text,  ingredientQuantity8.Text, ingredientQuantity9.Text, ingredientQuantity10.Text, ingredientQuantity11.Text, ingredientQuantity12.Text,ingredientQuantity13.Text,
                                  ingredientQuantity14.Text, ingredientQuantity15.Text };

            for (int i = 0; i < ingamount; i++)
            {
                ingItem      = new ingredient();
                recIngItem   = new recipeingredient();
                ingItem.Name = ingredName[i];
                ingModel.InsertIngredient(ingItem);
                recIngItem.Recipe     = recipeModel.GetRecipeIDByName(txtName.Text);
                testLabel.Text        = Convert.ToString(recIngItem.Recipe);
                recIngItem.Ingredient = ingModel.getIngredientIDByName(ingredName[i]);
                testLabel.Text       += Convert.ToString(recIngItem.Ingredient) + " ";
                recIngItem.UM         = unitType[i];
                recIngItem.Quantity   = Convert.ToInt32(ingQuant[i]);
                testLabel.Text       += recIngItem.UM + " ";
                testLabel.Text       += recIngItem.ToString();
                recIngModel.InsertRecipeIngredient(recIngItem);
            }

            if (flImage.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(flImage.FileName);
                    flImage.SaveAs(Server.MapPath("~/") + filename);
                    StatusLabel.Text = "Upload status: File uploaded!";
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int RecipeID = Convert.ToInt32(Server.HtmlEncode(Request.Cookies["RecipeID"].Value));

        if (txtCategory.Visible == false)
        {
            string query = "UPDATE Recipe SET Name='" + txtName.Text + "',Category='" + DropDownList1.SelectedValue.ToString() +
                           "',Description='" + txtDescription.Text + "',PrepTime=" + Convert.ToInt32(txtTime.Text) + ",Servings = " + Convert.ToInt32(this.txtNumOfServing.Text) + " WHERE ID =" + RecipeID + ";";

            using (SqlConnection db = new SqlConnection("Data Source=DESKTOP-FOJ2HKK;Initial Catalog=COMP229S17S2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
            {
                SqlCommand command = new SqlCommand(query, db);
                db.Open();
                SqlDataReader reader = command.ExecuteReader();
            }
        }
        else
        {
            string query = "UPDATE Recipe SET Name='" + txtName.Text + "',Category='" + txtCategory.Text +
                           "',Description='" + txtDescription.Text + "',PrepTime=" + Convert.ToInt32(txtTime.Text) + ",Servings = " + Convert.ToInt32(this.txtNumOfServing.Text) + " WHERE ID =" + RecipeID + ";";

            using (SqlConnection db = new SqlConnection("Data Source=DESKTOP-FOJ2HKK;Initial Catalog=COMP229S17S2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
            {
                SqlCommand command = new SqlCommand(query, db);
                db.Open();
                SqlDataReader reader = command.ExecuteReader();
            }
        }
        using (COMP229S17S2Entities db = new COMP229S17S2Entities())
        {
            List <ListOfIngredients> ingredientList = new List <ListOfIngredients>();
            foreach (GridViewRow row in grd.Rows)
            {
                TextBox ingNameTB = (TextBox)row.FindControl("txtIngredient");
                string  ingName   = ingNameTB.Text;


                TextBox unitTB  = (TextBox)row.FindControl("txtUnit");
                string  ingUnit = unitTB.Text;

                TextBox quantityTB  = (TextBox)row.FindControl("txtQuantity");
                int     ingQuantity = Convert.ToInt32(quantityTB.Text);

                ingredientList.Add(new ListOfIngredients(ingName, ingQuantity, ingUnit));
            }
            db.SaveChanges();

            foreach (ListOfIngredients item in ingredientList)
            {
                recipeingredient      newRepIng     = new recipeingredient();
                IngredientModel       ingModel      = new IngredientModel();
                RecipeIngredientModel ReInModel     = new RecipeIngredientModel();
                RecipeModel           recipeModel   = new RecipeModel();
                ingredient            newIngredient = new ingredient();
                if (ReInModel.CheckIngredient(RecipeID, ingModel.getIngredientIDByName(item.Name)) < 0)
                {
                    if (ingModel.getIngredientIDByName(item.Name) < 0)
                    {
                        newIngredient.Name = item.Name;
                        ingModel.InsertIngredient(newIngredient);
                    }
                    newRepIng.Ingredient = ingModel.getIngredientIDByName(item.Name);
                    newRepIng.Recipe     = RecipeID;
                    newRepIng.Quantity   = item.Quantity;
                    newRepIng.UM         = item.Unit;

                    ReInModel.InsertRecipeIngredient(newRepIng);
                }
                else
                {
                    string query1 = "UPDATE recipeingredients SET UM='" + item.Unit + "',Quantity="
                                    + item.Quantity + "WHERE Recipe = " + RecipeID + "AND Ingredient = "
                                    + ingModel.getIngredientIDByName(item.Name) + ";";
                    using (SqlConnection db1 = new SqlConnection("Data Source=DESKTOP-FOJ2HKK;Initial Catalog=COMP229S17S2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
                    {
                        SqlCommand command = new SqlCommand(query1, db1);
                        db1.Open();
                        SqlDataReader reader = command.ExecuteReader();
                    }
                }
            }

            List <recipeingredient> freshest = (from recipeIngItems in db.recipeingredients
                                                where recipeIngItems.Recipe == RecipeID
                                                select recipeIngItems).ToList();
            List <int> recipeIngIdsToDelete = new List <int>();

            try
            {
                for (int i = 0; i < ingredientList.Count; i++)
                {
                    freshest[i].Quantity = ingredientList[i].Quantity;
                    freshest[i].UM       = ingredientList[i].Unit;

                    if (freshest[i].Quantity == 0)
                    {
                        //recipeIngIdsToDelete.Add(freshest[i].id);
                        db.recipeingredients.Remove(freshest[i]);
                    }
                }
            }
            catch (Exception ed)
            {
            }
            db.SaveChanges();
            //Redirect bact to the updated recipes page
            Response.Redirect("Recipes.aspx");
        }

        Label1.Text = TextBox1.Text;
    }