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); } }
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; } }