using PageAdmin.BLL;
using PageAdmin.Common;
using PageAdmin.Utils;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    public class MsgAdminController : DefaultBaseController
    {

        public MsgAdminController() : base("pa_msg", "User")
        {
            base.MvcContext.IncludeAttachments = true;
            base.AddViewExecuting = GetRelative;
            base.AddExecuting = SetSendIds;
            base.AddExecuted = SendMsg;
            base.DeleteExecuted = DeleteRelative;
        }


        //[HttpGet]
        //public ActionResult IFrameIndex()
        //{
        //    ViewBag.DefaultUrl = Url.Action("Index", "MsgAdmin");
        //    ViewBag.Titile = "站内信息";
        //    return View("_IFramePage");
        //}

        //[HttpGet]
        //[ChildActionOnly]
        //public ActionResult IFrameMenu()
        //{
        //    return View();
        //}


        private void GetRelative()
        {
            ViewBag.UserName = base.CurrentUser.UserName;
        }

        ///// <summary>
        ///// 获取收件箱id
        ///// </summary>
        //private void GetReceiverUid()
        //{
        //    ViewBag.Guid = SysHelper.NewGuid();
        //    ViewBag.UserName = base.CurrentUser.UserName;
        //}


        /// <summary>
        ///设置sendIds
        /// </summary>
        private void SetSendIds()
        {
            var form = base.MvcContext.Data;
            string sendType = form["sendType"];
            string sendIds = "";
            switch (sendType)
            {
                case "1":
                    sendIds = form["SendMemberGroupIds"];
                    break;
                case "2":
                    sendIds = form["SendDepartmentIds"];
                    break;
                case "3":
                    sendIds = form["SendUIds"];
                    break;

            }
            form["sendIds"] = sendIds;
        }

        /// <summary>
        ///添加信息后同步发送到收件箱
        /// </summary>
        private void SendMsg()
        {
            MsgBLL msgBll = new MsgBLL();
            msgBll.SendMsg(base.MvcContext);
        }

        /// <summary>
        /// 同时删除收件箱的数据
        /// </summary>
        private void DeleteRelative()
        {
            int id = StringHelper.Format<int>(base.MvcContext.Data["id"]);
            MsgInboxBLL msgInboxBll = new MsgInboxBLL();
            msgInboxBll.DeleteByMsgId(id);

        }


    }
}