Esempio n. 1
0
        public RecipeDetailsView(RecipeClass recipe)
        {
            this.recipe = recipe;
            InitializeComponent();
            FlowListView.Init();
            BindingContext = RecipeViewModel._viewModelInstance;
            var vm = BindingContext as RecipeViewModel;

            vm.getRecipeDetails(recipe);
        }
        private List <RecipeClass> buildRecipeBook(RecipeClass newRecipe)
        {
            // read local storage to get the list of existing recipes, and store into a list in memory
            List <RecipeClass> recipeBook = new List <RecipeClass>();

            var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            List <RecipeClass> recipeBookStore = (List <RecipeClass>)roamingSettings.Values["recipeBook"];

            if (recipeBookStore != null)
            {
                recipeBook = recipeBookStore;
            }

            if (NotesSource_Pivot.SelectedIndex == 0)
            {
                // get the new notes from the UI and store into an object in memory
                List <string> noteList = new List <string>();
                foreach (TextBox t in IndividualNote_Stackpanel_Phone.Children)
                {
                    string note = t.Text;
                    noteList.Add(note);
                }
                newRecipe.Notes = noteList;
            }

            if (NotesSource_Pivot.SelectedIndex == 1)
            {
                // get the new source from the UI and store into an object in memory
                SourceClass source = new SourceClass();

                if (Source_ComboBox.SelectedIndex == 0)
                {
                    source.Type    = "Web";
                    source.Website = WebTitle_Phone.Text;
                    source.Address = WebAddress_Phone.Text;
                }
                if (Source_ComboBox.SelectedIndex == 1)
                {
                    source.Type   = "Book";
                    source.Title  = BookTitle_Phone.Text;
                    source.Author = BookAuthor_Phone.Text;
                    source.Page   = BookPage_Phone.Text;
                    source.ISBN   = BookISBN_Phone.Text;
                }

                newRecipe.Source = source;
            }

            // append the new note/source to the list, and return the list
            recipeBook.Add(newRecipe);

            return(recipeBook);
        }
        private void Add_Clicked(object sender, RoutedEventArgs e)
        {
            // track a custom event
            GoogleAnalytics.EasyTracker.GetTracker().SendEvent("ui_action", "add_click", "Add: from Recipe_AddNote", 0);

            var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

            // read recipeBook to memory
            RecipeClass        newRecipe  = new RecipeClass();
            List <RecipeClass> recipeBook = buildRecipeBook(newRecipe);

            //roamingSettings.Values["recipeBook"] = recipeBook;

            SplitView.splitviewPage.MainContentFrame.Navigate(typeof(Recipe_HeaderImage));
        }
Esempio n. 4
0
        public void getRecipeDetails(RecipeClass recipe)
        {
            _recipeDetails      = recipe;
            _recipeImage        = recipe.Image.ToString();
            _recipeTitle        = recipe.Label;
            _recipeAuthor       = recipe.Source;
            _recipeLink         = recipe.Url.ToString();
            _recipeHealthLabels = recipe.HealthLabels;
            _recipeIngredients  = recipe.IngredientLines;
            _recipeCalories     = recipe.Calories.ToString();

            OnPropertyChanged("_recipeImage");
            OnPropertyChanged("_recipeTitle");
            OnPropertyChanged("_recipeAuthor");
            OnPropertyChanged("_recipeHealthLabels");
            OnPropertyChanged("_recipeIngredients");
            OnPropertyChanged("_recipeCalories");
        }
Esempio n. 5
0
    protected void UploadRecipe_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            RecipeClass recipeObject;
            RecipeDB recipeDatabase = new RecipeDB();

            if (PhotoUpload.HasFile)
            {
                string FileName = Path.GetFileName(PhotoUpload.PostedFile.FileName);
                string FileNameWithoutExtension = Path.GetFileNameWithoutExtension(PhotoUpload.PostedFile.FileName);
                string FileExtension = Path.GetExtension(PhotoUpload.PostedFile.FileName);

                string FolderPath = "~\\UserFiles\\" + User.Identity.Name.ToString();
                if (!Directory.Exists(FolderPath))
                    Directory.CreateDirectory(Server.MapPath(FolderPath));

                string ImagePath = string.Concat(FolderPath, "\\", FileName);

                int i = 1;
                while(File.Exists(Server.MapPath(ImagePath)))
                {
                    ImagePath = string.Concat(FolderPath, "\\", FileNameWithoutExtension,i.ToString(),FileExtension);
                    i++;
                }

                PhotoUpload.SaveAs(Server.MapPath(ImagePath));

                recipeObject = new RecipeClass(RecipeCategory.SelectedItem.Value, RecipeName.Text,
                    User.Identity.Name, Ingredients.Text, Directions.Text, int.Parse(PreparationTime.Text), ImagePath);
            }
            else
            {
                string ImagePath = "~\\Images\\noimage.jpg";
                recipeObject = new RecipeClass(RecipeCategory.SelectedItem.Value, RecipeName.Text,
                    User.Identity.Name, Ingredients.Text, Directions.Text, int.Parse(PreparationTime.Text), ImagePath);
            }
            recipeDatabase.InsertRecipe(recipeObject);

            Response.Redirect("~\\Default.aspx");
        }
    }
