Esempio n. 1
0
        protected void lnkAddFav_Click(object sender, EventArgs e)
        {
            try
            {
                var user = (Users)Session["UserLogged"];

                DataAccess.Menu oMenu = new Admin().GetMenuByUrl(Request.Url.AbsolutePath);

                var oFav = new Favoritos {MenuId = oMenu.MenuId, PersonaId = user.PersonaId};
                new Admin().AddFavorito(oFav);

                Session["MenuFavoritos"] = new Admin().GetListFavorito(user.PersonaId);

                var listaFav = (List<Favoritos>)Session["MenuFavoritos"];

                this.rptMenuFav.DataSource = listaFav;
                this.rptMenuFav.DataBind();

                if (listaFav.Where(p => p.Menu.Url == Request.Url.AbsolutePath).ToList().Count > 0)
                    this.lnkAddFav.Visible = false;
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 2
0
File: Admin.cs Progetto: GeraElem/VS
        public void AddFavorito(Favoritos fav)
        {
            try
            {
                using (var context = new QuirofanoEntities())
                {
                    context.Favoritos.AddObject(fav);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("23505"))
                    throw new Exception("Error: no puede asignar dos veces el mismo favorito.");
            }
        }
Esempio n. 3
0
File: Admin.cs Progetto: GeraElem/VS
        public void UpdateFavorito(Favoritos fav)
        {
            using (var context = new QuirofanoEntities())
            {
                Favoritos fav2 = context.Favoritos.First(i => i.FavoritoId == fav.FavoritoId);

                fav2.MenuId = fav.MenuId;
                fav2.PersonaId = fav.PersonaId;

                context.SaveChanges();
            }
        }