Beispiel #1
0
 /// <summary>
 /// 根据ID获取用户信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Domain.SYS_USER GetUserById(int id)
 {
     return(UserManage.Get(p => p.ID == id));
 }
Beispiel #2
0
        /// <summary>
        /// 用户登录注册信息
        /// </summary>
        /// <param name="id"></param>
        public void Register(string account, string password)
        {
            try
            {
                //获取用户信息
                var User = UserManage.Get(p => p.ACCOUNT == account);
                if (User != null && User.PASSWORD == password)
                {
                    //更新在线状态
                    var  UserOnline = UserOnlineManage.LoadListAll(p => p.FK_UserId == User.ID).FirstOrDefault();
                    bool isEdit     = UserOnline != null;
                    if (!isEdit)    //若没有在线信息,则新增。
                    {
                        UserOnline = new SYS_USER_ONLINE {
                            FK_UserId = User.ID
                        };
                    }
                    UserOnline.ConnectId  = Context.ConnectionId;
                    UserOnline.OnlineDate = DateTime.Now;
                    UserOnline.IsOnline   = true;
                    UserOnline.UserIP     = Utils.GetIP();
                    UserOnlineManage.SaveOrUpdate(UserOnline, isEdit);

                    //获取历史消息
                    int      days            = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["HistoryDays"]);
                    DateTime dtHistory       = DateTime.Now.AddDays(-days);
                    var      ChatMessageList = ChatMessageManage.LoadAll(p => p.MessageDate > dtHistory);

                    //超级管理员
                    if (User.ID == ClsDic.DicRole["超级管理员"])
                    {
                        //通知用户上线
                        Clients.All.UserLoginNotice("超级管理员:" + User.NAME + " 上线了!");

                        var HistoryMessage = ChatMessageList.OrderBy(p => p.MessageDate).ToList().Select(p => new
                        {
                            UserName    = UserManage.Get(m => m.ID == p.FromUser).NAME,
                            UserFace    = string.IsNullOrEmpty(UserManage.Get(m => m.ID == p.FromUser).FACE_IMG) ? "/Pro/Project/User_Default_Avatat?name=" + UserManage.Get(m => m.ID == p.FromUser).NAME.Substring(0, 1) : UserManage.Get(m => m.ID == p.FromUser).FACE_IMG,
                            MessageType = GetMessageType(p.MessageType),
                            p.FromUser,
                            p.MessageContent,
                            MessageDate = p.MessageDate.GetDateTimeFormats('D')[1].ToString() + " - " + p.MessageDate.ToString("HH:mm:ss"),
                            ConnectId   = UserOnlineManage.LoadListAll(m => m.SYS_USER.ID == p.FromUser).FirstOrDefault().ConnectId
                        }).ToList();

                        //推送历史消息
                        Clients.Client(Context.ConnectionId).addHistoryMessageToPage(JsonConverter.Serialize(HistoryMessage));
                    }
                    else
                    {
                        //获取用户一级部门信息
                        var Depart = GetUserDepart(User.DPTID);
                        if (Depart != null && !string.IsNullOrEmpty(Depart.ID))
                        {
                            //添加用户到部门群组 Groups.Add(用户连接ID,群组)
                            Groups.Add(Context.ConnectionId, Depart.ID);
                            //通知用户上线
                            Clients.All.UserLoginNotice(Depart.NAME + " - " + CodeManage.Get(m => m.CODEVALUE == User.LEVELS && m.CODETYPE == "ZW").NAMETEXT + ":" + User.NAME + " 上线了!");
                            //用户历史消息
                            int typeOfpublic   = Common.Enums.ClsDic.DicMessageType["广播"];
                            int typeOfgroup    = Common.Enums.ClsDic.DicMessageType["群组"];
                            int typeOfprivate  = Common.Enums.ClsDic.DicMessageType["私聊"];
                            var HistoryMessage = ChatMessageList.Where(p => p.MessageType == typeOfpublic || (p.MessageType == typeOfgroup && p.ToGroup == Depart.ID) || (p.MessageType == typeOfprivate && p.ToGroup == User.ID.ToString())).OrderBy(p => p.MessageDate).ToList().Select(p => new
                            {
                                UserName    = UserManage.Get(m => m.ID == p.FromUser).NAME,
                                UserFace    = string.IsNullOrEmpty(UserManage.Get(m => m.ID == p.FromUser).FACE_IMG) ? "/Pro/Project/User_Default_Avatat?name=" + UserManage.Get(m => m.ID == p.FromUser).NAME.Substring(0, 1) : UserManage.Get(m => m.ID == p.FromUser).FACE_IMG,
                                MessageType = GetMessageType(p.MessageType),
                                p.FromUser,
                                p.MessageContent,
                                MessageDate = p.MessageDate.GetDateTimeFormats('D')[1].ToString() + " - " + p.MessageDate.ToString("HH:mm:ss"),
                                ConnectId   = UserOnlineManage.LoadListAll(m => m.SYS_USER.ID == p.FromUser).FirstOrDefault().ConnectId
                            }).ToList();

                            //推送历史消息
                            Clients.Client(Context.ConnectionId).addHistoryMessageToPage(JsonConverter.Serialize(HistoryMessage));
                        }
                    }
                    //刷新用户通讯录
                    Clients.All.ContactsNotice(getUserOnlineJson(UserOnline));
                }
            }
            catch (Exception ex)
            {
                Clients.Client(Context.ConnectionId).UserLoginNotice("出错了:" + ex.Message);
                throw ex.InnerException;
            }
        }