public EditTopic(Topic TopicToEdit) { TempTopic = TopicToEdit; InitializeComponent(); TopicTextBox.Focus(); TopicTextBox.Text = TopicToEdit.TopicName; }
public AddTopic( Topic TopicToAdd) { TempTopic = TopicToAdd; InitializeComponent(); TopicTextBox.Focus(); }
private void EditTopicButton_Click(object sender, RoutedEventArgs e) { try { if (TopicsDataGrid.SelectedIndex == -1) throw new Exception("Select any topic."); int selTopicID = (TopicsDataGrid.SelectedValue as Topic).TopicID; Topic TopicToEdit = new Topic(); TopicToEdit.TopicName = (TopicsDataGrid.SelectedValue as Topic).TopicName; EditTopic editTopic = new EditTopic(TopicToEdit); editTopic.ShowDialog(); if (TopicToEdit.TopicName == null || TopicToEdit.TopicName == "") throw new Exception("You should write smth!"); (from q in forumEntities.Topic where q.TopicID == selTopicID select q).First().TopicName = TopicToEdit.TopicName; forumEntities.SaveChanges(); FillShowTopicTab(curForumID); } catch (Exception excpt) { MessageBox.Show(excpt.Message); } }
private void AddTopicButton_Click(object sender, RoutedEventArgs e) { try { TopicsDataGrid.ItemsSource = null; this.IsEnabled = false; Topic TopicToAdd = new Topic(); AddTopic addTopic = new AddTopic(TopicToAdd); addTopic.ShowDialog(); if (TopicToAdd.TopicName == null) throw new Exception("none"); if (TopicToAdd.TopicName == "") throw new Exception("Write topic's name!"); TopicToAdd.CreateDate = DateTime.Now; TopicToAdd.PostsCount = 0; TopicToAdd.LastPostID = null; TopicToAdd.ForumID = curForumID; TopicToAdd.UserId = UserLogined.UserId; //check for uniq in cur forum var f = from q in forumEntities.Topic where (q.TopicName == TopicToAdd.TopicName && q.ForumID == TopicToAdd.ForumID) select q; if (f.Count() != 0) throw new Exception("Such Topic already exists!"); forumEntities.Topic.AddObject(TopicToAdd); DB.IncreaseTopicCount(curForumID); forumEntities.SaveChanges(); } catch (Exception excpt) { if (excpt.Message != "none") MessageBox.Show(excpt.Message); } finally { FillShowTopicTab(curForumID); this.IsEnabled = true; } }
private void TopicsDataGrid_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { TopicExt TopicExtToDel = (TopicsDataGrid.SelectedValue as TopicExt); Topic TopicToDel = new Topic(); TopicToDel.CreateDate = TopicExtToDel.CreateDate; TopicToDel.TopicID = TopicExtToDel.TopicID; TopicToDel.TopicName = TopicExtToDel.TopicName; TopicToDel.LastPostID = TopicExtToDel.LastPostID; TopicToDel.PostsCount = TopicExtToDel.PostsCount; TopicToDel.UserId = TopicExtToDel.UserId; TopicToDel.ForumID = TopicExtToDel.ForumID; //del connections in Users-Topic-LastActivity var lastAct = from qq in forumEntities.UserTopicLastActiv where qq.TopicId == TopicToDel.TopicID select qq; if (lastAct.Count() != 0) { foreach (UserTopicLastActiv UserTopPasAct in lastAct) { forumEntities.DeleteObject(UserTopPasAct); } } DB.DelPostsBelongToTopic(TopicToDel.TopicID, true); //call del posts DB.DecreaseTopicCount(TopicToDel.ForumID); var topicdel = from q in forumEntities.Topic where q.TopicID == TopicToDel.TopicID select q; forumEntities.DeleteObject(topicdel.First()); //last post id Forum f = (from q in forumEntities.Forum where q.ForumID == TopicToDel.ForumID select q).First(); var p = from q in forumEntities.Post where q.ForumID == TopicToDel.ForumID orderby q.DateAdded descending select q.PostID; if (p.Count() == 0) { f.LastPostID = null; } else { f.LastPostID = p.First(); } } }
/// <summary> /// Deprecated Method for adding a new object to the Topic EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTopic(Topic topic) { base.AddObject("Topic", topic); }
/// <summary> /// Create a new Topic object. /// </summary> /// <param name="topicID">Initial value of the TopicID property.</param> /// <param name="topicName">Initial value of the TopicName property.</param> /// <param name="forumID">Initial value of the ForumID property.</param> /// <param name="postsCount">Initial value of the PostsCount property.</param> /// <param name="createDate">Initial value of the CreateDate property.</param> /// <param name="userId">Initial value of the UserId property.</param> public static Topic CreateTopic(global::System.Int32 topicID, global::System.String topicName, global::System.Int32 forumID, global::System.Int32 postsCount, global::System.DateTime createDate, global::System.Guid userId) { Topic topic = new Topic(); topic.TopicID = topicID; topic.TopicName = topicName; topic.ForumID = forumID; topic.PostsCount = postsCount; topic.CreateDate = createDate; topic.UserId = userId; return topic; }