public async Task <IActionResult> Edit(UserEditModel model) { if (!ModelState.IsValid) { return(Json(ResultDto.Err(GetErrorFromModelStateStr()))); } if (!string.IsNullOrWhiteSpace(model.Avatar)) { if (model.Avatar.Contains("[")) { var saveUrl = IMGOperate.BaseSave(ImagePathType.员工头像, model.Avatar); model.Avatar = saveUrl; } } var m = await UserApp.GetAsync(model.Id); if (m == null) { return(Json(ResultDto.Err("数据不存在或已被删除"))); } m = model.MapToMeg <UserEditModel, User>(m); var r = await UserApp.UpdateUserInfoAsync(m, await CurrentUser()); return(Json(r)); }
/// <summary> /// 获取当前用户 /// </summary> /// <returns></returns> public async Task <CurrentUser> CurrentUser() { CurrentUser CurrentUser; if (!User.Identity.IsAuthenticated) { return(null); } if (bool.Parse(Configuration.GetSection("IsIdentity").Value)) { // var name = this.HttpContext.User.Claims.FirstOrDefault(o => o.Type == ClaimTypes.Name)?.Value; var name = HttpContext.User.Identity.Name;// User.Claims.FirstOrDefault(o => o.Type == ClaimTypes.Name)?.Value; var user = await UserApp.GetAsync(name); CurrentUser = new CurrentUser { Avatar = user.Avatar, IsSys = user.IsSys, Id = user.Id, RoleId = user.RoleId, RealName = user.RealName, UserType = "Saas", AgentId = 0, LoginIPAddress = "" }; return(CurrentUser); } string userdata = User.Claims.FirstOrDefault(o => o.Type == ClaimTypes.UserData).Value; return(CurrentUser.FromJson(userdata)); }
public async Task <IActionResult> Edit(UserEditModel model) { if (!ModelState.IsValid) { return(Operation(false, GetErrorFromModelStateStr())); } if (!string.IsNullOrWhiteSpace(model.Avatar)) { if (model.Avatar.Contains("[")) { var saveUrl = IMGOperate.BaseSave(ImagePathType.员工头像, model.Avatar); model.Avatar = saveUrl; } } User m = await UserApp.GetAsync(model.Id); if (m == null) { return(Operation(false, "数据不存在或已被删除")); } m = MapperHelper.Map <UserEditModel, User>(model, m); var r = await UserApp.UpdateUserInfoAsync(m, CurrentUser); return(Operation(r.IsSuc, r.IsSuc ? "数据编辑成功" : r.Msg, model.GoBackUrl)); }
public async Task <IActionResult> Edit(long id) { UserEditModel model = new UserEditModel(); User user = await UserApp.GetAsync(id); if (user == null) { return(NotFind()); } model = user.MapTo <UserEditModel>(); model.GoBackUrl = SetingBackUrl(this.HttpContext.Request); var data = await RoleApp.GetListAsync(new RoleOption { }); List <SelectListItem> selects = data.Select(o => new SelectListItem { Value = o.Id.ToString(), Text = o.Name }).ToList(); model.Rolelist = selects; var deptdata = await DepartmentApp.GetDepartmentListAsync(); deptdata = deptdata.SortDepartmentsForTree().ToList(); var selectList = new List <SelectListItem>(); foreach (var c in deptdata) { selectList.Add(new SelectListItem() { Value = c.Id.ToString(), Text = c.GetFormattedBreadCrumb(deptdata), Selected = c.Id == model.DepartmentId }); } model.deptlist = selectList; ViewBag.GoBackUrl = SetingBackUrl(this.HttpContext.Request); return(View(model)); }