public static bool Del(string loginKey, ref ErrorInfo err) { var ent = OnLines.SingleOrDefault(a => a.Guid == loginKey); if (ent == null) { return(true); } using (DBEntities db = new DBEntities()) { int userID = ent.UserId; #region 记录登出历史 var tmp_user = db.fa_user.SingleOrDefault(x => x.ID == userID); if (tmp_user != null) { tmp_user.LAST_LOGOUT_TIME = DateTime.Now; } if (ProInterface.AppSet.WiteLoginLog) { var tmp = db.fa_login_history.SingleOrDefault(x => x.ID == ent.loginHistoryId); if (tmp != null) { tmp.LOGOUT_TIME = DateTime.Now; } } #endregion Remove(ent); Fun.DBEntitiesCommit(db, ref err); } Save(); return(true); }
public static GlobalUser Add(int userId, string loginIP) { GlobalUser reEnt = new GlobalUser(); var entArr = OnLines.Where(a => a.UserId == userId && a.LoginIP == loginIP).ToList(); if (entArr.Count() > 0) { reEnt = entArr[0]; reEnt.LastOpTime = DateTime.Now; return(reEnt); } lock (symObj) { using (DBEntities db = new DBEntities()) { var user = db.fa_user.SingleOrDefault(x => x.ID == userId); string loginKey = Guid.NewGuid().ToString().Replace("-", ""); ClearTimeOutUser(); IList <string> idArr = new List <string>(); var dis = user.fa_district; var tmp = dis; while (tmp != null) { idArr.Add(tmp.ID.ToString()); tmp = tmp.fa_district2; } string tmpRuleRegionList = ""; if (user.fa_district1.Count() > 0) { tmpRuleRegionList = string.Format("'{0}'", string.Join("','", user.fa_district1.Select(x => x.CODE).ToList())); } else { tmpRuleRegionList = string.Format("'{0}'", user.DISTRICT_ID); } reEnt = new GlobalUser { Guid = loginKey, UserId = userId, DistrictId = user.DISTRICT_ID, LastOpTime = DateTime.Now, RoleID = user.fa_role.Select(y => y.ID).ToList(), UserName = user.NAME, LoginIP = loginIP, Region = user.DISTRICT_ID.ToString(), RegionList = idArr, RuleRegionStr = tmpRuleRegionList, LevelId = user.fa_district.LEVEL_ID, LoginName = user.LOGIN_NAME, DistrictCode = user.fa_district.CODE }; OnLines.Add(reEnt); Save(); #region 记录登录历史 var tmp_user = db.fa_user.SingleOrDefault(x => x.ID == userId); if (tmp_user.LOGIN_COUNT == null) { tmp_user.LOGIN_COUNT = 0; } tmp_user.LOGIN_COUNT++; tmp_user.LAST_LOGIN_TIME = DateTime.Now; if (ProInterface.AppSet.WiteLoginLog) { fa_login_history hist = new fa_login_history(); hist.ID = Fun.GetSeqID <fa_login_history>(); hist.USER_ID = userId; hist.LOGIN_TIME = DateTime.Now; hist.LOGIN_HOST = loginIP; db.fa_login_history.Add(hist); GetUser(loginKey).loginHistoryId = hist.ID; } ErrorInfo err = new ErrorInfo(); Fun.DBEntitiesCommit(db, ref err); #endregion //var Watermark = PicFun.CreateWatermark(ProInterface.AppSet.SysName, reEnt.UserName); //try //{ // File.WriteAllBytes(string.Format("{0}/UpFiles/{1}.jpg", AppDomain.CurrentDomain.BaseDirectory, reEnt.Guid), Watermark); //} //catch { } return(reEnt); } } }