//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using CommunityServer.Components;
using CommunityServer.Controls;

namespace CommunityServer.ControlPanel.Blogs
{
	/// <summary>
	/// Summary description for DeleteTokenCommand.
	/// </summary>
	public class DeleteTokenCommand : BlogCommand
	{
		public DeleteTokenCommand()
		{
		}

		public override string Message(BlogCommandPage page)
		{

			TextToken token = GetToken();
			if(token == null)
			{
				Modal.ClosePage(page);
				return null;
			}

			return "Are you sure you want to the token <strong>" + token.Token + "</strong>? This action can not be undone.";
		}

		public override void Action(BlogCommandPage page)
		{
			TextToken token = GetToken();
			TextTokens.Delete(token);

		}

		protected TextToken GetToken()
		{
			CSContext context = CSContext.Current;
			int TokenID = Int32.Parse(context.QueryString["TokenID"]);
			int SectionID = context.SectionID;
			ArrayList list = TextTokens.GetTokens(SectionID);
			foreach(TextToken token in list)
			{
				if(token.TokenID == TokenID)
					return token;
			}

			return null;
		}

		public override string Title
		{
			get { return "Delete Token";}
		}

	}
}
