• 1


        /// <summary>
        /// 聊天室实体
        /// </summary>
        public class ChatDTO
        {
            /// <summary>
            /// 聊天室ID
            /// </summary>
            public Guid ChatID { get; set; }
            /// <summary>
            /// 访客
            /// </summary>
            public Visitor Visitor { get; set; }
            /// <summary>
            /// 客服
            /// </summary>
            public List<Agent> Agents { get; set; }
            public DateTime CreateTime { get; set; }
        }
    
        /// <summary>
        /// visitor
        /// </summary>
        public class Visitor
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }
    
        /// <summary>
        /// agent
        /// </summary>
        public class Agent
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }
    
        /// <summary>
        /// 消息实体
        /// </summary>
        public class Messages
        {
            //主键
            public Guid MID { get; set; }
            //聊天室ID
            public Guid ChatID { get; set; }
            //发送者的ID
            public int ID { get; set; }
            //发送者角色,客服or访客
            public int Role { get; set; }
            //消息内容
            public string Content { get; set; }
            //发送时间
            public DateTime SendTime { get; set; }
        }
    
        public interface IChatService
        {
            /// <summary>
            /// 创建聊天室
            /// </summary>
            /// <returns></returns>
            Guid CreateChat(Visitor visitor);
    
            /// <summary>
            /// 关闭聊天室
            /// </summary>
            /// <param name="chatid"></param>
            /// <returns></returns>
            bool CloseChat(Guid chatid);
    
            /// <summary>
            /// 添加客服
            /// </summary>
            /// <param name="agent"></param>
            /// <returns></returns>
            bool AddAgent(Agent agent);
    
            /// <summary>
            /// 客服离开
            /// </summary>
            /// <param name="id">客服ID</param>
            /// <returns></returns>
            bool RemoveAgent(int id);
    
            /// <summary>
            /// 发送消息
            /// </summary>
            /// <param name="chatid">聊天室ID</param>
            /// <param name="id">发送者的ID</param>
            /// <param name="role">发送者角色,客服or访客</param>
            /// <param name="content">消息内容</param>
            void SendMsg(Guid chatid, int id, int role, string content);
        }
    
        public class ChatService : IChatService
        {
            //当前存在的聊天室
            List<ChatDTO> chatDTOs = new List<ChatDTO>();
            //已发送的消息
            List<Messages> messages = new List<Messages>();
    
            public bool AddAgent(Agent agent)
            {
                throw new NotImplementedException();
            }
    
            public bool CloseChat(Guid chatid)
            {
                throw new NotImplementedException();
            }
    
            public Guid CreateChat(Visitor visitor)
            {
                var curChat = chatDTOs.Where(c => c.Visitor == visitor).FirstOrDefault();
                if (curChat != null)
                {
                    return curChat.ChatID;
                }
                else
                {
                    ChatDTO chat = new ChatDTO()
                    {
                        ChatID = Guid.NewGuid(),
                        Visitor = visitor,
                        CreateTime = DateTime.Now
                    };
                    chatDTOs.Add(chat);
                    return chat.ChatID;
                }
            }
    
            public bool RemoveAgent(int id)
            {
                throw new NotImplementedException();
            }
    
            public void SendMsg(Guid chatid, int id, int role, string content)
            {
                throw new NotImplementedException();
            }
        }
  • 相关阅读:
    C#反射概念以及实例详解【转】
    .NET(C#):使用反射来获取枚举的名称、值和特性【转】
    探求C#.Net中ArrayList与Array的区别 【转】
    C#中IList<T>与List<T>的区别感想【转】
    C# System.Guid.NewGuid() 【转】
    回车键触发按钮事件
    MVC中Json的使用:Controller中Json的处理【转】
    关于优化性能<主要是速度方面>的个人心得 【转】
    ca72a_c++_标准IO库:面向对象的标准库
    ca71a_c++_指向函数的指针_通过指针调用函数txwtech
  • 原文地址:https://www.cnblogs.com/2333hh/p/13357120.html
Copyright © 2020-2023  润新知