public SubForum(string subForumTitle, Forum parentForun, ForumGeneratorContext db) { this.subForumTitle = subForumTitle; this.moderators = new List<Moderator>(); this.parentForum = parentForun; Moderator m = new Moderator(parentForum.admin, ForumGenerator_Version2_Server.Users.Moderator.modLevel.ALL); this.moderators.Add(m); db.Moderators.Add(m); db.SaveChanges(); this.discussions = new List<Discussion>(); this.vocabulary = new HashSet<Word>(); }
public Forum(string forumName, string adminUserName, string adminPassword, ForumGeneratorContext db, RegPolicy registrationPolicy) { // TODO: Complete member initialization this.forumName = forumName; this.members = new List<User>(); this.admin = new User(adminUserName, adminPassword, "", "", this); this.admin.isConfirmed = true; db.Users.Add(this.admin); db.SaveChanges(); this.members.Add(this.admin); this.subForums = new List<SubForum>(); this.registrationPolicy = registrationPolicy; }
public Boolean addModerator(string modUserName, ForumGeneratorContext db, ForumGenerator_Version2_Server.Users.Moderator.modLevel level) { // check if user is registered to the forum Moderator newModerator = new Moderator(parentForum.getUser(modUserName), level); if (moderatorExists(modUserName)) throw new UnauthorizedOperationException(ForumGeneratorDefs.EXIST_MODERATOR); if (!newModerator.user.isConfirmed) throw new UnauthorizedOperationException(ForumGeneratorDefs.INACTIVE_USR); else { // OK, moderator is not exist this.moderators.Add(newModerator); db.Moderators.Add(newModerator); db.SaveChanges(); return true; } }
internal Boolean removeModerator(string modUserName, ForumGeneratorContext db) { if (parentForum.admin.userName == modUserName) // not allowed { throw new UnauthorizedOperationException(ForumGeneratorDefs.F_ADMIN_S_MOD); } Moderator moderator = this.moderators.Find(delegate(Moderator mod) { return mod.user.userName == modUserName; }); bool ans = moderators.Remove(moderator); //lock (db) //{ db.Moderators.Remove(moderator); db.SaveChanges(); // } return ans; }
internal Discussion removeDiscussion(int discussionId, ForumGeneratorContext db) { Discussion d = this.getDiscussion(discussionId); lock (db) { this.discussions.Remove(d); db.Discussions.Remove(d); db.SaveChanges(); } return d; }
internal Discussion createNewDiscussion(string title, string content, User user, ForumGeneratorContext db, HashSet<string> stopWords) { List<string> keyWords = parseKeyWords(content, stopWords); if (keyWords != null && keyWords.Count > 0) { if (isClassifies()) { checkRelevantContent(keyWords); } else this.vocabulary = TextClassifier.addToVocabulary(keyWords, this.vocabulary); } Discussion newDiscussion = new Discussion(title, content, user, this); this.discussions.Add(newDiscussion); db.Discussions.Add(newDiscussion); db.SaveChanges(); return newDiscussion; }
internal bool changeModLevel(int forumId, int subForumId, string moderatorName, Moderator.modLevel newLevel, ForumGeneratorContext db) { Moderator moderator = this.getModerator(moderatorName); moderator.level = newLevel; db.Entry(db.Moderators.Find(moderator.moderatorId)).CurrentValues.SetValues(moderator); db.SaveChanges(); return true; }
internal Comment createNewComment(string content, User user, ForumGeneratorContext db) { content = content.Replace("/","//"); Comment newComment = new Comment(content, user, this); //lock (db) //{ this.comments.Add(newComment); db.Comments.Add(newComment); db.SaveChanges(); //} return newComment; }
internal Discussion editDiscussion(string newContent, ForumGeneratorContext db) { this.content = newContent; //lock (db) //{ db.Entry(db.Discussions.Find(this.discussionId)).CurrentValues.SetValues(this); db.SaveChanges(); //} return this; }
internal User register(string userName, string password, string email, string signature, ForumGeneratorContext db) { // Check if userName is already exist if (userExists(userName)) throw new UnauthorizedAccessException(ForumGeneratorDefs.EXIST_USERNAME); else { // userName does not exist - create new User //lock (db) //{ User newUser = new User(userName, password, email, signature, this); // RegistrationPolicy handling switch (this.registrationPolicy) { case RegPolicy.NONE: newUser.isConfirmed = true; break; case RegPolicy.ADMIN_CONFIRMATION: newUser.isConfirmed = false; break; case RegPolicy.MAIL_ACTIVATION: var fromAddress = new MailAddress("*****@*****.**", "Nimbus - Forum Generator"); var toAddress = new MailAddress(email, userName); const string fromPassword = "******"; string subject = "Nimbus - Registration Confirmation Mail"; StringBuilder sb = new StringBuilder(); sb.AppendLine("<HTML>Hey,"); sb.AppendLine("We've just got your registration. Please use <a href=\"http://localhost:56068/confirmation?forumId=" + forumId + "&userName="******"\">this link</a> to confirm your registration."); sb.AppendLine("Thanks,"); sb.AppendLine("Nimbus Forum Generator</HTML>"); string body = sb.ToString(); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } break; } this.members.Add(newUser); db.Users.Add(newUser); db.SaveChanges(); return newUser; // } } }
internal User logout(string userName, string password, ForumGeneratorContext db) { lock (db) { User user = getUser(userName).logout(password); db.Entry(db.Users.Find(user.memberID)).CurrentValues.SetValues(user); db.SaveChanges(); return user; } }
internal SubForum createNewSubForum(string subForumTitle, ForumGeneratorContext db) { if (this.subForums.Find(delegate(SubForum subfrm) { return subfrm.subForumTitle == subForumTitle; }) != null) throw new UnauthorizedOperationException(ForumGeneratorDefs.EXIST_TITLE); SubForum newSubForum = new SubForum(subForumTitle, this, db); //lock (db) //{ this.subForums.Add(newSubForum); db.SubForums.Add(newSubForum); db.SaveChanges(); //} return newSubForum; }
internal User changeAdmin(int newAdminUserId, ForumGeneratorContext db) { User currentMember = getUser(newAdminUserId); this.admin = currentMember; lock (db) { db.Entry(db.Forums.Find(this.forumId)).CurrentValues.SetValues(this); db.SaveChanges(); } return this.admin; }