Esempio n. 1
0
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Recipe   recipe   = (Recipe)Session["Recipe"];
            Favorite favorite = new Favorite();

            favorite = model.Favorites.FirstOrDefault(x => x.UserId == HttpContext.Current.Request.LogonUserIdentity.Name && x.RecipeId == recipe.ID);

            if (favorite == null)
            {
                favorite          = new Favorite();
                favorite.RecipeId = recipe.ID;
                favorite.UserId   = HttpContext.Current.Request.LogonUserIdentity.Name;
                favorite.Rating   = Int32.Parse(selectedValue);

                model.Favorites.Add(favorite);
                model.SaveChanges();
            }
            else
            {
                model.Entry(favorite).State = EntityState.Deleted;
                model.SaveChanges();
                favorite.Rating = Int32.Parse(selectedValue);

                model.Favorites.Add(favorite);
                model.SaveChanges();
            }
        }
Esempio n. 2
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();
         }
     }
 }