public ForumQuestion FindForumQuestionByQuestionHeader(string questionHeader) { ForumQuestion fq = new ForumQuestion(); for (int i = 0; i < forumQuestions.Count; i += 1) { string fqHeader = forumQuestions[i].QuestionHeader; if (fqHeader == questionHeader) { fq = forumQuestions[i]; } } return(fq); }
private async Task <bool> SendEmailToForumActiveUsers(ForumQuestion question, ForumAnswer answer, CancellationToken cancellationToken) { var moduleQry = await _db.ModuleCollection.FindAsync(m => m.Id == question.ModuleId, cancellationToken : cancellationToken); var module = await moduleQry.SingleOrDefaultAsync(cancellationToken); var forumEmailUsers = _db.UserCollection.AsQueryable().Where(u => u.ForumActivities.HasValue && u.ForumActivities.Value).ToList(); try { if (forumEmailUsers != null && forumEmailUsers.Count > 0) { foreach (User user in forumEmailUsers) { if (user != null && (!string.IsNullOrEmpty(user.ForumEmail) || !string.IsNullOrEmpty(user.Email))) { var emailToSend = string.IsNullOrEmpty(user.ForumEmail) ? user.Email : user.ForumEmail; var emailData = new EmailUserData { Email = emailToSend, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.UserName }, { "username", answer.UserName }, { "forumTitle", question.Title }, { "forumUrl", _options.Value.SiteUrl + $"/forum/{module.Title}/{question.ModuleId}/{question.Id}" } } }; await _provider.SendEmail(emailData, "Uma atividade no módulo " + module.Title, "BTG-ForumActivity"); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
private async Task <bool> SendEmailToQuestioner(ForumQuestion question, CancellationToken cancellationToken) { var userQry = await _db.UserCollection.FindAsync(u => u.Id == question.CreatedBy, cancellationToken : cancellationToken); var user = await userQry.SingleOrDefaultAsync(cancellationToken); var moduleQry = await _db.ModuleCollection.FindAsync(m => m.Id == question.ModuleId, cancellationToken : cancellationToken); var module = await moduleQry.SingleOrDefaultAsync(cancellationToken); try { if (user != null && module != null) { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.Name }, { "forumTitle", question.Title }, { "forumUrl", _options.Value.SiteUrl + $"/forum/{module.Title}/{question.ModuleId}/{question.Id}" } } }; await _provider.SendEmail(emailData, "Responderam sua pergunta", "BTG-ForumQuestionAnswered"); await SaveNotification(user.Id, module, question.Id, true); return(true); } return(false); } catch (Exception ex) { await SaveNotification(user.Id, module, question.Id, false); return(false); } }
private List <string> GetLikedByWithoutUser(ForumQuestion question, string userId) { return(question.LikedBy .Where(uId => uId != userId) .ToList()); }
private bool IsQuestionLikedByUser(ForumQuestion question, string userId) { return(question.LikedBy.Any(uId => uId == userId)); }
public void AddReply(ForumQuestion fq, Reply r, Member replyMember) { replies.Add(r); replyMember.Answers.Add(r); fq.AddReply(r); }
public void AddForumQuestion(ForumQuestion fq, Member member) { member.QuestionsAsked.Add(fq); forumQuestions.Add(fq); }
private void AddTestData() { Member m1 = new Member { Name = "Michelangelo di Lodovico Buonarroti Simoni", Password = "******", Title = "Member" }; Member m2 = new Member { Name = "Donato di Niccolò di Betto Bardi", Password = "******", Title = "Member" }; Member m3 = new Member { Name = "Leonardo da Vinci", Password = "******", Title = "Member" }; Member m4 = new Member { Name = "Raffaello Sanzio da Urbino", Password = "******", Title = "Member" }; AddMember(m1); AddMember(m2); AddMember(m3); AddMember(m4); // Make Forum Questions ForumQuestion fq1 = new ForumQuestion { Questioner = m1, DateAdded = new DateTime(2017, 1, 1), QuestionHeader = "Year, Month, and Day parameters " + "describe an un-representable DateTime Exception", QuestionBody = "I'm getting this error when I try to " + "print a DateTime object on my website.", }; // Populate keywords fq1.FindKeywords(); ForumQuestion fq2 = new ForumQuestion { Questioner = m2, DateAdded = new DateTime(2019, 4, 7), QuestionHeader = "Null pointer references when the .cshtml page tries to render Comment objects.", QuestionBody = "The debugger shows that there is a comment object, but the user name is Null.", }; // Populate keywords fq2.FindKeywords(); // Make Replies Reply r1 = new Reply() { DateAdded = new DateTime(2017, 1, 4), Responder = m3, ReplyBody = "Have you tried adding a .ToString?", }; Reply r2 = new Reply() { DateAdded = new DateTime(2017, 1, 5), Responder = m4, ReplyBody = "Try adding a date string formatter. I used this " + " to get year-month-day: dateObj.ToString('yyyy - MM - dd')", }; // Find keywords in replies r1.FindKeywords(); r2.FindKeywords(); // Add replies to forum questions AddReply(fq1, r1, m3); AddReply(fq1, r2, m4); // Add replies to context AddForumQuestion(fq1, m1); AddForumQuestion(fq2, m2); // Make FAQs/Kbs FAQuestion faq1 = new FAQuestion { // Date DateAdded = new DateTime(2019, 2, 28), // Title QuestionHeader = "What is a method and why do I have to call it?", // Body QuestionBody = "A method is a code block that contains a series " + "of statements. A program causes the statements to be executed " + "by calling the method and specifying any required method " + "arguments. In C#, every executed instruction is performed in " + "the context of a method. The Main method is the entry point " + "for every C# application and it's called by the common " + "language runtime (CLR) when the program is started. " + "The method definition specifies the names and types of any" + " parameters that are required. When calling code calls the" + " method, it provides concrete values called arguments for each" + " parameter. The arguments must be compatible with the " + "parameter type but the argument name (if any) used in the " + "calling code doesn't have to be the same as the parameter " + "named defined in the method. ", }; FAQuestion faq2 = new FAQuestion { DateAdded = new DateTime(2019, 10, 9), // Title QuestionHeader = "What is the difference between ref & out " + "parameters?", // Body QuestionBody = "An argument passed as ref must be initialized" + " before passing to the method whereas the out parameter needs not " + "to be initialized before passing to a method. ", }; FAQuestion faq3 = new FAQuestion { DateAdded = new DateTime(2018, 3, 15), // Title QuestionHeader = "What is the difference between public, " + "static, and void?", // Body QuestionBody = "Public declared variables or methods are " + "accessible anywhere in the application. Static declared " + "variables or methods are globally accessible without creating " + "an instance of the class. Static member are by default not" + " globally accessible it depends upon the type of access " + "modified used. The compiler stores the address of the method " + "as the entry point and uses this information to begin" + " execution before any objects are created. And Void is a " + "type modifier that states that the method or variable does " + "not return any value. ", }; // Add keywords faq1.FindKeywords(); faq2.FindKeywords(); faq3.FindKeywords(); // Add FAQs to context AddFAQuestion(faq1); AddFAQuestion(faq2); AddFAQuestion(faq3); // Make Tutors Tutor t1 = new Tutor { UserName = "******", Password = "******", Title = "Moderator", Expertise = { "C#", "Python" } }; AddTutor(t1); }