Web and Desktop - comment threads
This commit is contained in:
@@ -16,17 +16,18 @@ namespace WinForms
|
||||
{
|
||||
Announcement announcement;
|
||||
User currentUser;
|
||||
public AnnouncementForm(Announcement? announcement, bool readOnly, User? currentUser)
|
||||
public AnnouncementForm(Announcement? announcement, bool readOnly, User currentUser)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.announcement = announcement;
|
||||
this.currentUser = currentUser;
|
||||
|
||||
dtpPublishDate.Enabled = false;
|
||||
if (readOnly)
|
||||
{
|
||||
btnSave.Enabled = false;
|
||||
tbTitle.Enabled = false;
|
||||
tbDescription.Enabled = false;
|
||||
dtpPublishDate.Enabled = false;
|
||||
ckbImportant.Enabled = false;
|
||||
ckbSticky.Enabled = false;
|
||||
}
|
||||
@@ -38,12 +39,19 @@ namespace WinForms
|
||||
dtpPublishDate.Value = announcement.PublishDate;
|
||||
ckbImportant.Checked = announcement.IsImportant;
|
||||
ckbSticky.Checked = announcement.IsSticky;
|
||||
RefreshComments();
|
||||
}
|
||||
else
|
||||
{
|
||||
btnCreateComment.Enabled = false;
|
||||
btnDeleteComment.Enabled = false;
|
||||
btnEditComment.Enabled = false;
|
||||
btnViewComment.Enabled = false;
|
||||
}
|
||||
if (currentUser != null)
|
||||
{
|
||||
lblAuthor.Text = $"Created by: {currentUser.Name}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
@@ -61,9 +69,72 @@ namespace WinForms
|
||||
}
|
||||
else
|
||||
{
|
||||
announcementManager.UpdateAnnouncement(announcement.ID, tbTitle.Text, tbDescription.Text, currentUser, dtpPublishDate.Value, ckbImportant.Checked, ckbSticky.Checked);
|
||||
announcementManager.UpdateAnnouncement(announcement.ID, tbTitle.Text, tbDescription.Text, ckbImportant.Checked, ckbSticky.Checked);
|
||||
}
|
||||
this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void btnViewComment_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBox1.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Please select an item from the list");
|
||||
}
|
||||
else
|
||||
{
|
||||
CommentForm form = new CommentForm((Comment)listBox1.SelectedItem, true, currentUser);
|
||||
form.ShowDialog();
|
||||
RefreshComments();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEditComment_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBox1.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Please select an item from the list");
|
||||
}
|
||||
else
|
||||
{
|
||||
CommentForm form = new CommentForm((Comment)listBox1.SelectedItem, false, currentUser);
|
||||
form.ShowDialog();
|
||||
RefreshComments();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnDeleteComment_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBox1.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Please select an item from the list");
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment currentComment = (Comment)listBox1.SelectedItem;
|
||||
if (MessageBox.Show($"Are you sure you want to delete\n{currentComment.Title}\nCreated at {currentComment.PublishDate.ToString("g")} by {currentComment.Author.Name}",
|
||||
"Delete announcement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
CommentManager commentManager = new CommentManager();
|
||||
commentManager.DeleteCommentOnAnnouncement(currentComment.ID, announcement.ID);
|
||||
}
|
||||
RefreshComments();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnCreateComment_Click(object sender, EventArgs e)
|
||||
{
|
||||
CommentForm form = new CommentForm(null, false, currentUser, true, announcement.ID);
|
||||
form.ShowDialog();
|
||||
RefreshComments();
|
||||
}
|
||||
|
||||
private void RefreshComments()
|
||||
{
|
||||
listBox1.Items.Clear();
|
||||
foreach (var item in announcement.Comments)
|
||||
{
|
||||
listBox1.Items.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user