Ejemplo n.º 1
0
 /// <summary>
 /// 声明已经阅读了某条
 /// </summary>
 /// <param name="messageId"></param>
 /// <param name="username"></param>
 public static void Read(int messageId, string username)
 {
     using (Model2DataContext db = new Model2DataContext())
     {
         Message message = db.PondOfMessage.FirstOrDefault(x => x.Id == messageId);
         if (message == null) { throw new Exception("消息不存在"); }
         if (message.Readed) { return; }
         message.Readed = true;
         db.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送一个新的聊天信息
        /// </summary>
        /// <param name="_from">发件人</param>
        /// <param name="_to">收件人</param>
        /// <param name="content">正文</param>
        /// <param name="ip">来源地址</param>
        /// <param name="address">来源地址</param>
        /// <param name="readed">已经阅读</param>
        /// <param name="isOfficial">一个布尔值 表示是否官方信息</param>
        /// <returns>返回被创建的聊天信息的封装</returns>
        public static Message Send(string _from, string _to, string content, string ip, string address
            , bool readed, bool isOfficial = false)
        {
            using (Model2DataContext db = new Model2DataContext())
            {
                Message message = new Message(_from, _to, content, ip, address, readed, isOfficial);
                db.PondOfMessage.Add(message);
                db.SaveChanges();

                return message;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 创建一个新的Ip/实际地址对照
 /// </summary>
 /// <param name="ip">网络地址</param>
 /// <param name="address">实际地址</param>
 public static void Create(string ip, string address)
 {
     using (Model2DataContext db = new Model2DataContext())
     {
         db.PondOfIpToAddress.Where(x => x.Ip == ip)
             .ToList()
             .ForEach(x => db.PondOfIpToAddress.Remove(x));
         IpToAddress t = new IpToAddress(ip, address);
         db.PondOfIpToAddress.Add(t);
         db.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        public static string Create(byte[] content)
        {
            using (Model2DataContext db = new Model2DataContext())
            {
                string token = Guid.NewGuid().ToString("N");
                Picture pic = new Picture(token, content);
                db.PondOfPicture.Add(pic);
                db.SaveChanges();

                return token;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 读取未读信息列表
 /// </summary>
 /// <param name="targetUser">对方的用户名</param>
 /// <param name="self">自己的用户名</param>
 /// <returns>返回未读信息的列表</returns>
 public static List<MessageResult> ReadUnreadMessages(string targetUser, string self)
 {
     using (Model2DataContext db = new Model2DataContext())
     {
         List<MessageResult> result = new List<MessageResult>();
         List<Message> tList = db.PondOfMessage.Where(x => x.From == targetUser && x.To == self && !x.Readed)
             .ToList();
         tList.ForEach(x =>
             {
                 x.Readed = true;
                 MessageResult mr = new MessageResult(x, x.From == self);
                 result.Add(mr);
             });
         db.SaveChanges();
         return result;
     }
 }