public ActionResult AddFavorite(FavoriteForum newFavoriteForum) { if (!favoriteForumDAO.DoesFavoriteExist(newFavoriteForum)) { FavoriteForum favoriteForum = favoriteForumDAO.AddFavorite(newFavoriteForum); if (favoriteForum != null) { return(Ok(favoriteForum)); } } return(StatusCode(409)); }
public FavoriteForum AddFavorite(FavoriteForum favoriteForum) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.FavoriteForums.Add(favoriteForum); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(favoriteForum); }
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); }