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

using System;
using System.Collections;
using System.Web.UI.WebControls;
using CommunityServer.Files.Components;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;

namespace CommunityServer.ControlPanel.FileAdmin
{
	/// <summary>
	///		Summary description for FolderEditControl.
	/// </summary>
	public class FolderEditControl : BaseFilesAdminControl
	{
		#region Child Controls
		
		protected FolderEditControlDetails SectionDetails1;
		protected FolderPermissionListControl SectionPermissions1;
		protected FolderOptionsControl FolderOptions1;
		
		#endregion

		public int SectionID = -1;
		private CSContext context;
	
		private void Page_Load(object sender, EventArgs e)
		{
			context = CSContext.Current;
			FolderOptions1.SectionID = SectionDetails1.SectionID = SectionPermissions1.SectionID = SectionID;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new EventHandler(this.Page_Load);

		}
		#endregion

		public Folder Save()
		{
			Folder folder = null;

			if(!Page.IsValid)
				return null;

			folder = SectionDetails1.Save() ;
			if(!Page.IsValid)
				return null;
			
			FolderOptions1.SectionID = SectionDetails1.SectionID;
			FolderOptions1.Save();

			SectionPermissions1.SectionID = SectionDetails1.SectionID;
			SectionPermissions1.Save();
			if(!Page.IsValid)
				return null;

			return folder;
		}

	}
}