Esempio n. 6
0
    protected void Page_PreRender(object sender, EventArgs e)
    {
        Recipe = recipeDB.GetRecipe(RecipeID);

        RecipeTitle = Recipe.RecipeName;
        PreparationTime = Recipe.PreparationTime;
        Views = Recipe.Views;
        Favorites = Recipe.Favorites;
        Likes = Recipe.Likes;
        DateAdded = Recipe.DateAdded;
        Category = Recipe.RecipeCategory;

        if (Membership.GetUser() != null)
        {
            if (recipeDB.isFav(RecipeID, Membership.GetUser().UserName))
            {
                Favorite_Button.ImageUrl = "~/Images/rem_fav.png";
            }
            else
            {
                Favorite_Button.ImageUrl = "~/Images/add_fav.png";
            }
        }

        if (Recipe.ImagePath != null)
        {
            RecipeImage.ImageUrl = Recipe.ImagePath;
        }

        if (!this.IsPostBack)
        {
            Page.Title = RecipeTitle;
            string[] newLineDelim = { Environment.NewLine };

            string[] _Ingredients = Recipe.Ingredients.Split(newLineDelim, StringSplitOptions.RemoveEmptyEntries);
            foreach (string item in _Ingredients)
            {
                IngredientsList.Items.Add(item);
            }

            string[] _Directions = Recipe.Directions.Split(newLineDelim, StringSplitOptions.RemoveEmptyEntries);
            foreach (string item in _Directions)
            {
                DirectionsList.Items.Add(item);
            }
        }

        this.DataBind();
    }
        public JsonResult GetRecipeData(string productName, string EquipID, string ID)
        {
            var result = RecipeClass.getData(productName, EquipID, ID);

            Dictionary <string, object> response = new Dictionary <string, object>();
            List <RecipeObject>         obj      = new List <RecipeObject>();

            int counter = 0;

            string type = EquipmentModels.GetEquipmentTypeByID(Convert.ToInt32(ID));

            if (type == "")
            {
                var child = EquipmentModels.getChildEquipments(EquipID);
                if (child == null)
                {
                    counter = 0;
                }
                else
                {
                    if (child.Count > 0)
                    {
                        counter = child.Count;
                    }
                    else
                    {
                        counter = 0;
                    }
                }
            }
            else
            {
                counter = 1;
            }

            try
            {
                if (result.Rows.Count > 0)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        var temp_obj = new RecipeObject();
                        temp_obj.RecipeID    = dr["RecipeID"].ToString();
                        temp_obj.RecipeName  = dr["RecipeName"].ToString();
                        temp_obj.RecipeBody  = dr["RecipeBody"].ToString();
                        temp_obj.ProductName = dr["ProductName"].ToString();
                        temp_obj.EquipID     = dr["EquipID"].ToString();
                        temp_obj.Counter     = counter;
                        DataTable dt = new DataTable();
                        dt = RecipeClass.getParams(dr["RecipeID"].ToString());
                        List <string> lstGroupName     = new List <string>();
                        List <string> lstParameterName = new List <string>();
                        List <string> lstMin           = new List <string>();
                        List <string> lstMax           = new List <string>();
                        List <string> lstValue         = new List <string>();
                        if (dt != null)
                        {
                            if (dt.Rows.Count > 0)
                            {
                                foreach (DataRow dr2 in dt.Rows)
                                {
                                    lstGroupName.Add(dr2["GroupName"].ToString());
                                    lstParameterName.Add(dr2["ParameterName"].ToString());
                                    lstMin.Add(dr2["Min"].ToString());
                                    lstMax.Add(dr2["Max"].ToString());
                                    lstValue.Add(dr2["Value"].ToString());
                                }
                            }
                        }
                        temp_obj.GroupName     = lstGroupName;
                        temp_obj.ParameterName = lstParameterName;
                        temp_obj.Min           = lstMin;
                        temp_obj.Max           = lstMax;
                        temp_obj.Value         = lstValue;
                        obj.Add(temp_obj);
                    }
                }
                else
                {
                    obj = null;
                }
            }
            catch
            {
                obj = null;
            }

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
 // Use this for initialization
 void Start()
 {
     //selecte a random Recipe order.
     order = RecipeGeneratorClass.GetRandomRecipe();
 }
