/2003/src/Controls/EditForum.cs

# · C# · 112 lines · 91 code · 16 blank · 5 comment · 4 complexity · ac853457661be66c0bd7a330bc5762a0 MD5 · raw file

  1. using System;
  2. using System.Web;
  3. using System.Web.UI.WebControls;
  4. using BilSimser.SharePoint.WebParts.Forums.Controls.Base;
  5. using BilSimser.SharePoint.WebParts.Forums.Controls.Common;
  6. using BilSimser.SharePoint.WebParts.Forums.Core.Domain.Entities;
  7. using BilSimser.SharePoint.WebParts.Forums.Core.Service.Application;
  8. namespace BilSimser.SharePoint.WebParts.Forums.Controls
  9. {
  10. public class EditForum : AdminBaseControl
  11. {
  12. private int id;
  13. private TextBox txtName;
  14. private DropDownList ddlCategories;
  15. private TextBox txtDescription;
  16. private SPButton btnSubmit;
  17. private SPButton btnCancel;
  18. private Forum forum;
  19. public EditForum()
  20. {
  21. ParentLink = ForumApplication.Instance.GetLink(SharePointForumControls.ManageForums);
  22. }
  23. protected override void CreateAdminChildControls()
  24. {
  25. CreateControls();
  26. LoadControlValues();
  27. BuildUI();
  28. }
  29. private void BuildUI()
  30. {
  31. AddBoxHeader(String.Format("Editing Forum \"{0}\"", forum.Name), false, 2);
  32. Controls.Add(CreateRow(txtName, "Forum Name"));
  33. Controls.Add(CreateRow(ddlCategories, "Category"));
  34. Controls.Add(CreateRow(txtDescription, "Description"));
  35. Controls.Add(CreateButtonRow(btnSubmit, btnCancel));
  36. CloseBox();
  37. }
  38. private void LoadControlValues()
  39. {
  40. id = ValidInt(HttpContext.Current.Request.QueryString["forum"]);
  41. if (id == 0)
  42. forum = new Forum(1, "New Forum");
  43. else
  44. forum = RepositoryRegistry.ForumRepository.GetById(id);
  45. txtName.Text = forum.Name;
  46. ddlCategories.SelectedIndex = forum.CategoryId - 1;
  47. txtDescription.Text = forum.Description;
  48. }
  49. private void CreateControls()
  50. {
  51. txtName = new TextBox();
  52. ddlCategories = new DropDownList();
  53. ddlCategories.DataTextField = "Name";
  54. ddlCategories.DataValueField = "Id";
  55. ddlCategories.DataSource = RepositoryRegistry.CategoryRepository.GetAll();
  56. ddlCategories.DataBind();
  57. txtDescription = new TextBox();
  58. txtDescription.TextMode = TextBoxMode.MultiLine;
  59. txtDescription.Rows = 10;
  60. txtDescription.Columns = 30;
  61. btnSubmit = new SPButton("Submit");
  62. btnSubmit.Click += new EventHandler(btnSubmit_Click);
  63. btnCancel = new SPButton("Cancel");
  64. btnCancel.Click += new EventHandler(btnCancel_Click);
  65. }
  66. private void btnCancel_Click(object sender, EventArgs e)
  67. {
  68. RedirectToParent();
  69. }
  70. private void btnSubmit_Click(object sender, EventArgs e)
  71. {
  72. int tempId = SaveControlValues();
  73. // id = ValidInt(HttpContext.Current.Request.QueryString["forum"]);
  74. // if(id == 0)
  75. // {
  76. ParentLink = ForumApplication.Instance.GetLink(SharePointForumControls.ManageForumPermissions, "forum={0}", tempId);
  77. // }
  78. // else
  79. {
  80. RedirectToParent();
  81. }
  82. }
  83. private int SaveControlValues()
  84. {
  85. id = ValidInt(HttpContext.Current.Request.QueryString["forum"]);
  86. if (id == 0)
  87. forum = new Forum(1, "");
  88. else
  89. forum = RepositoryRegistry.ForumRepository.GetById(id);
  90. forum.Name = txtName.Text;
  91. forum.CategoryId = ddlCategories.SelectedIndex + 1;
  92. forum.Description = txtDescription.Text;
  93. return RepositoryRegistry.ForumRepository.Save(forum);
  94. }
  95. }
  96. }