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); }
public int GetRating(long userId, long linkId) { if (!UserProfileDao.Exists(userId)) { throw new InstanceNotFoundException <UserProfileDetails>("userId", userId); } if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } try { return(RatingDao.FindForUserAndLink(userId, linkId).value); } catch (InstanceNotFoundException <Rating> ) { return(0); } catch (DuplicateInstanceException <Rating> ex) { throw new InternalErrorException(ex); } }
public FavoriteDetails GetFavorite(long userId, long linkId) { if (!UserProfileDao.Exists(userId)) { throw new InstanceNotFoundException <UserProfileDetails>("userId", userId); } if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } Favorite favorite; try { favorite = FavoriteDao.FindForUserAndLink(userId, linkId); } catch (InstanceNotFoundException <Favorite> ex) { throw new InstanceNotFoundException <FavoriteDetails>(ex.Properties); } catch (DuplicateInstanceException <Favorite> ex) { throw new InternalErrorException(ex); } return(new FavoriteDetails(favorite.favoriteId, favorite.linkId, favorite.name, favorite.description, favorite.date)); }
public DictionaryBlock <string, long> GetLabelsForLink(long linkId, int startIndex, int count) { if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } ListBlock <Label> labels; try { labels = LabelDao.ListForLinkRated(linkId, startIndex, count); } catch (InstanceNotFoundException <Label> ) { return(new DictionaryBlock <string, long>(startIndex, false)); } catch (NoMoreItemsException <Label> ) { return(new DictionaryBlock <string, long>(startIndex, false)); } DictionaryBlock <string, long> details = new DictionaryBlock <string, long>(labels.Index, labels.HasMore); foreach (Label label in labels) { int rating = RatingDao.CalculateValueForLabel(label.text); details.Add(label.text, rating); } return(details); }
public int CountCommentsForLink(long linkId) { if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } return(CommentDao.CountForLink(linkId)); }
public bool HasInFavorites(long userId, long linkId) { if (!UserProfileDao.Exists(userId)) { throw new InstanceNotFoundException <UserProfileDetails>("userId", userId); } if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } return(FavoriteDao.ExistsForUserAndLink(userId, linkId)); }
public ListBlock <CommentDetails> GetCommentsForLink(long linkId, int startIndex, int count) { if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } ListBlock <Comment> comments; try { comments = CommentDao.ListForLink(linkId, startIndex, count); } catch (InstanceNotFoundException <Comment> ) { return(new ListBlock <CommentDetails>(startIndex, false)); } catch (NoMoreItemsException <Comment> ) { return(new ListBlock <CommentDetails>(startIndex, false)); } List <CommentDetails> details = new List <CommentDetails>(); foreach (Comment comment in comments) { UserProfile user; try { user = UserDao.Find(comment.userId); } catch (InstanceNotFoundException <UserProfile> ex) { throw new InternalErrorException(ex); } details.Add(new CommentDetails(comment.commentId, comment.text, comment.userId, user.userLogin, comment.linkId, comment.date)); } return(new ListBlock <CommentDetails>(details, comments.Index, comments.HasMore)); }
public void UpdateFavorite(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); } Favorite favorite; try { favorite = FavoriteDao.FindForUserAndLink(userId, linkId); } catch (InstanceNotFoundException <Favorite> ex) { throw new InstanceNotFoundException <FavoriteDetails>(ex.Properties); } catch (DuplicateInstanceException <Favorite> ex) { throw new InternalErrorException(ex); } favorite.name = name; favorite.description = description; try { FavoriteDao.Update(favorite); } catch (InstanceNotFoundException <Favorite> ex) { throw new InternalErrorException(ex); } }
public long AddComment(long userId, long linkId, string text) { if (!UserDao.Exists(userId)) { throw new InstanceNotFoundException <UserProfileDetails>("userId", userId); } if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } Comment comment = Comment.CreateComment(-1, userId, linkId, text, DateTime.Now); try { CommentDao.Create(comment); } catch (DuplicateInstanceException <Comment> ex) { throw new InternalErrorException(ex); } return(comment.commentId); }
public void RemoveFromFavorites(long userId, long linkId) { if (!UserProfileDao.Exists(userId)) { throw new InstanceNotFoundException <UserProfileDetails>("userId", userId); } if (!LinkDao.Exists(linkId)) { throw new InstanceNotFoundException <LinkDetails>("linkId", linkId); } Favorite favorite; try { favorite = FavoriteDao.FindForUserAndLink(userId, linkId); } catch (InstanceNotFoundException <Favorite> ex) { throw new InstanceNotFoundException <FavoriteDetails>(ex.Properties); } catch (DuplicateInstanceException <Favorite> ex) { throw new InternalErrorException(ex); } try { FavoriteDao.Remove(favorite.favoriteId); } catch (InstanceNotFoundException <Favorite> ex) { throw new InternalErrorException(ex); } }
public bool ExistsLink(long linkId) { return(LinkDao.Exists(linkId)); }