public async Task <bool> CheckPostTopicAndParentId(PostCommentData err, ForumContext context) { if (!int.TryParse(TopicId, out int topicId)) { err.TopicId = "Topic id is incorrect"; return(false); } else if (await context.GetTopicById(topicId) == null) { err.TopicId = "Topic doesn't exist"; return(false); } else if (ParentCommentId != null) { if (!int.TryParse(ParentCommentId, out int parentCommentId)) { err.ParentCommentId = "Parent comment id is incorrect"; return(false); } else if (await context.GetCommentInTopic(topicId, parentCommentId) == null) { err.ParentCommentId = "Comment doesn't exist or doesn't belong to topic"; return(false); } } return(true); }
public async Task <string> DislikeTopic(string username, ForumContext context) { if (!int.TryParse(Id, out int id)) { return("Id is invalid"); } else if (await context.GetTopicById(id) == null) { return("Topic doesn't exist"); } var like = await context.GetTopicScore(id, username); if (like == null) { await context.DislikeTopic(id, username); return(null); } else if (like.Score == Score.Like) { await context.DeleteTopicLike(id, username); return(null); } else { return("User is already dislike topic"); } }