Example #1
0
 public AddPost(Post PostToAdd, string name)
 {
     TempPost = PostToAdd;
     InitializeComponent();
     this.Title = "Send Message To " + name;
     PostTextBox.Focus();
 }
Example #2
0
 public EditPost(Post PostToEdit)
 {
     TempPost = PostToEdit;
     InitializeComponent();
     PostTextBox.Focus();
     PostTextBox.Text = PostToEdit.Text;
 }
 private void RoleBanCheckBox_Click(object sender, RoutedEventArgs e)
 {
     if (RoleAdminCheckBox.IsChecked == true)
     {
         RoleBannedCheckBox.IsChecked = false;
         MessageBox.Show("Admin can't be banned!");
         return;
     }
     else if (RoleModerCheckBox.IsChecked == true)
     {
         RoleBannedCheckBox.IsChecked = false;
         MessageBox.Show("Moderator can't be banned!");
         return;
     }
     if (RoleBannedCheckBox.IsChecked == false)
     {
         var userinrole = from q in forumEntities.UsersInRoles
                          where q.UserId == curUser.UserId && q.RoleId == RoleBannedID
                          select q;
         UsersInRoles UserInRoleDel = userinrole.First();
         forumEntities.DeleteObject(UserInRoleDel);
         curUser.IsLocked = false;
         curUser.LockedDateOut = DateTime.Now;
     }
     else
     {
         //BAN info
         BanParameters BanPar = new BanParameters(curUser);
         BanPar.ShowDialog();
         if (curUser.LockedDateOut.Date <= DateTime.Now.Date)
         {
             RoleBannedCheckBox.IsChecked = false;
             return;
         }
         //ban
         {
             UsersInRoles UserInRoleAdd = new UsersInRoles();
             UserInRoleAdd = new UsersInRoles();
             UserInRoleAdd.RoleId = RoleBannedID;
             UserInRoleAdd.UserId = curUser.UserId;
             forumEntities.UsersInRoles.AddObject(UserInRoleAdd);
             curUser.IsLocked = true;
             //
             Post postBan = new Post();
             postBan.DateAdded = DateTime.Now;
             postBan.ForumID = (from q in forumEntities.Forum
                                    where q.ForumName == "usersprivateforum"
                                    select q).First().ForumID;
             postBan.TopicID = (from q in forumEntities.Topic
                                where q.TopicName == curUser.UserLoweredName + "privatetopicin"
                                select q).First().TopicID;
             postBan.Text = "You are banned!\nDate: " + curUser.LockedDateOut.ToString() + "\nReason: " + curUser.LockedReason;
             postBan.UserId = LoginedUser.UserId;
             forumEntities.AddToPost(postBan);
         }
     }
     forumEntities.SaveChanges();
     FillProfile();
 }
 private void SendMesButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Post PostToAdd1 = new Post();
         Post PostToAdd2 = new Post();
         AddPost Mes = new AddPost(PostToAdd1, curUser.UserName);
         Mes.ShowDialog();
         if (PostToAdd1.Text == null)
             throw new Exception("none");
         if (PostToAdd1.Text == "")
             throw new Exception("You should write smth!");
         //message in OUT
         var privTopicOUT = from q in forumEntities.Topic
                            where q.TopicName == LoginedUser.UserLoweredName + "privatetopicout"
                            select q;
         PostToAdd1.DateAdded = DateTime.Now;
         PostToAdd1.ForumID = privTopicOUT.First().ForumID;
         PostToAdd1.TopicID = privTopicOUT.First().TopicID;
         PostToAdd1.UserId = curUser.UserId;
         DB.IncreasePostCount(PostToAdd1.TopicID);
         forumEntities.Post.AddObject(PostToAdd1);
         forumEntities.SaveChanges();
         //message in IN
         var privTopicIN = from q in forumEntities.Topic
                            where q.TopicName == curUser.UserLoweredName + "privatetopicin"
                            select q;
         PostToAdd2.Text = PostToAdd1.Text;
         PostToAdd2.ForumID = PostToAdd1.ForumID;
         PostToAdd2.DateAdded = PostToAdd1.DateAdded;
         PostToAdd2.UserId = LoginedUser.UserId;
         PostToAdd2.TopicID = privTopicIN.First().TopicID;
         DB.IncreasePostCount(PostToAdd2.TopicID);
         forumEntities.Post.AddObject(PostToAdd2);
         forumEntities.SaveChanges();
     }
     catch (Exception excpt)
     {
         if (excpt.Message != "none")
             MessageBox.Show(excpt.Message);
     }
 }
Example #5
0
 private void SentDataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Delete)
     {
         PostExt PostExtToDel = (SentDataGrid.SelectedValue as PostExt);
         Post PostToDel = new Post();
         PostToDel.DateAdded = PostExtToDel.DateAdded;
         PostToDel.PostID = PostExtToDel.PostID;
         PostToDel.Text = PostExtToDel.Text;
         PostToDel.ForumID = PostExtToDel.ForumID;
         PostToDel.TopicID = PostExtToDel.TopicID;
         PostToDel.UserId = PostExtToDel.UserId;
         DB.DecreasePostCount(PostToDel.TopicID);
         var postdel = from q in forumEntities.Post
                       where q.PostID == PostToDel.PostID
                       select q;
         forumEntities.DeleteObject(postdel.First());
     }
 }
