예제 #1
0
파일: Site.Master.cs 프로젝트: GeraElem/VS
        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)
            {
            }
        }
예제 #2
0
파일: Admin.cs 프로젝트: 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.");
            }
        }
예제 #3
0
파일: Admin.cs 프로젝트: 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();
            }
        }