public long AddToFavorites(long userId, long linkId, string name, string description) { if (!UserProfileDao.Exists(userId)) { throw new InstanceNotFoundException <UserProfileDetails>("userId", userId); } if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } if (FavoriteDao.ExistsForUserAndLink(userId, linkId)) { throw new DuplicateInstanceException <FavoriteDetails>("userId", userId, "linkId", linkId); } Favorite favorite = Favorite.CreateFavorite(-1, userId, linkId, name, description, DateTime.Now); try { FavoriteDao.Create(favorite); } catch (DuplicateInstanceException <Favorite> ex) { throw new InternalErrorException(ex); } return(favorite.favoriteId); }
private Favorite CreateTestFavorite(UserProfile user, Link link, string favoriteName, string favoriteDescription, DateTime time) { Favorite favorite = Favorite.CreateFavorite( TestData.nonExistentFavoriteId, user.userId, link.linkId, favoriteName, favoriteDescription, Trunk(time)); FavoriteDao.Create(favorite); return(favorite); }