Example #6
0
 private void EditPostButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (PostsDataGrid.SelectedIndex == -1)
             throw new Exception("Select any post.");
         int selPostID = (PostsDataGrid.SelectedValue as Post).PostID;
         Post PostToEdit = new Post();
         PostToEdit.Text = (PostsDataGrid.SelectedValue as Post).Text;
         EditPost editPost = new EditPost(PostToEdit);
         editPost.ShowDialog();
         if (PostToEdit.Text == null || PostToEdit.Text == "")
             throw new Exception("You should write smth!");
         (from q in forumEntities.Post
          where q.PostID == selPostID
          select q).First().Text = PostToEdit.Text;
         forumEntities.SaveChanges();
         FillShowPostTab(curTopicID);
     }
     catch (Exception excpt)
     {
         MessageBox.Show(excpt.Message);
     }
 }
Example #7
0
 private void AddPostButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         PostsDataGrid.ItemsSource = null;
         this.IsEnabled = false;
         Post PostToAdd = new Post();
         AddPost addPost = new AddPost(PostToAdd);
         addPost.ShowDialog();
         if (PostToAdd.Text == null)
             throw new Exception("none");
         if (PostToAdd.Text == "")
             throw new Exception("You should write smth!");
         PostToAdd.DateAdded = DateTime.Now;
         PostToAdd.ForumID = curForumID;
         PostToAdd.TopicID = curTopicID;
         PostToAdd.UserId = UserLogined.UserId;
         forumEntities.Post.AddObject(PostToAdd);
         DB.IncreasePostCount(curTopicID);
         //set last postID
         Forum f = (from q in forumEntities.Forum
                    where q.ForumID == PostToAdd.ForumID
                    select q).First();
         f.LastPostID = PostToAdd.PostID;
         Topic t = (from q in forumEntities.Topic
                    where q.TopicID == PostToAdd.TopicID
                    select q).First();
         t.LastPostID = PostToAdd.PostID;
         forumEntities.SaveChanges();
     }
     catch (Exception excpt)
     {
         if (excpt.Message != "none")
             MessageBox.Show(excpt.Message);
     }
     finally
     {
         FillShowPostTab(curTopicID);
         this.IsEnabled = true;
     }
 }
Example #8
0
 private void PostsDataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Delete)
     {
         PostExt PostExtToDel = (PostsDataGrid.SelectedValue as PostExt);
         Post PostToDel = new Post();
         PostToDel.DateAdded = PostExtToDel.DateAdded;
         PostToDel.PostID = PostExtToDel.PostID;
         PostToDel.Text = PostExtToDel.Text;
         PostToDel.ForumID = PostExtToDel.ForumID;
         PostToDel.TopicID = PostExtToDel.TopicID;
         PostToDel.UserId = PostExtToDel.UserId;
         DB.DecreasePostCount(PostToDel.TopicID);
         var postdel = from q in forumEntities.Post
                        where q.PostID == PostToDel.PostID
                        select q;
         forumEntities.DeleteObject(postdel.First());
         //last post id?
         Forum f = (from q in forumEntities.Forum
                    where q.ForumID == PostToDel.ForumID
                    select q).First();
         var p = from q in forumEntities.Post
                  where q.ForumID == PostToDel.ForumID
                  orderby q.DateAdded descending
                  select q.PostID;
         if (p.Count() == 0)
         {
             f.LastPostID = null;
         }
         else
         {
             f.LastPostID = p.First();
         }
         Topic t = (from q in forumEntities.Topic
                    where q.TopicID == PostToDel.TopicID
                    select q).First();
         p = from q in forumEntities.Post
                 where q.TopicID == PostToDel.TopicID
                 orderby q.DateAdded descending
                 select q.PostID;
         if (p.Count() == 0)
         {
             t.LastPostID = null;
         }
         else
         {
             t.LastPostID = p.First();
         }
     }
 }
Example #9
0
 public AddPost(Post PostToAdd)
 {
     TempPost = PostToAdd;
     InitializeComponent();
     PostTextBox.Focus();
 }
Example #10
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Post EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPost(Post post)
 {
     base.AddObject("Post", post);
 }
Example #11
0
 /// <summary>
 /// Create a new Post object.
 /// </summary>
 /// <param name="postID">Initial value of the PostID property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="topicID">Initial value of the TopicID property.</param>
 /// <param name="forumID">Initial value of the ForumID property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="dateAdded">Initial value of the DateAdded property.</param>
 public static Post CreatePost(global::System.Int32 postID, global::System.String text, global::System.Int32 topicID, global::System.Int32 forumID, global::System.Guid userId, global::System.DateTime dateAdded)
 {
     Post post = new Post();
     post.PostID = postID;
     post.Text = text;
     post.TopicID = topicID;
     post.ForumID = forumID;
     post.UserId = userId;
     post.DateAdded = dateAdded;
     return post;
 }