Esempio n. 9
0
    public void InsertRecipe(RecipeClass recipe)
    {
        SqlCommand InsertRecipeCommand = new SqlCommand("InsertRecipe", DefaultConnection);

        InsertRecipeCommand.CommandType = CommandType.StoredProcedure;

        InsertRecipeCommand.Parameters.Add("@RecipeCategory", SqlDbType.NVarChar, 50);
        InsertRecipeCommand.Parameters["@RecipeCategory"].Value = recipe.RecipeCategory;

        InsertRecipeCommand.Parameters.Add("@RecipeName", SqlDbType.NVarChar, 50);
        InsertRecipeCommand.Parameters["@RecipeName"].Value = recipe.RecipeName;

        InsertRecipeCommand.Parameters.Add("@Cook", SqlDbType.NVarChar, 50);
        InsertRecipeCommand.Parameters["@Cook"].Value = recipe.Cook;

        InsertRecipeCommand.Parameters.Add("@ImagePath", SqlDbType.NVarChar, recipe.ImagePath.Length);
        InsertRecipeCommand.Parameters["@ImagePath"].Value = recipe.ImagePath;

        InsertRecipeCommand.Parameters.Add("@Ingredients", SqlDbType.Text);
        InsertRecipeCommand.Parameters["@Ingredients"].Value = recipe.Ingredients;

        InsertRecipeCommand.Parameters.Add("@Directions", SqlDbType.Text);
        InsertRecipeCommand.Parameters["@Directions"].Value = recipe.Directions;

        InsertRecipeCommand.Parameters.Add("@PreparationTime", SqlDbType.Int);
        InsertRecipeCommand.Parameters["@PreparationTime"].Value = recipe.PreparationTime;

        InsertRecipeCommand.Parameters.Add("@DateAdded", SqlDbType.Date);
        InsertRecipeCommand.Parameters["@DateAdded"].Value = recipe.DateAdded;

        try
        {
            DefaultConnection.Open();
            InsertRecipeCommand.ExecuteNonQuery();
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            DefaultConnection.Close();
        }
    }
Esempio n. 10
0
    public RecipeClass GetRecipe(int RecipeID)
    {
        SqlCommand GetRecipeCommand;
        if (Membership.GetUser() != null)
        {
            if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || isCook(RecipeID, Membership.GetUser().UserName))
                GetRecipeCommand = new SqlCommand("GetRecipeAdmin", DefaultConnection);
            else
                GetRecipeCommand = new SqlCommand("GetRecipe", DefaultConnection);
        }
        else
            GetRecipeCommand = new SqlCommand("GetRecipe", DefaultConnection);

        GetRecipeCommand.CommandType = CommandType.StoredProcedure;

        GetRecipeCommand.Parameters.Add(new SqlParameter("@RecipeID", SqlDbType.Int));
        GetRecipeCommand.Parameters["@RecipeID"].Value = RecipeID;

        try
        {
            DefaultConnection.Open();

            SqlDataReader RecipeReader = GetRecipeCommand.ExecuteReader(CommandBehavior.SingleRow);
            RecipeReader.Read();

            RecipeClass recipe = new RecipeClass();

            recipe.RecipeCategory = RecipeReader["RecipeCategory"].ToString();
            recipe.RecipeName = RecipeReader["RecipeName"].ToString();
            recipe.Cook = RecipeReader["Cook"].ToString();
            recipe.Directions = RecipeReader["Directions"].ToString();
            recipe.Ingredients = RecipeReader["Ingredients"].ToString();
            recipe.Views = (int)RecipeReader["views"];
            recipe.Favorites = (int)RecipeReader["favorites"];
            recipe.Likes = (int)RecipeReader["likes"];
            recipe.PreparationTime = (int)RecipeReader["PreparationTime"];
            recipe.ImagePath = RecipeReader["ImagePath"].ToString();
            recipe.DateAdded = (DateTime)RecipeReader["DateAdded"];

            RecipeReader.Close();
            return recipe;
        }
        catch (SqlException err)
        {
            throw new ApplicationException(err.Message);
        }
        finally
        {
            DefaultConnection.Close();
        }
    }
Esempio n. 11
0
        public IActionResult Add(NewRecipeVM obj)
        {
            int?uid  = HttpContext.Session.GetInt32("UID");
            int uid2 = uid.Value;

            if (ModelState.IsValid)
            {
                //RecipeClass newRecipe = context.Recipes.Single(c => c.RecId == obj.RecId);
                TagsClass t = new TagsClass
                {
                    TagName = obj.TagName
                };
                context.Tags.Add(t);
                context.SaveChanges();


                RecipeClass r = new RecipeClass
                {
                    RecName = obj.RecName,
                    TagsId  = t.Id,
                    UserId  = uid2
                              //Calories = obj.Calories
                };
                context.Recipes.Add(r);
                context.SaveChanges();


                InstructionsClass inst = new InstructionsClass
                {
                    RecipeId  = r.Id,
                    StepOrder = obj.StepOrder,
                    Instruct  = obj.Instruct
                };
                context.Instructions.Add(inst);
                context.SaveChanges();

                IngredientsClass ing = new IngredientsClass
                {
                    IngName = obj.IngName,
                    UM      = obj.UM
                              //Id = ingQ.Id
                };
                context.Ingredients.Add(ing);
                context.SaveChanges();

                IngQuantClass ingQ = new IngQuantClass
                {
                    RecipeClassId      = r.Id,
                    IngredientsClassId = ing.Id,
                    Quantity           = obj.Quantity
                };
                context.IngQuant.Add(ingQ);
                context.SaveChanges();

                ViewBag.message = "Recipe created";

                return(Redirect("/Index"));
            }

            return(View(obj));
        }