using PushInfo.Core.IDAL;
using PushPlatform.Common.Model;
using PushPlatform.Common.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PushInfo.Core.BLL
{
    public class PushMessageBLL
    {
        /// <summary>
        /// 消息日志数据访问接口
        /// </summary>
        private IPushMessageDAL pushMessageDALDal;
        /// <summary>
        /// 构造函数
        /// </summary>
        public PushMessageBLL()
        {
            this.pushMessageDALDal = DALFactory.CreatePushMessageDAL();
        }
        #region 更新用户全部消息为只读
        /// <summary>
        /// 更新用户全部消息为只读
        /// </summary>
        /// <param name="projectId">项目Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public APIResult<string> UpAllMsgRead(string projectId,string userId)
        {
            APIResult<string> result = new APIResult<string>();
            result.Result = 1;
            try
            {
                if(string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(projectId))
                {
                    result.Result = 0;
                    result.Msg = "项目与用户必要信息确实，请联系管理员。";
                    return result;
                }
                var ret = pushMessageDALDal.UpdatePartail(new Models.Tables.Push_Message { Update_Time = DateTime.Now,Update_User=userId,HaveRead=1},x=>new {x.Update_User,x.Update_Time,x.HaveRead },x=>x.User_Id==userId && x.Project_Id==projectId);
                //if (ret.Result != 1)
                //{
                //    result.Result = 0;
                //    result.Msg = "提交数据库失败。请联系管理员";
                //}
            }
            catch(Exception ex)
            {
                LogHelper.Debug(projectId + "；" + userId);
                LogHelper.Error(ex);
                result.Result = 0;
                result.Msg = "更新全部异常，请联系管理员。";
            }
            return result;
        }
        #endregion
    }
}
