/// <summary> /// 把物理文件保存到服务器 /// </summary> /// <returns></returns> public JsonResult FileUpload() { string result = "0"; string path = string.Empty; try { path = RWUtility.UploadToServer(Request.Files[0], true); result = "1"; } catch (Exception ex) { } return(new JsonResult() { Data = new { result, path } }); }
public JsonResult SaveUserInfo() { string result = "0"; //头像相关 string head_img = ""; string nick_name = ""; HttpPostedFileBase file = null; //是通过右上角更新自己的信息,或者用户列表中更新自己的信息,则ajax返回时,把右上角改了 string update_cookie = "0"; try { long row_key = 0, depart_key = 0; long.TryParse(Request["row_key"], out row_key); long.TryParse(Request["depart_key"], out depart_key); if (row_key == 0) { if (depart_key > 0) { //用户名查重 List <UserEntity> queryList = db.PageList <UserEntity>(1, Utility.PageMaxCount, (p => p.LoginName == Request["login_name"]), null); if (queryList.Count > 0) { result = "2"; } else { UserEntity addUser = new UserEntity(); addUser.DepartKey = depart_key; addUser.RowKey = Utility.CreateRowKey(); addUser.Pwd = CommonConfig.Current.UserDefaultPwd; addUser.LoginName = Request["login_name"]; nick_name = addUser.NickName = Request["nick_name"]; addUser.Sex = Request["sex"]; addUser.Role = Request["role"]; addUser.Phone = Request["Phone"]; addUser.Creator = addUser.Editor = Utility.GetLoginUserKey(); addUser.CreateTime = addUser.UpdateTime = DateTime.Now; addUser.Status = true; //头像 file = Request.Files["loadFile"]; if (file != null && file.ContentLength > 0) { long rowKey = Utility.CreateRowKey(); string filepath = RWUtility.UploadToServer(file, true); head_img = addUser.HeadImg = filepath; } if (db.InsertEntity <UserEntity>(addUser)) { result = "1"; } } } } else { UserEntity editItem = db.Single <UserEntity>(row_key); editItem.LoginName = Request["login_name"]; nick_name = editItem.NickName = Request["nick_name"]; editItem.Sex = Request["sex"]; editItem.Role = Request["role"]; editItem.Phone = Request["Phone"]; editItem.Editor = Utility.GetLoginUserKey(); editItem.UpdateTime = DateTime.Now; //头像 file = Request.Files["loadFile"]; if (file != null && file.ContentLength > 0) { long rowKey = Utility.CreateRowKey(); string filepath = RWUtility.UploadToServer(file, true); head_img = editItem.HeadImg = filepath; } foreach (System.Data.Linq.ObjectChangeConflict occ in db.ChangeConflicts) { occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues); } db.SubmitChanges(); result = "1"; } if (!string.IsNullOrEmpty(head_img) && result == "1") { UploadImageModel model = new UploadImageModel(); model.headFileName = Request.Form["headFileName"].ToString(); model.x = Convert.ToInt32(Request["x"]); model.y = Convert.ToInt32(Request["y"]); if (Request["isIE"] == "1") { Stream stream = file.InputStream; System.Drawing.Image image = System.Drawing.Image.FromStream(stream); model.width = Convert.ToInt32(image.Width); model.height = Convert.ToInt32(image.Height); } else { model.width = Convert.ToInt32(Request["width"]); model.height = Convert.ToInt32(Request["height"]); } RWUtility.CutAvatar(head_img, model.x, model.y, model.width, model.height, 75L, ResFileType.UserIcon120x120, 120); RWUtility.CutAvatar(head_img, model.x, model.y, model.width, model.height, 75L, ResFileType.UserIcon94x94, 94); RWUtility.CutAvatar(head_img, model.x, model.y, model.width, model.height, 75L, ResFileType.UserIcon48x48, 48); RWUtility.CutAvatar(head_img, model.x, model.y, model.width, model.height, 75L, ResFileType.UserIcon28x28, 28); if (Request["type"] == "2" || Utility.GetLoginUserKey() == row_key) { //更新cookie中的头像 Utility.UpdateCookie("head_img", head_img, Utility.LoginCookieName); } } if (result == "1") { if (Request["type"] == "2" || Utility.GetLoginUserKey() == row_key) { //更新cookie中的昵称 Utility.UpdateCookie("nick_name", nick_name, Utility.LoginCookieName); update_cookie = "1"; } } head_img = RWUtility.FormatResUrl(head_img, ResFileType.UserIcon28x28); } catch (Exception ex) { } return(new JsonResult() { Data = new { result, head_img, nick_name, update_cookie } }); }