private HelpfulnessVoteResponse RegisterAnonymousVote(HelpfulnessVoteModel voteModel, ProductReview productReview, Product productPage, bool isHelpful) { if (productReview.Votes.Any(v => v.IPAddress == voteModel.IPAddress)) { return new HelpfulnessVoteResponse { Type = ProductReviewResponseType.Info, Message = "Already voted", RedirectUrl = "~/" + productPage.LiveUrlSegment }; } var vote = new HelpfulnessVote { IsHelpful = isHelpful, ProductReview = productReview, IPAddress = voteModel.IPAddress }; productReview.Votes.Add(vote); _session.Transact(session => session.Save(vote)); return new HelpfulnessVoteResponse { Message = "Vote registered", RedirectUrl = "~/" + productPage.LiveUrlSegment, Type = ProductReviewResponseType.Success }; }
public void Add(ProductReview productReview) { User user = _getCurrentUser.Get(); if (user != null) { productReview.User = user; productReview.Name = user.Name; productReview.Email = user.Email; } _session.Transact(session => session.Save(productReview)); }
private HelpfulnessVoteResponse RegisterLoggedInVote(HelpfulnessVoteModel voteModel, ProductReview productReview, User currentUser, Product productPage, bool isHelpful) { if (productReview.Votes.Any(v => v.IsHelpful == isHelpful && v.User == currentUser)) { return new HelpfulnessVoteResponse { Type = ProductReviewResponseType.Info, Message = "Already voted", RedirectUrl = "~/" + productPage.LiveUrlSegment }; } List<HelpfulnessVote> oppositeVotes = productReview.Votes.Where(v => v.IsHelpful != isHelpful && v.User == currentUser).ToList(); if (oppositeVotes.Any()) { _session.Transact(session => oppositeVotes.ForEach(v => { productReview.Votes.Remove(v); session.Delete(v); })); } var vote = new HelpfulnessVote { IsHelpful = isHelpful, User = currentUser, ProductReview = productReview, IPAddress = voteModel.IPAddress }; productReview.Votes.Add(vote); _session.Transact(session => session.Save(vote)); return new HelpfulnessVoteResponse { Message = "Vote registered", RedirectUrl = "~/" + productPage.LiveUrlSegment, Type = ProductReviewResponseType.Success }; }
public void Delete(ProductReview productReview) { _session.Transact(session => session.Delete(productReview)); }
public void Update(ProductReview productReview) { _session.Transact(session => session.Update(productReview)); }