using PageAdmin.BLL;using PageAdmin.Filter;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PageAdmin.Common;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    public class FriendRequestController : BaseController
    {

        public FriendRequestController():base("pa_friends_request", "Work")
        {
            base.ListDataExecuting= new Action(OnListWhere);
            base.MvcContext.ListOrder = "id desc";

            base.AddExecuting = new Action(OnAddExecuting);
        }
        private void OnListWhere()
        {
            var form = System.Web.HttpContext.Current.Request.QueryString;
            string requestxx = StringHelper.Format<string>(form["requestxx"]);
            MemberBLL memberBLL = new MemberBLL();
            string where = "";
            if (requestxx == "friends")
            {
                base.MvcContext.SqlCondition = "request_uid=" + base.CurrentUser.Uid;
                where = memberBLL.SelectUid("uid");
                if (where != "")
                {
                    base.MvcContext.SqlCondition += " and " + where;
                }
            }
            else
            {
                base.MvcContext.SqlCondition = "uid=" + base.CurrentUser.Uid;
                where = memberBLL.SelectUid("request_uid");
                if (where != "")
                {
                    base.MvcContext.SqlCondition += " and " + where;
                }
            }
        }
        private void OnAddExecuting()
        {
            FriendRequestBLL bll = new FriendRequestBLL();
            TipsInfo tipsInfo = base.MvcContext.TipsInfo;
            tipsInfo = bll.Add(base.MvcContext.Data);
        }

        [HttpGet]
        public ActionResult MyFriendRequest()
        {
            return View();
        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult IsAgree(FormCollection form)
        {
            FriendRequestBLL bll = new FriendRequestBLL();
            return Json(bll.IsAgree(form));

        }
    }
}