PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/WEB/c/user/customer/_ctrl/_cntUserEdit.ascx.cs

https://bitbucket.org/zzare/eko
C# | 256 lines | 128 code | 82 blank | 46 comment | 21 complexity | fbc0bbd751f53ee2163648c2a3030560 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13. using System.Collections.Generic;
  14. namespace SM.UI.Controls
  15. {
  16. public partial class _customer_cntUserEdit : BaseControl
  17. {
  18. public Guid PageID { get; set; }
  19. public event EventHandler OnUserChanged;
  20. public event EventHandler OnCancel;
  21. public Guid UID {
  22. get
  23. {
  24. Guid res = Guid.Empty;
  25. if (ViewState["UID"] == null) return res;
  26. if (!SM.EM.Helpers.IsGUID(ViewState["UID"].ToString())) return res;
  27. return new Guid(ViewState["UID"].ToString());
  28. }
  29. set{
  30. ViewState["UID"] = value;
  31. }
  32. }
  33. public Guid ProjectID { get; set; }
  34. public Guid SiteID { get; set; }
  35. public Guid GroupID { get; set; }
  36. protected void Page_Load(object sender, EventArgs e)
  37. {
  38. if (!IsPostBack)
  39. {
  40. }
  41. }
  42. // default values
  43. protected void LoadDefaultValues() {
  44. UID = Guid.Empty;
  45. // litCode.Text = "";
  46. ParentPage.mp.StatusText = "Add NEW USER";
  47. // btDeleteUser.Visible = false;
  48. }
  49. // bind data
  50. public void BindData() {
  51. this.Visible = true;
  52. if (UID == Guid.Empty)
  53. {
  54. LoadDefaultValues();
  55. }
  56. else {
  57. LoadData();
  58. }
  59. LoadRoles();
  60. }
  61. // LOAD Question
  62. protected void LoadData() {
  63. CustomerRep crep = new CustomerRep();
  64. CUSTOMER usr = crep.GetCustomerByID(UID);
  65. if (usr == null)
  66. return;
  67. if (usr.PageID != PageID)
  68. return;
  69. MembershipUser muser = Membership.GetUser(usr.USERNAME);
  70. tbUserName.Text = usr.USERNAME;
  71. tbEmail.Text = usr.USERNAME;
  72. tbName.Text = usr.FIRST_NAME;
  73. tbLastName.Text = usr.LAST_NAME;
  74. cbActive.Checked = muser.IsApproved ;
  75. // set status text
  76. string status = "";
  77. status = "Uporabnik: " + usr.USERNAME ;
  78. panEdit.Visible = true;
  79. // load bonus
  80. if (usr.CampaignID != null) {
  81. string type = "";
  82. string href = "";
  83. string name = "";
  84. // check if is a campaign
  85. MARKETING_CAMPAIGN c = MARKETING_CAMPAIGN.GetCampaignByID(usr.CampaignID.Value);
  86. if (c != null)
  87. {
  88. type = "kampanja: ";
  89. href = MARKETING_CAMPAIGN.Common.GetCampaignDetailsCMSHref(usr.CampaignID.Value);
  90. name = c.Name;
  91. }
  92. else {
  93. type = "user affilliate - bonus";
  94. href = EM_USER.Common.RenderCMSHref(usr.CampaignID.Value);
  95. }
  96. // litBonus.Text = string.Format("<a href=\"" + Page.ResolveUrl( href) +"\" >" + type + name +"</a>");
  97. }
  98. }
  99. protected void LoadRoles() {
  100. // load roles if admin
  101. //if (SM.BLL.BizObject.IsAdmin)
  102. //{
  103. //List<string> list = Roles.GetAllRoles().ToList();
  104. //if (list.Contains("admin"))
  105. // if (!Roles.IsUserInRole("admin"))
  106. // list.Remove("admin");
  107. //cblRoles.DataSource = list;
  108. // cblRoles.DataBind();
  109. // foreach (ListItem item in cblRoles.Items)
  110. // {
  111. // if (Roles.IsUserInRole(tbUserName.Text, item.Value))
  112. // item.Selected = true;
  113. // }
  114. }
  115. public void Save() {
  116. // validation
  117. Page.Validate("usredit");
  118. if (!Page.IsValid) return;
  119. eMenikDataContext db = new eMenikDataContext();
  120. CUSTOMER usr;
  121. // add new user
  122. if (UID == Guid.Empty)
  123. {
  124. return;
  125. }
  126. else
  127. {
  128. usr = db.CUSTOMERs.SingleOrDefault(w=>w.CustomerID == UID );
  129. }
  130. //usr.act = cbActive.Checked;
  131. //usr.EMAIL = tbEmail.Text;
  132. usr.FIRST_NAME = tbName.Text.Trim();
  133. usr.LAST_NAME = tbLastName.Text.Trim();
  134. int discount = 0;
  135. // save
  136. db.SubmitChanges();
  137. // set user active
  138. MembershipUser userM = Membership.GetUser(usr.USERNAME);
  139. userM.IsApproved = cbActive.Checked;
  140. userM.UnlockUser();
  141. Membership.UpdateUser(userM);
  142. // change password
  143. if (!String.IsNullOrEmpty(tbChangePassWord.Text.Trim()))
  144. userM.ChangePassword(userM.GetPassword(), tbChangePassWord.Text);
  145. //// save roles
  146. //foreach(ListItem item in cblRoles.Items ){
  147. // if (item.Selected) {
  148. // if (!Roles.IsUserInRole(tbUserName.Text, item.Value))
  149. // Roles.AddUserToRole(tbUserName.Text, item.Value);
  150. // }
  151. // else if (Roles.IsUserInRole(tbUserName.Text, item.Value))
  152. // Roles.RemoveUserFromRole(tbUserName.Text, item.Value);
  153. //}
  154. // set status text
  155. ParentPage.mp.StatusText = "User has been SAVED ";
  156. // remove from cache
  157. //usr.RemoveFromCache();
  158. // raise changed event
  159. OnUserChanged (this, new EventArgs());
  160. }
  161. // GROUP
  162. protected void btSave_Click(object sender, EventArgs e)
  163. {
  164. Save();
  165. }
  166. protected void btCancel_Click(object sender, EventArgs e)
  167. {
  168. //this.Visible = false;
  169. OnCancel(this, new EventArgs());
  170. // remove status text
  171. ParentPage.mp.StatusText = "";
  172. }
  173. }
  174. }