public async Task <ActionResult> PostComment(ViewWordViewModel model, string wordId) { if (!String.IsNullOrWhiteSpace(model.Comment)) { // get account id string userId = await Task.Run(() => User.Identity.GetUserId()); // add comment WordComment comment = await this.m_commentService.PostWordCommentAsync(userId, wordId, model.Comment); // Check result if (comment != null) { // Update target return(PartialView("_WordCommentPartial", comment)); } else { return(View()); } } else { return(View()); } }
public async Task <ServiceResult> UnlikeCommentAsync(string userId, string commentId) { try { // Delete from database await this.m_userLikeWordCommentRepository.DeleteAsync(t => t.UserId == userId && t.CommentId == commentId); WordComment comment = this.m_wordCommentRepository.FindEntity(t => t.Id == commentId); // Update number of votes comment.Votes = comment.Votes - 1; // update comment await this.m_wordCommentRepository.UpdateAsync(comment); // save changes await m_userLikeWordCommentRepository.SaveChangesAsync(); await m_wordCommentRepository.SaveChangesAsync(); // return successfull return(ServiceResult.Success); } catch (Exception ex) { return(ServiceResult.AddError(ex.Message)); } }
public async Task <ServiceResult> LikeCommentAsync(string userId, string commentId) { try { // Create result user liked comment UserLikedWordComment result = EntityFactory.CreateUserLikeWordComment(userId, commentId); // Insert to database await this.m_userLikeWordCommentRepository.InsertAsync(result); WordComment comment = await this.m_wordCommentRepository.FindEntityAsync(t => t.Id == commentId); // Update number of votes comment.Votes = comment.Votes + 1; // update comment await this.m_wordCommentRepository.UpdateAsync(comment); // save changes await m_userLikeWordCommentRepository.SaveChangesAsync(); await m_wordCommentRepository.SaveChangesAsync(); // return successfull return(ServiceResult.Success); } catch (Exception ex) { return(ServiceResult.AddError(ex.Message)); } }
public WordComment PostWordComment(string userId, string wordId, string content) { // Create WordComment comment = EntityFactory.CreateWordComment(userId, wordId, content); try { // Insert comment this.m_wordCommentRepository.Insert(comment); this.m_wordCommentRepository.SaveChanges(); // Return successfull return(comment); } catch { return(null); } }
public ServiceResult LikeComment(string userId, string commentId) { try { // Create result user liked comment UserLikedWordComment result = EntityFactory.CreateUserLikeWordComment(userId, commentId); // Insert to database this.m_userLikeWordCommentRepository.Insert(result); WordComment comment = this.m_wordCommentRepository.FindEntity(t => t.Id == commentId); // Update number of votes comment.Votes = comment.Votes + 1; // update comment this.m_wordCommentRepository.Update(comment); // return successfull return(ServiceResult.Success); } catch (Exception ex) { return(ServiceResult.AddError(ex.Message)); } }
public async Task <WordComment> PostWordCommentAsync(string userId, string wordId, string content) { // Create WordComment comment = EntityFactory.CreateWordComment(userId, wordId, content); try { // Insert comment await this.m_wordCommentRepository.InsertAsync(comment); await this.m_wordCommentRepository.SaveChangesAsync(); // Return successfull return(comment); } catch { // Add error return(comment); } }