예제 #1
0
        protected void bSaveRecipe_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    // TODO: category tags..
                    long rid = Convert.ToInt64(atHiddenRecipeId.Value);
                    if (rid > 0)
                    {
                        aqufitEntities entities = new aqufitEntities();
                        Recipe         r        = entities.UserStreamSet.OfType <Recipe>().FirstOrDefault(s => s.Id == rid && s.UserSetting.UserKey == this.UserId && s.UserSetting.PortalKey == this.PortalId);
                        if (r == null)  // security exception
                        {
                            // TODO: send a notification email
                            throw new Exception("Security Exception:  User does not own data.  Action has been logged");
                        }
                    }
                    string[] ingredients = atiRecipeIngredients.Text.Split('\n');
                    Affine.Data.json.RecipeIngredient[] riArray = ingredients.Where(i => !string.IsNullOrEmpty(i)).Select(i => new Affine.Data.json.RecipeIngredient()
                    {
                        Name = i
                    }).ToArray();

                    Affine.Data.json.RecipeExtended re = new Data.json.RecipeExtended()
                    {
                        Directions  = atiRecipeDirections.Text,
                        Ingredients = riArray
                    };
                    // TODO: Ingredients
                    string   extraTags   = string.Empty;
                    CheckBox cbBreakfast = (CheckBox)atiRecipeCategoriesPanel.FindControl("breakfast");
                    if (cbBreakfast.Checked)
                    {
                        extraTags += "," + cbBreakfast.Text;
                    }
                    CheckBox cbLunch = (CheckBox)atiRecipeCategoriesPanel.FindControl("lunch");
                    if (cbLunch.Checked)
                    {
                        extraTags += "," + cbLunch.Text;
                    }
                    CheckBox cbDinner = (CheckBox)atiRecipeCategoriesPanel.FindControl("dinner");
                    if (cbDinner.Checked)
                    {
                        extraTags += "," + cbDinner.Text;
                    }
                    CheckBox cbSnack = (CheckBox)atiRecipeCategoriesPanel.FindControl("snack");
                    if (cbSnack.Checked)
                    {
                        extraTags += "," + cbSnack.Text;
                    }
                    CheckBox cbDessert = (CheckBox)atiRecipeCategoriesPanel.FindControl("dessert");
                    if (cbDessert.Checked)
                    {
                        extraTags += "," + cbDessert.Text;
                    }
                    Affine.Data.json.StreamData recipe = new Data.json.StreamData()
                    {
                        Id             = rid,
                        Title          = atiRecipeName.Text,
                        Description    = atiRecipeDescription.Text,
                        AvrRating      = Convert.ToDouble(atiHiddenRecipeRate.Value),
                        AvrStrictness  = Convert.ToDouble(atiHiddenRecipeStrict.Value),
                        Tags           = atiRecipeTags.Text + extraTags,
                        NumServings    = Convert.ToInt32(atiRecipeServings.Text),
                        TimePrep       = Convert.ToInt32(atiRecipePrep.Text),
                        TimeCook       = Convert.ToInt32(atiRecipeCook.Text),
                        RecipeExtended = re
                    };

                    Affine.WebService.StreamService service = new WebService.StreamService();
                    long id = service.SaveRecipe(this.UserId, this.PortalId, recipe);
                    // long id = 0;
                    litStatus.Text = "<em>SUCESS</em> Your recipe has been saved.  To Finish attach some image files then press 'done'.";
                    RadAjaxManager1.ResponseScripts.Add(" Paleo.AddMedia(" + id + "); ");
                }
            }
            catch (Exception ex)
            {
                litStatus.Text = "<span style=\"color: red;\"><em>FAIL</em> " + ex.Message + "</span>";
                RadAjaxManager1.ResponseScripts.Add(" Paleo.OnFail(); ");
            }
        }
예제 #2
0
        protected void bSaveRecipe_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    // TODO: category tags..
                    long rid = Convert.ToInt64(atHiddenRecipeId.Value);
                    if (rid > 0)
                    {
                        aqufitEntities entities = new aqufitEntities();
                        Recipe r = entities.UserStreamSet.OfType<Recipe>().FirstOrDefault(s => s.Id == rid && s.UserSetting.UserKey == this.UserId && s.UserSetting.PortalKey == this.PortalId);
                        if (r == null)  // security exception
                        {
                            // TODO: send a notification email
                            throw new Exception("Security Exception:  User does not own data.  Action has been logged");
                        }
                    }
                    string[] ingredients = atiRecipeIngredients.Text.Split('\n');
                    Affine.Data.json.RecipeIngredient[] riArray = ingredients.Where( i => !string.IsNullOrEmpty(i) ).Select(i => new Affine.Data.json.RecipeIngredient() { Name = i }).ToArray();

                    Affine.Data.json.RecipeExtended re = new Data.json.RecipeExtended()
                    {
                        Directions = atiRecipeDirections.Text,
                        Ingredients = riArray
                    };
                    // TODO: Ingredients
                    string extraTags = string.Empty;
                    CheckBox cbBreakfast = (CheckBox)atiRecipeCategoriesPanel.FindControl("breakfast");
                    if( cbBreakfast.Checked ){
                        extraTags += ","+cbBreakfast.Text;
                    }
                    CheckBox cbLunch = (CheckBox)atiRecipeCategoriesPanel.FindControl("lunch");
                    if (cbLunch.Checked)
                    {
                        extraTags += "," + cbLunch.Text;
                    }
                    CheckBox cbDinner = (CheckBox)atiRecipeCategoriesPanel.FindControl("dinner");
                    if (cbDinner.Checked)
                    {
                        extraTags += "," + cbDinner.Text;
                    }
                    CheckBox cbSnack = (CheckBox)atiRecipeCategoriesPanel.FindControl("snack");
                    if (cbSnack.Checked)
                    {
                        extraTags += "," + cbSnack.Text;
                    }
                    CheckBox cbDessert = (CheckBox)atiRecipeCategoriesPanel.FindControl("dessert");
                    if (cbDessert.Checked)
                    {
                        extraTags += "," + cbDessert.Text;
                    }
                    Affine.Data.json.StreamData recipe = new Data.json.StreamData()
                    {
                        Id = rid,
                        Title = atiRecipeName.Text,
                        Description = atiRecipeDescription.Text,
                        AvrRating = Convert.ToDouble(atiHiddenRecipeRate.Value),
                        AvrStrictness = Convert.ToDouble(atiHiddenRecipeStrict.Value),
                        Tags = atiRecipeTags.Text + extraTags,
                        NumServings = Convert.ToInt32(atiRecipeServings.Text),
                        TimePrep = Convert.ToInt32(atiRecipePrep.Text),
                        TimeCook = Convert.ToInt32(atiRecipeCook.Text),
                        RecipeExtended = re
                    };

                    Affine.WebService.StreamService service = new WebService.StreamService();
                    long id = service.SaveRecipe(this.UserId, this.PortalId, recipe);
                   // long id = 0;
                    litStatus.Text = "<em>SUCESS</em> Your recipe has been saved.  To Finish attach some image files then press 'done'.";
                    RadAjaxManager1.ResponseScripts.Add(" Paleo.AddMedia("+id+"); ");

                }
            }
            catch (Exception ex)
            {
                litStatus.Text = "<span style=\"color: red;\"><em>FAIL</em> "+ex.Message+"</span>";
                RadAjaxManager1.ResponseScripts.Add(" Paleo.OnFail(); ");
            }
        }