PageRenderTime 5300ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/src/BugNET_WAP/Account/UserProfile.aspx.cs

#
C# | 246 lines | 163 code | 44 blank | 39 comment | 26 complexity | 6be8fdc813922f918378513d56dd4c7b MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI.WebControls;
  7. using BugNET.BLL;
  8. using BugNET.Common;
  9. using BugNET.Entities;
  10. using BugNET.UserInterfaceLayer;
  11. using log4net;
  12. namespace BugNET.Account
  13. {
  14. /// <summary>
  15. ///
  16. /// </summary>
  17. public partial class UserProfile : BasePage
  18. {
  19. private static readonly ILog Log = LogManager.GetLogger(typeof(UserProfile));
  20. /// <summary>
  21. /// Handles the Load event of the Page control.
  22. /// </summary>
  23. /// <param name="sender">The source of the event.</param>
  24. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  25. protected void Page_Load(object sender, EventArgs e)
  26. {
  27. if (Page.IsPostBack) return;
  28. litUserProfile.Text = Page.Title;
  29. foreach (ListItem li in BulletedList4.Items)
  30. li.Attributes.Add("class", "");
  31. BulletedList4.Items[0].Attributes.Add("class", "active");
  32. var resources = ResourceManager.GetInstalledLanguageResources();
  33. var resourceItems = (from code in resources let cultureInfo = new CultureInfo(code, false) select new ListItem(cultureInfo.DisplayName, code)).ToList();
  34. ddlPreferredLocale.DataSource = resourceItems;
  35. ddlPreferredLocale.DataBind();
  36. var membershipUser = UserManager.GetUser(User.Identity.Name);
  37. litUserName.Text = User.Identity.Name;
  38. FirstName.Text = WebProfile.Current.FirstName;
  39. LastName.Text = WebProfile.Current.LastName;
  40. FullName.Text = WebProfile.Current.DisplayName;
  41. ddlPreferredLocale.SelectedValue = WebProfile.Current.PreferredLocale;
  42. IssueListItems.SelectedValue = UserManager.GetProfilePageSize().ToString();
  43. AllowNotifications.Checked = WebProfile.Current.ReceiveEmailNotifications;
  44. if (membershipUser == null) return;
  45. UserName.Text = membershipUser.UserName;
  46. Email.Text = membershipUser.Email;
  47. var isFromOpenIdRegistration = Request.Get("oid", false);
  48. if(isFromOpenIdRegistration)
  49. {
  50. Message1.ShowInfoMessage(GetLocalResourceObject("UpdateProfileForOpenId").ToString());
  51. }
  52. }
  53. /// <summary>
  54. /// Adds the user.
  55. /// </summary>
  56. /// <param name="s">The s.</param>
  57. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  58. protected void AddProjectNotification(Object s, EventArgs e)
  59. {
  60. //The users must be added to a list first because the collection can not
  61. //be modified while we iterate through it.
  62. var usersToAdd = lstAllProjects.Items.Cast<ListItem>().Where(item => item.Selected).ToList();
  63. foreach (var item in usersToAdd)
  64. {
  65. var notification = new ProjectNotification
  66. {
  67. ProjectId = Convert.ToInt32(item.Value),
  68. NotificationUsername = Security.GetUserName()
  69. };
  70. if (!ProjectNotificationManager.SaveOrUpdate(notification)) continue;
  71. lstSelectedProjects.Items.Add(item);
  72. lstAllProjects.Items.Remove(item);
  73. }
  74. lstSelectedProjects.SelectedIndex = -1;
  75. }
  76. /// <summary>
  77. /// Removes the user.
  78. /// </summary>
  79. /// <param name="s">The s.</param>
  80. /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
  81. protected void RemoveProjectNotification(Object s, EventArgs e)
  82. {
  83. //The users must be added to a list first because the collection can not
  84. //be modified while we iterate through it.
  85. var usersToRemove = lstSelectedProjects.Items.Cast<ListItem>().Where(item => item.Selected).ToList();
  86. foreach (var item in usersToRemove)
  87. {
  88. if (!ProjectNotificationManager.Delete(Convert.ToInt32(item.Value), Security.GetUserName())) continue;
  89. lstAllProjects.Items.Add(item);
  90. lstSelectedProjects.Items.Remove(item);
  91. }
  92. lstAllProjects.SelectedIndex = -1;
  93. }
  94. protected void BulletedList4_Click1(object sender, BulletedListEventArgs e)
  95. {
  96. //Label1.Text = "The Index of Item you clicked: " + e.Index + "<br> The value of Item you clicked: " + BulletedList4.Items[e.Index].Text;
  97. foreach (ListItem li in BulletedList4.Items)
  98. li.Attributes.Add("class", "");
  99. BulletedList4.Items[e.Index].Attributes.Add("class", "active");
  100. ProfileView.ActiveViewIndex = e.Index;
  101. var userName = Security.GetUserName();
  102. switch (ProfileView.ActiveViewIndex)
  103. {
  104. case 2:
  105. lstAllProjects.Items.Clear();
  106. lstSelectedProjects.Items.Clear();
  107. lstAllProjects.DataSource = ProjectManager.GetByMemberUserName(userName);
  108. lstAllProjects.DataTextField = "Name";
  109. lstAllProjects.DataValueField = "Id";
  110. lstAllProjects.DataBind();
  111. // Copy selected users into Selected Users List Box
  112. var projectNotifications = ProjectNotificationManager.GetByUsername(userName);
  113. foreach (var currentNotification in projectNotifications)
  114. {
  115. var matchItem = lstAllProjects.Items.FindByValue(currentNotification.ProjectId.ToString());
  116. if (matchItem == null) continue;
  117. lstSelectedProjects.Items.Add(matchItem);
  118. lstAllProjects.Items.Remove(matchItem);
  119. }
  120. break;
  121. }
  122. }
  123. /// <summary>
  124. /// Handles the Click event of the SaveButton control.
  125. /// </summary>
  126. /// <param name="s">The source of the event.</param>
  127. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  128. protected void SaveButton_Click(object s, EventArgs e)
  129. {
  130. var membershipUser = UserManager.GetUser(User.Identity.Name);
  131. membershipUser.Email = Email.Text;
  132. WebProfile.Current.FirstName = FirstName.Text;
  133. WebProfile.Current.LastName = LastName.Text;
  134. WebProfile.Current.DisplayName = FullName.Text;
  135. try
  136. {
  137. WebProfile.Current.Save();
  138. Membership.UpdateUser(membershipUser);
  139. Message1.ShowSuccessMessage(GetLocalResourceObject("ProfileSaved").ToString());
  140. if (Log.IsInfoEnabled)
  141. {
  142. if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
  143. MDC.Set("user", HttpContext.Current.User.Identity.Name);
  144. Log.Info("Profile updated");
  145. }
  146. }
  147. catch (Exception ex)
  148. {
  149. if (Log.IsErrorEnabled)
  150. {
  151. if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
  152. MDC.Set("user", HttpContext.Current.User.Identity.Name);
  153. Log.Error("Profile update error", ex);
  154. }
  155. Message1.ShowErrorMessage(GetLocalResourceObject("ProfileUpdateError").ToString());
  156. }
  157. }
  158. /// <summary>
  159. /// Handles the Click event of the BackButton control.
  160. /// </summary>
  161. /// <param name="s">The source of the event.</param>
  162. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  163. protected void BackButton_Click(object s, EventArgs e)
  164. {
  165. var url = Request.Get("referrerurl", string.Empty);
  166. if (!string.IsNullOrEmpty(url))
  167. Response.Redirect(url);
  168. }
  169. /// <summary>
  170. /// Handles the Click event of the SaveCustomizeSettings control.
  171. /// </summary>
  172. /// <param name="sender">The source of the event.</param>
  173. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  174. protected void SaveCustomSettings_Click(object sender, EventArgs e)
  175. {
  176. WebProfile.Current.IssuesPageSize = Convert.ToInt32(IssueListItems.SelectedValue);
  177. WebProfile.Current.PreferredLocale = ddlPreferredLocale.SelectedValue;
  178. WebProfile.Current.ReceiveEmailNotifications = AllowNotifications.Checked;
  179. try
  180. {
  181. WebProfile.Current.Save();
  182. Message3.ShowSuccessMessage(GetLocalResourceObject("CustomSettingsSaved").ToString());
  183. if (Log.IsInfoEnabled)
  184. {
  185. if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
  186. MDC.Set("user", HttpContext.Current.User.Identity.Name);
  187. Log.Info("Profile updated");
  188. }
  189. }
  190. catch (Exception ex)
  191. {
  192. if (Log.IsErrorEnabled)
  193. {
  194. if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
  195. MDC.Set("user", HttpContext.Current.User.Identity.Name);
  196. Log.Error("Profile update error", ex);
  197. }
  198. Message3.ShowErrorMessage(GetLocalResourceObject("CustomSettingsUpdateError").ToString());
  199. }
  200. }
  201. }
  202. }