using System;
using System.Web.UI;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using CMS.Messaging;
using CMS.UIControls;
public partial class CMSModules_Messaging_Controls_MessageUserButtons : CMSUserControl
{
#region "Private variables"
private string mInformationText = string.Empty;
private string mErrorText = string.Empty;
private bool mDisplayInline = false;
#endregion
#region "Public properties"
///
/// Related user.
///
public int RelatedUserId
{
get
{
return ValidationHelper.GetInteger(ViewState["RelatedUserId"], 0);
}
set
{
ViewState["RelatedUserId"] = value;
}
}
///
/// Information text.
///
public string InformationText
{
get
{
return mInformationText;
}
set
{
mInformationText = value;
}
}
///
/// Error text.
///
public string ErrorText
{
get
{
return mErrorText;
}
set
{
mErrorText = value;
}
}
///
/// Indicates if the control should be rendered as inline.
///
public bool DisplayInline
{
get
{
return mDisplayInline;
}
set
{
mDisplayInline = value;
}
}
#endregion
#region "Page events"
///
/// Page load.
///
/// Sender
/// Event arguments
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (!StopProcessing)
{
if (DisplayInline)
{
pnlButtons.Attributes.Add("style", "display: inline;");
}
ReloadData();
}
}
#endregion
#region "Methods"
///
/// Reload data.
///
public void ReloadData()
{
if (RelatedUserId > 0)
{
btnAddToIgnoreList.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("Messsaging.AddToIgnoreListConfirmation")) + ");";
btnAddToContactList.ToolTip = GetString("Messsaging.AddToContactList");
btnAddToIgnoreList.ToolTip = GetString("Messsaging.AddToIgnoreList");
imgAddToContactList.AlternateText = GetString("Messsaging.AddToContactList");
imgAddToIgnoreList.AlternateText = GetString("Messsaging.AddToIgnoreList");
imgAddToContactList.ImageUrl = GetImageUrl("/CMSModules/CMS_Messaging/addtocontactlist.png");
imgAddToIgnoreList.ImageUrl = GetImageUrl("/CMSModules/CMS_Messaging/addtoignorelist.png");
pnlButtons.Visible = true;
btnAddToContactList.Visible = true;
btnAddToIgnoreList.Visible = true;
// Hide btnAddToContactList if sender is already in contact list
if (ContactListInfoProvider.IsInContactList(CMSContext.CurrentUser.UserID, RelatedUserId))
{
btnAddToContactList.Visible = false;
}
// Hide btnAddToIgnoreList if sender is already in ignore list
if (IgnoreListInfoProvider.IsInIgnoreList(CMSContext.CurrentUser.UserID, RelatedUserId))
{
btnAddToIgnoreList.Visible = false;
}
}
else
{
pnlButtons.Visible = false;
}
}
#endregion
#region "Button handling"
protected void btnAddToIgnoreList_Click(object sender, EventArgs e)
{
try
{
// Current user ID
int currentUserId = CMSContext.CurrentUser.UserID;
// Add user to ignore list
IgnoreListInfoProvider.AddToIgnoreList(currentUserId, RelatedUserId);
InformationText = GetString("MessageUserButtons.IgnoreAdded");
}
catch (Exception ex)
{
ErrorText = ex.Message;
}
}
protected void btnAddToContactList_Click(object sender, EventArgs e)
{
try
{
// Current user ID
int currentUserId = CMSContext.CurrentUser.UserID;
// Add user to contact list
ContactListInfoProvider.AddToContactList(currentUserId, RelatedUserId);
InformationText = GetString("MessageUserButtons.ContactAdded");
}
catch (Exception ex)
{
ErrorText = ex.Message;
}
}
#endregion
}