/// <summary> /// 更新头像 /// </summary> /// <param name="cutParams"></param> /// <param name="usrId"></param> /// <returns></returns> public OperationResult UpdateAvatar(CutAvatarParams cutParams, int usrId) { OperationResult optRst = new OperationResult(); try { bool rst = ImageHelper.CutAvatar(cutParams, 100, 100); if (!rst) { optRst.ResultType = OperationResultType.Error; optRst.Message = Msg_UpdateAvatar + "失败,未知错误"; return(optRst); } rst = _usrDetailRep.Exists(u => u.Id == usrId); optRst = rst ? base.Update(u => u.Id == usrId, u => new UserDetails { SrcImage = cutParams.imgSrcFilePath, AvatarImage = cutParams.imgAvatarFilePath }) : base.Add(new UserDetails { Id = usrId, SrcImage = cutParams.imgSrcFilePath, AvatarImage = cutParams.imgAvatarFilePath }); } catch (Exception ex) { base.ProcessException(ref optRst, Msg_UpdateAvatar, ex); } return(optRst); }
public JsonResult CutImage(CutAvatarParams cutInfo) { ResultEntity rst = new ResultEntity(); var jsonRst = new JsonResult { Data = rst, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; if (cutInfo == null) { rst.code = 0; rst.msg = "图片裁剪参数不能为空"; return(jsonRst); } cutInfo.imgSrcRealPath = Server.MapPath(cutInfo.imgSrcPath); try { ImageHelper.CutAvatar(cutInfo, 100, 100); rst.code = 1; rst.msg = "图片裁剪成功"; } catch (Exception ex) { rst.code = 0; rst.msg = ex.Message; } return(jsonRst); }
public JsonResult CutAvatar(CutAvatarParams cutParams) { JsonResult jsonRst = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet }; if (cutParams == null) { jsonRst.Data = new { code = OperationResultType.ParamError, message = "图片裁剪参数不能为空" }; return(jsonRst); } if (string.IsNullOrEmpty(cutParams.imgSrcFilePath)) { jsonRst.Data = new { code = OperationResultType.ParamError, message = "源图文件路径不能为空" }; return(jsonRst); } cutParams.imgSrcFileRealPath = Server.MapPath(cutParams.imgSrcFilePath); cutParams.imgAvatarFilePath = cutParams.imgSrcFilePath.Replace("src", "avatar"); cutParams.imgAvatarRealPath = cutParams.imgSrcFileRealPath.Replace("src", "avatar"); try { int usrId = (int)Session.GetUserId(); var optRst = _usrDetailSrv.UpdateAvatar(cutParams, usrId); if (optRst.ResultType != OperationResultType.Success) { jsonRst.Data = new { code = optRst.ResultType, message = optRst.Message }; return(jsonRst); } //更新session var usrDetail = Session.GetUserDetail(); if (usrDetail == null) { optRst = _usrDetailSrv.Find(u => u.Id == usrId); if (optRst.ResultType == OperationResultType.Success) { var lst = (List <UserDetails>)optRst.AppendData; if (lst != null && lst.Count > 0) { usrDetail = lst[0]; } } } if (usrDetail != null) { usrDetail.SrcImage = cutParams.imgSrcFilePath; usrDetail.AvatarImage = cutParams.imgAvatarFilePath; Session.SetUserDetail(usrDetail); } jsonRst.Data = new { code = OperationResultType.Success, message = "头像修改成功" }; } catch (Exception ex) { jsonRst.Data = new { code = OperationResultType.Error, message = ex.Message }; } return(jsonRst); }