Exemple #1
0
 /// <summary>
 /// 设置首次登录信息
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="id"></param>
 /// <param name="nickName"></param>
 /// <returns></returns>
 public static bool SetFirstLoginInformationById(int id, string nickName)
 {
     try
     {
         using (BeMyMouthDB db = new BeMyMouthDB())
         {
             foreach (var user in db.Users)
             {
                 if (user.Id == id)
                 {
                     user.NickName     = nickName;
                     user.IsFirstLogin = false;
                     break;
                 }
             }
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine("当SetFirstLoginInformationById时出现异常:" + e);
         return(false);
     }
 }
Exemple #2
0
 /// <summary>
 /// 添加用户
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static bool ModifyUserInfo(int id, string username, string password)
 {
     try
     {
         using (BeMyMouthDB db = new BeMyMouthDB())
         {
             var user = db.Users.Where(u => u.Id == id).FirstOrDefault();
             if (user != null)
             {
                 if (username != string.Empty)
                 {
                     user.NickName = username;
                 }
                 if (password != string.Empty)
                 {
                     user.Password = password;
                 }
             }
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine("创建用户失败");
         return(false);
     }
 }
Exemple #3
0
 /// <summary>
 /// 保存消息
 /// </summary>
 public static void SavaMessage(string message, int sendId, int reciveId, DateTime dateTime)
 {
     try
     {
         Messages messages = new Messages()
         {
             Message  = message,
             SendId   = sendId,
             ReciveId = reciveId,
         };
         using (BeMyMouthDB db = new BeMyMouthDB())
         {
             db.Messages.Add(messages);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
Exemple #4
0
 /// <summary>
 /// 通过ID添加好友
 /// </summary>
 /// <param name="friendId"></param>
 /// <param name="selfId"></param>
 /// <returns></returns>
 public static bool AddFriendById(int friendId, int selfId)
 {
     try
     {
         using (BeMyMouthDB db = new BeMyMouthDB())
         {
             Friend friend = new Friend()
             {
                 LeftId  = friendId,
                 RightId = selfId
             };
             db.Friends.Add(friend);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemple #5
0
 /// <summary>
 /// 添加用户
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static bool AddUser(string username, string password)
 {
     try
     {
         using (BeMyMouthDB db = new BeMyMouthDB())
         {
             User user = new User()
             {
                 UserName     = username,
                 Password     = password,
                 NickName     = "用户007",
                 IsFirstLogin = true
             };
             db.Users.Add(user);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine("创建用户失败");
         return(false);
     }
 }