Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (LicentaEntities entities = new LicentaEntities())
     {
         var ret = entities.Users.FirstOrDefault(x => x.Username == HttpContext.Current.Request.LogonUserIdentity.Name);
         if (ret == null)
         {
             entities.Users.Add(new User {
                 Username = HttpContext.Current.Request.LogonUserIdentity.Name
             });
             entities.SaveChanges();
         }
     }
 }
Example #2
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            LicentaEntities model = new LicentaEntities();

            Recommendation recommendation = model.Recommendations.FirstOrDefault(x => x.UserId == HttpContext.Current.Request.LogonUserIdentity.Name);

            if (recommendation == null)
            {
                List <Recipe> recipes = new List <Recipe>(GetRandomRecipes());
                global_recipes       = recipes;
                DataList1.DataSource = recipes;
                DataList1.DataBind();
            }
            else
            {
                List <Recipe> recipes = new List <Recipe>();
                int           count   = 0;
                foreach (string id in recommendation.Recommendations.Split(','))
                {
                    if (count >= 15)
                    {
                        break;
                    }

                    Recipe recipe = GetReceipeInfo(Int32.Parse(id));
                    if (!string.IsNullOrEmpty(recipe.Title) || !string.IsNullOrWhiteSpace(recipe.Title))
                    {
                        recipe.ingredients  = GetReceipeIngredients(recipe.ID);
                        recipe.instructions = GetReceipeInstructions(recipe.ID);
                        count++;
                        recipes.Add(recipe);
                    }
                }

                global_recipes       = recipes;
                DataList1.DataSource = recipes;
                DataList1.DataBind();
            }
        }