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 PubMapPatuserDocuserRepository : BaseRepositoryToASHermed_SinoInterface<Pub_Map_Patuser_Docuser>, IPubMapPatuserDocuserRepository
    {
        public int InsertPatuserDocuser(Pub_Map_Patuser_Docuser ent)
        {
            StringBuilder selectSql = new StringBuilder();
            selectSql.Append(@"INSERT INTO `pub_map_patuser_docuser` (
								`ID`,
								`PAT_USER_ID`,
								`DOC_USER_ID`,
								`STATUS`,
								`CREATE_TIME`,
								`UPDATE_TIME`)
								VALUES
									(@ID,@PAT_USER_ID,@DOC_USER_ID,@STATUS,@CREATE_TIME,@UPDATE_TIME);");
            return Execute(selectSql.ToString(), ent);
        }

        public Pub_Map_Patuser_Docuser SelectByPatAndDoc(int userId, int Id)
        {
            var selectSql = new StringBuilder();
            selectSql.Append(@" select ID, PAT_USER_ID, DOC_USER_ID, STATUS, CREATE_TIME, UPDATE_TIME
                                    from pub_map_patuser_docuser
                                    where STATUS = 1
                                      and PAT_USER_ID = @patUserId
                                      and DOC_USER_ID = @docUserId");
            var parms = new Dictionary<string, object>();
            parms.Add("@patUserId", userId);
            parms.Add("@docUserId", Id);
            var result = Query<Pub_Map_Patuser_Docuser>(selectSql.ToString(), parms);
            return result.FirstOrDefault();
        }



    }
}
