using ASHermed.SinoInterface.Api.ContractModel;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.IRepository;
using ASHermed.SinoInterface.Repository.MySql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASHermed.SinoInterface.Api.MySqlRepository
{
    public class Repository : BaseRepositoryToASHermed_SinoInterface<Pub_Message_Qimo>, IModelRepository
    {
        public int InsertPubMessageQimo(Pub_Message_Qimo ent)
        {
            var parms = new Dictionary<string, object>();
            var selectSql = @"insert into pub_message_qimo (UserId,IsRead,CreateTime,Content) values (@UserId ,@IsRead,@CreateTime,@Content)";
            parms.Add("@UserId", ent.UserId);
            parms.Add("@IsRead", ent.IsRead);
            parms.Add("@CreateTime", ent.CreateTime);
            parms.Add("@Content", ent.Content);
            var result = Insert(selectSql, parms);
            return result;
        }

        public int ReadQimoMessage(int userId)
        {
            var selectSql = new StringBuilder();
            selectSql.Append(@" UPDATE pub_message_qimo
                                    SET IsRead= TRUE
                                    WHERE UserId = @UserId");
            var parms = new Dictionary<string, object>();
            parms.Add("@UserId", userId);
            var result = Execute(selectSql.ToString(), parms);
            return result;
        }

        public int GetQimoMessage(int userId)
        {
            var selectSql = new StringBuilder();
            var parms = new Dictionary<string, object>();
            selectSql.Append(@"select count(1) from pub_message_qimo where UserId = @UserId and IsRead=false");
            parms.Add("@UserId", userId);
            var result = Query<int>(selectSql.ToString(), parms);
            return result.FirstOrDefault();
        }




    }
}
