public BLLResult ChangePassword(string Username, string OldPassword, string NewPassword) { BLLResult res = new BLLResult(); TbUsers User = Find(Username); if (User != null) { string UserPass = NetTalk.Common.Hash.NetTalkEncrypt.Decrypt(User.UserPassCrypt, User.UserPassSalt); if (UserPass == OldPassword) { User.UserPassCrypt = NetTalk.Common.Hash.NetTalkEncrypt.Encrypt(NewPassword, User.UserPassSalt); User.UserLastChangePass = DateTime.Now; res.IsSuccess = Api.Save() > 0; res.ErrorMessage = Api.SaveError; } else { res.ErrorMessage = "password is invalid"; } } else { res.ErrorMessage = "user not found"; } return(res); }
/// <summary> /// change user status in database /// </summary> /// <param name="Username"></param> /// <param name="UserStatusText"></param> /// <param name="UserStatus">ShowType FROM AgsXmpp</param> /// <param name="IsOnline">Precence</param> /// <returns></returns> public BLLResult ChangeUserStatus(string Username, string UserStatusText, short?UserStatus, bool IsOnline) { BLLResult res = new BLLResult(); TbUsers User = Find(Username); if (User != null) { if (User.TbUserStatus == null) { User.TbUserStatus = new TbUserStatus(); User.TbUserStatus.UserStatus = 0; } User.TbUserStatus.UserStatusText = UserStatusText; if (UserStatus.HasValue) { User.TbUserStatus.UserStatus = UserStatus.Value; } User.TbUserStatus.UserStatusDate = DateTime.Now; User.TbUserStatus.UserIsOnline = IsOnline; res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; } return(res); }
public override BLLResult Delete(string idList) { BLLResult res = new BLLResult(); res.IsSuccess = true; List <Guid> ids = idList.ToGuidArray(); foreach (Guid Id in ids) { Api.DeleteUser(Id); } return(res); }
public BLLResult ChangeUserPicture(string Username, string Picture) { TbUsers User = Find(Username); BLLResult res = new BLLResult(); if (User != null) { User.TbVcard.VcardPhoto = Picture; res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; } return(res); }
public BLLResult Update(Guid id, string Text, string AlertTime) { TbAlerts alert = Find(id); alert.AlertTime = AlertTime.ToTime(); alert.AlertText = Text; alert.AlertHTML = Text.Replace("\r\n", "<br />").Replace("\r", "<br />").Replace("\n", "<br />"); BLLResult res = new BLLResult(); res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; return(res); }
public virtual BLLResult Delete(string idList) { List <Guid> ids = idList.ToGuidArray(); foreach (Guid g in ids) { BaseApi.Delete(BaseApi.Find(Key, g)); } BLLResult res = new BLLResult(); res.IsSuccess = (BaseApi.Save() > 0); res.ErrorMessage = BaseApi.SaveError; return(res); }
public BLLResult ChangeFriendStatus(string Username, string FriendUsername, string Group, byte?Status) { BLLResult res = new BLLResult(); TbFriend Friend = Api.FindFriend(Username, FriendUsername); if (Friend != null) { if (Status.HasValue) { Friend.FriendStatus = Status.Value; } Friend.GroupName = Group; res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; } return(res); }
public BLLResult Insert(string Text, string AlertTime) { TbAlerts alert = new TbAlerts(); alert.AlertTime = AlertTime.ToTime(); alert.AlertText = Text; alert.AlertHTML = Text.Replace("\r\n", "<br />").Replace("\r", "<br />").Replace("\n", "<br />"); alert.AlertId = NetTalk.GuidTools.Create(); Api.Insert(alert); BLLResult res = new BLLResult(); res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; return(res); }
public BLLResult ClearLastMonthLog() { DateTime Today = DateTime.Today; DateTime PrevMonth = Today.AddDays(-30); var q = Api.Table.Where(c => c.LogDate < Today && c.LogDate >= PrevMonth); foreach (TbLogs lg in q) { Api.Delete(lg); } BLLResult res = new BLLResult(); res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; return(res); }
public BLLResult DeleteFriend(string Username, string FriendUsername) { BLLResult res = new BLLResult(); TbFriend FA = Api.FindFriend(Username, FriendUsername); TbFriend FB = Api.FindFriend(FriendUsername, Username); if (FA != null) { Api.DeleteFriend(FA); } if (FB != null) { Api.DeleteFriend(FB); } res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; return(res); }
public BLLResult Insert(string ip, string sessionid, Guid?UserId, string text) { TbLogs lg = new TbLogs(); lg.LogId = NetTalk.GuidTools.Create(); lg.LogSessionId = sessionid; lg.LogText = text; lg.LogUserId = UserId; lg.LogIP = ip; lg.LogDate = DateTime.Now; Api.Insert(lg); BLLResult res = new BLLResult(); res.IsSuccess = Api.Save() > 0; res.ErrorMessage = Api.SaveError; return(res); }
public BLLResult AddUser(string Username, string Password, bool IsWebAdmin, TbVcard Vcard) { BLLResult res = new BLLResult(); TbUsers User = Find(Username); if (User == null) { string Salt = NetTalk.Common.Hash.NetTalkHash.Sha1Text(DateTime.Now.ToString("yyyyMMddHHmmss")); User = new TbUsers(); User.UserId = NetTalk.GuidTools.Create(); User.Username = Username; User.UserWebAdmin = IsWebAdmin; User.TbUserStatus = new TbUserStatus(); User.TbUserStatus.UserIsOnline = false; User.TbUserStatus.UserStatus = 0; User.TbUserStatus.UserStatusDate = DateTime.Now; User.UserPassSalt = Salt; User.UserPassCrypt = NetTalk.Common.Hash.NetTalkEncrypt.Encrypt(Password, Salt); User.TbVcard = Vcard; User.TbUserStatus = new TbUserStatus() { UserIsOnline = false, UserId = User.UserId, UserStatus = 0, UserStatusDate = DateTime.Now, UserStatusText = null }; Api.Insert(User); res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; } else { res.ErrorMessage = "this user name is taken"; } return(res); }
public BLLResult UpdateUser(string Username, string Password, bool IsWebAdmin, TbVcard Vcard) { BLLResult res = new BLLResult(); TbUsers User = Find(Username); if (User != null) { User.UserWebAdmin = IsWebAdmin; if (!string.IsNullOrEmpty(Password)) { User.UserPassCrypt = NetTalk.Common.Hash.NetTalkEncrypt.Encrypt(Password, User.UserPassSalt); } User.TbVcard = Vcard; res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; } else { res.ErrorMessage = "user name not found"; } return(res); }
public BLLResult AddFriend(string Username, string FriendUsername, string GroupName) { BLLResult res = new BLLResult(); if (!Api.IsFriend(Username, FriendUsername)) { TbUsers User = Find(Username); TbUsers Friend = Find(FriendUsername); if (User != null && Friend != null) { TbFriend FromUser = new TbFriend(); FromUser.UserId = User.UserId; //FromUser.TbUsers = User; FromUser.FriendId = Friend.UserId; //FromUser.TbUsers1 = Friend; FromUser.FriendStatus = 1; if (!string.IsNullOrEmpty(GroupName)) { FromUser.GroupName = GroupName; } Api.AddFriend(FromUser); TbFriend ToUser = new TbFriend(); ToUser.UserId = Friend.UserId; //ToUser.TbUsers = Friend; ToUser.FriendId = User.UserId; //ToUser.TbUsers1 = User; ToUser.FriendStatus = 0; Api.AddFriend(ToUser); res.IsSuccess = Api.Save() > 0; res.ErrorMessage = Api.SaveError; } } return(res); }
public BLLResult Insert(string fromuser, string touser, string text, string html, string senderIP, bool IsSent) { BLLResult res = new BLLResult(); TbUsers FUser = Api.FindUser(fromuser); TbUsers TUser = Api.FindUser(touser); if (FUser != null && TUser != null) { if (!string.IsNullOrEmpty(text)) { TbMessage msg = new TbMessage(); msg.MessageId = NetTalk.GuidTools.Create(); msg.MessageDate = DateTime.Now; msg.MessageFromUserId = FUser.UserId; msg.MessageHTML = html; msg.MessageSenderIP = senderIP; msg.MessageText = text; msg.MessageToUserId = TUser.UserId; msg.TbUsers = TUser; msg.TbUsers1 = FUser; if (IsSent) { msg.MessageViewDate = DateTime.Now; } Api.Insert(msg); res.IsSuccess = (Api.Save() > 0); res.ErrorMessage = Api.SaveError; } else { res.ErrorMessage = "user not found"; } } return(res); }