Esempio n. 1
0
        /// <summary>
        /// Handles Load event for a control.
        /// </summary>
        /// <param name="e">Event args.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try {
                var userId = GetUserId();
                SessionUserId = userId;

                if (!IsPostBack)
                {
                    // load the data into the control the first time we hit this page

                    // check we have an item to lookup
                    if (userId != null)
                    {
                        // load the item
                        var dataProvider = new UserHtmlDataProvider();
                        var item         = dataProvider.GetUserHtml(userId.Value, ModuleId);
                        if (item != null)
                        {
                            textUserHtml.Text = item.UserHtml;

                            // setup audit control
                            ctlAudit.CreatedByUser = UserController.Instance.GetUser(PortalId, item.CreatedByUserId)?.DisplayName
                                                     ?? LocalizeString("UnknownUser.Text");
                            ctlAudit.CreatedDate = item.CreatedOnDate.ToLongDateString();
                        }
                        else
                        {
                            LoadNewItem(userId.Value);
                        }

                        var user = UserController.Instance.GetUser(PortalId, userId.Value);
                        if (user != null)
                        {
                            AppendToPageTitle(user.DisplayName);
                        }
                        else
                        {
                            throw (new Exception($"User with UserId={userId.Value} doesn't exists."));
                        }
                    }
                    else
                    {
                        throw (new Exception("Expected \"user_id\" parameter in a querystring."));
                    }
                }
            }
            catch (Exception ex) {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
Esempio n. 2
0
        void ShowContent(int userId)
        {
            var user = userId != UserId?UserController.Instance.GetUser(PortalId, userId) : UserInfo;

            if (user.IsInAnyRole(Settings.RoleIds, true))
            {
                var dataProvider = new UserHtmlDataProvider();
                var userHtml     = dataProvider.GetUserHtml(userId, ModuleId);
                litUserHtml.Text = ProcessUserHtml(user,
                                                   (userHtml != null && !string.IsNullOrEmpty(userHtml.UserHtml))
                        ? userHtml.UserHtml
                        : Settings.EmptyHtml
                                                   );
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handles Click event for Update button
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='e'>
        /// Event args.
        /// </param>
        protected void buttonUpdate_Click(object sender, EventArgs e)
        {
            try {
                var userId = GetUserId();
                if (userId != null)
                {
                    var dataProvider = new UserHtmlDataProvider();
                    var item         = dataProvider.GetUserHtml(userId.Value, ModuleId);
                    var isNewItem    = (item == null);

                    // determine if we are adding or updating
                    // ALT: if (Null.IsNull (itemId))
                    if (isNewItem)
                    {
                        item = new UserHtmlInfo();
                    }

                    item.UserHtml = HtmlStripper.StripTags(textUserHtml.Text, true, Settings.StripTags, ",;");
                    item.ModuleId = ModuleId;
                    item.UserId   = userId.Value;

                    var now = DateTime.Now;
                    if (isNewItem)
                    {
                        item.CreatedByUserId = UserId;
                        item.CreatedOnDate   = now;
                    }
                    item.LastModifiedByUserId = UserId;
                    item.LastModifiedOnDate   = now;

                    if (isNewItem)
                    {
                        dataProvider.Add(item);
                        SessionUserId = item.UserId;
                    }
                    else
                    {
                        dataProvider.Update(item);
                    }

                    ModuleController.SynchronizeModule(ModuleId);
                    Response.Redirect(Globals.NavigateURL(), true);
                }
            }
            catch (Exception ex) {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Handles Click event for Delete button
 /// </summary>
 /// <param name='sender'>
 /// Sender.
 /// </param>
 /// <param name='e'>
 /// Event args.
 /// </param>
 protected void buttonDelete_Click(object sender, EventArgs e)
 {
     try {
         var userId = GetUserId();
         if (userId != null)
         {
             var dataProvider = new UserHtmlDataProvider();
             var item         = dataProvider.GetUserHtml(userId.Value, ModuleId);
             if (item != null)
             {
                 dataProvider.Delete(item);
                 Response.Redirect(Globals.NavigateURL(), true);
             }
         }
     }
     catch (Exception ex) {
         Exceptions.ProcessModuleLoadException(this, ex);
     }
 }