Ejemplo n.º 1
0
 public string getRecipe(long rid)
 {
     aqufitEntities entities = new aqufitEntities();
     IQueryable< UserStream > stream = entities.UserStreamSet.Include("UserSetting").Where(s => s.Id == rid);
     // hydrate the metrics
     stream.Select(m => m.UserSetting.Metrics).ToArray();
     UserComment[] comments = entities.UserComment.Include("UserSetting").Where(c => c.UserStream.Id == rid ).ToArray();
     RecipeExtended r = entities.RecipeExtendeds.Include("Image").Include("RecipeIngredients").FirstOrDefault(s => s.UserStream.Id == rid);
     IList<Affine.Data.json.StreamData> dsList = _IStreamManager.UserStreamArrayToStreamDataArray( new UserStream[]{ stream.First() }, comments);
     Affine.Data.json.StreamData ds = dsList[0];
     Affine.Data.json.RecipeExtended re = new Data.json.RecipeExtended()
     {
         Id = r.Id,
         NumRatings = r.NumRatings,
         NumStrictness = r.NumStrictness,
         Directions = r.Directions
     };
     re.Image1Id = r.Image != null ? r.Image.Id : 0;
     re.Image2Id = Convert.ToInt64( r.Image2Key );
     re.Image3Id = Convert.ToInt64(r.Image3Key);
     re.Image4Id = Convert.ToInt64(r.Image4Key);
     re.Ingredients = r.RecipeIngredients.Select(i => new Affine.Data.json.RecipeIngredient() { Id = i.Id, Name = i.Text }).ToArray();
     ds.RecipeExtended = re;
     string json = _jserializer.Serialize(ds);
     return json;
 }
Ejemplo n.º 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(); ");
            }
        }
Ejemplo n.º 3
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(); ");
            }
        }