예제 #1
0
        /// <summary>
        /// 管理员获取信息列表
        /// </summary>
        /// <returns>成功返回用户信息,失败返回Null.</returns>
        public ReturnItem <List <RetMessageInfo> > GetAllMessageInfo(MessageInfoModel parameter)
        {
            ReturnItem <List <RetMessageInfo> > r = new ReturnItem <List <RetMessageInfo> >();
            List <RetMessageInfo> listinfo        = new List <RetMessageInfo>();

            using (UserEntities user = new UserEntities())
            {
                try
                {
                    IQueryable <U_Message> messageList = user.U_Message.AsQueryable <U_Message>();
                    if (parameter.Tittle != null && !"".Equals(parameter.Tittle))
                    {
                        messageList = messageList.Where(x => x.Tittle.IndexOf(parameter.Tittle) >= 0);
                    }
                    if (!"".Equals(parameter.Type) && parameter.Type != null)
                    {
                        messageList = messageList.Where(x => x.Type == parameter.Type.ToString());
                    }
                    messageList = messageList.OrderByDescending(x => x.CreateTime);
                    if (messageList == null)
                    {
                        r.Data = null;
                        r.Code = -1;
                        r.Msg  = "没有数据";
                        return(r);
                    }
                    if (messageList != null)
                    {
                        List <U_Message> list = messageList.ToList <U_Message>();
                        r.Count = messageList.Count();
                        r.Msg   = "消息列表获取成功";
                        r.Code  = 0;
                        foreach (var item in list)
                        {
                            var info = new RetMessageInfo();
                            info.ID           = item.ID.ToString();
                            info.Type         = item.Type;
                            info.Tittle       = item.Tittle;
                            info.Text         = item.Text;
                            info.CreateTime   = item.CreateTime;
                            info.CreateUserID = item.CreateUserID;
                            listinfo.Add(info);
                        }
                        r.Data = listinfo;
                    }
                }
                catch (Exception e)
                {
                    r.Msg = "内部错误请重试";
                    log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace);
                    r.Code = -1;
                    return(r);
                }
            }

            return(r);
        }
예제 #2
0
        /// <summary>
        /// 获取消息信息
        /// </summary>
        public ReturnItem <RetMessageInfo> GetInfo(MessageInfoModel parameter)
        {
            ReturnItem <RetMessageInfo> r = new ReturnItem <RetMessageInfo>();

            using (UserEntities user = new UserEntities())
            {
                try
                {
                    var getinfo = user.U_Message.Where(s => s.ID == parameter.ID).FirstOrDefault();
                    if (getinfo == null)
                    {
                        r.Data = null;
                        r.Code = -1;
                        r.Msg  = "未找到消息";
                        return(r);
                    }
                    if (getinfo != null)
                    {
                        var model = new RetMessageInfo()
                        {
                            ID           = getinfo.ID.ToString(),
                            Type         = getinfo.Type,
                            Tittle       = getinfo.Tittle,
                            Text         = getinfo.Text,
                            CreateTime   = getinfo.CreateTime,
                            CreateUserID = getinfo.CreateUserID
                        };

                        var getuserinfo = user.U_User.Join(user.U_UserMessageRel, x => x.ID, x => x.UserID, (a, b) => new { a, b })
                                          .Join(user.U_Message, x => x.b.MessageID, x => x.ID, (a, c) => new { a.a, a.b, c })
                                          .Where(x => x.c.ID == parameter.ID).ToList();

                        List <RetUserInfo> userinfo = new List <RetUserInfo>();
                        foreach (var item in getuserinfo)
                        {
                            RetUserInfo info = new RetUserInfo()
                            {
                                Id        = item.a.ID.ToString(),
                                AccountId = item.a.AccountId.ToString(),
                                Name      = item.a.Name,
                                Type      = item.a.Type,

                                Email         = item.a.Email,
                                ContactPhone  = item.a.ContactPhone,
                                PassWord      = item.a.PassWord,
                                IsAdmin       = item.a.IsAdmin,
                                IsManageAdmin = item.a.IsManageAdmin,
                                HeadImgUrl    = item.a.HeadImgUrl == null ? "" : item.a.HeadImgUrl.ToString(),
                                CreateTime    = item.a.CreateTime,
                            };
                            userinfo.Add(info);
                        }
                        model.UserInfo = userinfo;
                        r.Msg          = "消息信息获取成功";
                        r.Code         = 0;
                        r.Data         = model;
                    }
                }
                catch (Exception e)
                {
                    r.Msg = "内部错误请重试";
                    log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace);
                    r.Code = -1;
                }
            }
            return(r);
        }