Esempio n. 1
0
 public static string SendMessge(int form,int to,string title,string message,string ip) {
     Status status = Status.error;
     string hitStr = "操作失败,请重试!";
     using (ClubEntities club = new ClubEntities()) {
         var toUser = club.Users.Where(u => u.Id == to).FirstOrDefault();
         if (toUser != null) {
             Message msg = new Message() { 
                 FromId=form,
                 ToId=to,
                 Title=title,
                 Message1=message,
                 Ip=ip,
                 Vardate=DateTime.Now
             };
             club.Messages.Add(msg);
             if (club.SaveChanges() >0) {
                 status = Status.success;
                 hitStr = "发送成功!";
             }
         }
         else {
             hitStr = "对方账号不存在!";
         }
     }
     return JsonConvert.SerializeObject(new {status=status,context=hitStr });
 }
        public JsonResult MassSend(string ids, string context) {
            user=GetUser();
            ids=HtmlCommon.ClearHtml(ids);
            context=HtmlCommon.ClearHtml(context);
            if (string.IsNullOrEmpty(ids)){
                hintStr = "信息发送失败,没有选择用户!";
            }
            else {

                if (string.IsNullOrEmpty(context)){
                    hintStr = "信息发送失败,发送的信息不能空!";
                }
                else {
                    string[] idArray = ids.Split(',');
                    int[] idIntArray = new int[idArray.Length];
                    int value = 0;
                    for (int i = 0; i < idArray.Length; i++){
                        Int32.TryParse(idArray[i],out value);
                        idIntArray[i] = value;
                    }
                    using (club = new ClubEntities())
                    {
                        List<Message> Messages=new List<Message>();
                        foreach (int item in idIntArray) {
                            var msg = new Message() {FromId=user.Id,ToId=item,Message1=context,Status=(byte)State.Disable, Ip=Request.UserHostAddress,Vardate=DateTime.Now,Title="个人消息" };
                            club.Messages.Add(msg);
                        }
                        if (club.SaveChanges() >= 0) {
                            status = Status.success;
                            hintStr = "发送成功!";
                        }else{
                            hintStr = "系统异常!!";
                        }
                    }
                }
            }
            return Json(new {status=status.ToString(),context=hintStr });
        }