protected void commentAddButton_Click(object sender, EventArgs e) { if (commentAddTextBox.Text.Length == 0) { commentAddLabel.Text = "Please enter a comment"; commentAddLabel.Visible = true; return; } if (itemsGridView.SelectedRow == null) { throw new InvalidFormDataException("Comment can only be added to a selected item"); } MPRSession session = MPRController.StartSession(); MPItem item = MPRController.RetrieveById <MPItem>(session, (Int64)itemsGridView.SelectedValue); if (item == null) { throw new InvalidFormDataException("Asked to provide details for invalid item id"); } MPItemComment comment = new MPItemComment(); comment.User = SessionUtils.GetCurrentUser(); comment.Text = commentAddTextBox.Text; item.Comments.Add(comment); MPRController.Save <MPItem>(session, item); MPRController.EndSession(session, true); commentAddTextBox.Text = ""; commentAddLabel.Text = "Comment added. Thank you!"; commentAddLabel.Visible = true; }
protected void commentAddButton_Click(object sender, EventArgs e) { if (commentAddTextBox.Text.Length == 0) { commentAddLabel.Text = "Please enter a comment"; commentAddLabel.Visible = true; return; } if (itemsGridView.SelectedRow == null) { throw new InvalidFormDataException("Comment can only be added to a selected item"); } MPRSession session = MPRController.StartSession(); MPItem item = MPRController.RetrieveById<MPItem>(session, (Int64)itemsGridView.SelectedValue); if (item == null) { throw new InvalidFormDataException("Asked to provide details for invalid item id"); } MPItemComment comment = new MPItemComment(); comment.User = SessionUtils.GetCurrentUser(); comment.Text = commentAddTextBox.Text; item.Comments.Add(comment); MPRController.Save<MPItem>(session, item); MPRController.EndSession(session, true); commentAddTextBox.Text = ""; commentAddLabel.Text = "Comment added. Thank you!"; commentAddLabel.Visible = true; }