public IHttpActionResult GetInfoByUser(MessageInfoModel paramter) { MessageBLL user = new MessageBLL(); var add = user.GetInfo(paramter); return(InspurJson <RetMessageInfo>(add)); }
public IHttpActionResult GetAllMessageInfo(MessageInfoModel model) { MessageBLL msg = new MessageBLL(); var get = msg.GetAllMessageInfo(model); return(InspurJson <List <RetMessageInfo> >(get)); }
/// <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); }
public IHttpActionResult AddMessage(MessageInfoModel model) { UserApi api = new UserApi(); var userApi = api.GetUserInfoByToken(); model.CreateUserID = Convert.ToInt32(userApi.Data.UserId); MessageBLL msg = new MessageBLL(); var get = msg.AddMessage(model); return(InspurJson <RetMessageInfo>(get)); }
public async Task <IActionResult> Get() { var client = new MessagingInfo.MessagingInfoClient(channel); var request = new MessageInfoModel() { UserId = 2 }; var reply = await client.GetMessageByIdAsync(request); return(Ok(reply)); //return await Task.FromResult(Ok("Welcome to GRPC client")); }
/// <summary> /// 新增消息 /// </summary> public ReturnItem <RetMessageInfo> AddMessage(MessageInfoModel parameter) { ReturnItem <RetMessageInfo> r = new ReturnItem <RetMessageInfo>(); using (UserEntities user = new UserEntities()) { try { //新增消息 U_Message message = new U_Message() { Type = parameter.Type, Tittle = parameter.Tittle, Text = parameter.Text, CreateTime = DateTime.Now, CreateUserID = parameter.CreateUserID }; user.U_Message.Add(message); user.SaveChanges(); //新增用户消息关联表 var getinfo = user.U_Message.OrderByDescending(m => m.CreateTime).FirstOrDefault(); foreach (var item in parameter.UserID) { U_UserMessageRel newrel = new U_UserMessageRel() { UserID = Convert.ToInt32(item), MessageID = getinfo.ID, Status = "0", CreateTime = DateTime.Now, CreateUserID = parameter.CreateUserID }; user.U_UserMessageRel.Add(newrel); } user.SaveChanges(); r.Msg = "消息新增成功"; r.Code = 0; } catch (Exception e) { r.Msg = "内部错误请重试"; log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace); r.Code = -1; } } return(r); }
public override Task <MessageModel> GetMessageById(MessageInfoModel request, ServerCallContext context) { MessageModel messagem = new MessageModel(); if (request.UserId == 1) { messagem.FirstName = "Mitiku"; messagem.LastName = "Teshome"; } else if (request.UserId == 2) { messagem.FirstName = "MT"; messagem.LastName = "TE"; } else if (request.UserId == 2) { messagem.FirstName = "BTT"; messagem.LastName = "TTT"; } else if (request.UserId == 3) { messagem.FirstName = "NS"; messagem.LastName = "afd"; } else if (request.UserId == 4) { messagem.FirstName = "afdaff"; messagem.LastName = "afdafdaf"; } else { messagem.FirstName = "unknown"; messagem.LastName = "unknown"; } return(Task.FromResult(messagem)); }
/// <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); }