using PageAdmin.BLL;
using PageAdmin.Utils;
using System.Collections.Generic;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.E.Controllers
{
    public class GetUserMsgController : BaseController
    {

        /// <summary>
        /// 获取当前用户的最新信息
        /// </summary>
        /// <param name="listNums"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult LatestMsg()
        {
            int listNums =StringHelper.Format<int>(Request.QueryString["listNums"]);
            if (listNums == 0)
            {
                listNums = 5;
            }
            CurrentUser currentUser = ViewBag.CurrentUser;
            if(currentUser.Uid==0)
            {
                return null;
            }
            int uid = currentUser.Uid;
            MsgInboxBLL msgInBoxBll = new MsgInboxBLL();
            int noReadedNums = msgInBoxBll.GetNoReadedNums(uid);
            IEnumerable<dynamic> list = msgInBoxBll.GetNoReadedList(listNums, uid);
            var newMsg = new
            {
                noReadedMsgNums = noReadedNums,
                noReadedMsgList = list
            };
            return Json(newMsg);
        }

    }
}