public JsonResultModel HandleApply(int applyid, int userid, short result, string reason) { var ds = _dal.HandleApply(applyid, userid, result, reason); //转换成相应的推送model id,applytype,targetid,userid ApplyHandledMessgae message = ds.Tables[0].Rows.Cast <DataRow>().Select(x => new ApplyHandledMessgae { id = x["id"].ToInt(), result = x["result"].ToShort(), applyuid = x["userid"].ToInt(), targetid = x["targetid"].ToInt(), applytype = x["applytype"].ToShort() }).FirstOrDefault(); if (message.result == 1) { #region 返回加好友的信息 if (message.applytype == ApplyType.Friend.GetHashCode()) { //好友信息 //发送给申请方 message.friend = ds.Tables[1].Rows.Cast <DataRow>().Select(x => new UserFriendAddedMessage { groupid = x["groupid"].ToInt(), avatar = x["friendavatar"].ToString(), id = x["friendid"].ToInt(), sign = x["friendremark"].ToString(), type = LayIMConst.LayIMFriendType, username = x["friendname"].ToString() }).FirstOrDefault(); //发送给当前操作人 message.mine = ds.Tables[2].Rows.Cast <DataRow>().Select(x => new UserFriendAddedMessage { groupid = x["groupid"].ToInt(), avatar = x["friendavatar"].ToString(), id = x["friendid"].ToInt(), sign = x["friendremark"].ToString(), type = LayIMConst.LayIMFriendType, username = x["friendname"].ToString() }).FirstOrDefault(); } #endregion #region 返回群信息 if (message.applytype == ApplyType.UserJoinGroup.GetHashCode()) { message.group = ds.Tables[1].Rows.Cast <DataRow>().Select(x => new UserGroupCreatedMessage { id = x["groupid"].ToInt(), groupname = x["groupname"].ToString(), avatar = x["avatar"].ToString(), memebers = x["members"].ToInt(), type = LayIMConst.LayIMGroupType }).FirstOrDefault(); } #endregion } return(JsonResultHelper.CreateJson(message, true)); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var userid = LayIMCache.Instance.GetCurrentUserId(); if (string.IsNullOrWhiteSpace(userid)) { filterContext.Result = new JsonResult { ContentType = "application/json", JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = JsonResultHelper.CreateJson(null, false, "unauthorized") }; } else { filterContext.ActionParameters["userid"] = userid.ToInt(); } base.OnActionExecuting(filterContext); }
public JsonResult UploadImg(HttpPostedFileBase uploadimgname, string touid) { string strPostfix = uploadimgname.FileName.Substring(uploadimgname.FileName.LastIndexOf(".") + 1); if (strPostfix.ToLower() != "gif" && strPostfix.ToLower() != "jpg" && strPostfix.ToLower() != "pic" && strPostfix.ToLower() != "bmp" && strPostfix.ToLower() != "jpeg" && strPostfix.ToLower() != "png") { return(Json(JsonResultHelper.CreateJson(null, false, "请上传图片格式" + "(bmp;jpg;jpeg;png;tif;pic;)"), JsonRequestBehavior.DenyGet)); } KNet.AAMS.Web.Security.ApplicationIdentity identity = this.User.Identity as KNet.AAMS.Web.Security.ApplicationIdentity; var upload = FileUploadHelper.Upload(uploadimgname, Server.MapPath("~/upload/img"), identity.Id, touid, true); /*作者原来这样写 可能是有些浏览器前端不能够识别json吧*/ //var result = Json(upload, "text/html", JsonRequestBehavior.DenyGet); var result = Json(upload, JsonRequestBehavior.DenyGet); return(result); }