Example #1
0
        /// <summary>
        /// Favorite the article,
        /// One count per user
        /// </summary>
        /// <param name="article_id"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public bool Favorite(int article_id, string info)
        {
            Favorite obj = new Data.Favorite() { DateTime = DateTime.Now, Article_ID = article_id, UserIP = info };
            try
            {
                if (!_db.Favorites.Any(x => x.Article_ID == article_id & x.UserIP == info))
                    _db.Favorites.Add(obj);

            }
            catch (Exception ex)
            {

                throw;
            }
            return _db.SaveChanges() > 0;
        }
Example #2
0
        public bool SetFavorite(int id)//FavoriteCreate model)
        {
            var entity =
                new Data.Favorite()
            {
                OwnerId = _userId,
                //FavoriteId = 22,//model.FavoriteId,
                NoteId = id //NoteId//model.NoteId,
                            //CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Favorites.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }