Пример #1
0
 public ActionResult AddFavorite(FavoriteForum newFavoriteForum)
 {
     if (!favoriteForumDAO.DoesFavoriteExist(newFavoriteForum))
     {
         FavoriteForum favoriteForum = favoriteForumDAO.AddFavorite(newFavoriteForum);
         if (favoriteForum != null)
         {
             return(Ok(favoriteForum));
         }
     }
     return(StatusCode(409));
 }
Пример #2
0
 public FavoriteForum AddFavorite(FavoriteForum favoriteForum)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.FavoriteForums.Add(favoriteForum);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(favoriteForum);
 }
Пример #3
0
        public bool DoesFavoriteExist(FavoriteForum favorite)
        {
            bool doesExist = false;

            try
            {
                using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
                {
                    if (nightCapDBContext.FavoriteForums.Any(f => f.UserId == favorite.UserId && f.ForumId == favorite.ForumId))
                    {
                        doesExist = true;
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(doesExist);
        }