public void AddOrUpdate(UserView view) { if (string.IsNullOrEmpty(view.OrganizationIds)) { throw new Exception("请为用户分配机构"); } User user = view; if (string.IsNullOrEmpty(view.Id)) { if (UnitWork.IsExist <User> (u => u.Account == view.Account)) { throw new Exception("用户账号已存在"); } user.CreateTime = DateTime.Now; user.Password = user.Account; //初始密码与账号相同 UnitWork.Add(user); view.Id = user.Id; //要把保存后的ID存入view } else { UnitWork.Update <User> (u => u.Id == view.Id, u => new User { Account = user.Account, BizCode = user.BizCode, Name = user.Name, Sex = user.Sex, Status = user.Status }); } UnitWork.Save(); string[] orgIds = view.OrganizationIds.Split(',').ToArray(); _revelanceApp.DeleteBy(Define.USERORG, user.Id); _revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => user.Id)); }
public void AddOrUpdate(UpdateUserReq request) { request.ValidationEntity(u => new { u.Account, u.Name, u.OrganizationIds }); if (string.IsNullOrEmpty(request.OrganizationIds)) { throw new Exception("请为用户分配机构"); } User requser = request; requser.CreateId = _auth.GetCurrentUser().User.Id; UnitWork.ExecuteWithTransaction(() => { if (string.IsNullOrEmpty(request.Id)) { if (UnitWork.Any <User>(u => u.Account == request.Account)) { throw new Exception("用户账号已存在"); } if (string.IsNullOrEmpty(requser.Password)) { requser.Password = requser.Account; //如果客户端没提供密码,默认密码同账号 } requser.CreateTime = DateTime.Now; UnitWork.Add(requser); request.Id = requser.Id; //要把保存后的ID存入view } else { UnitWork.Update <User>(u => u.Id == request.Id, u => new User { Account = requser.Account, BizCode = requser.BizCode, Name = requser.Name, Sex = requser.Sex, Status = requser.Status }); if (!string.IsNullOrEmpty(requser.Password)) //密码为空的时候,不做修改 { UnitWork.Update <User>(u => u.Id == request.Id, u => new User { Password = requser.Password }); } } UnitWork.Save(); string[] orgIds = request.OrganizationIds.Split(',').ToArray(); _revelanceApp.DeleteBy(Define.USERORG, requser.Id); _revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => requser.Id)); }); }
/// <summary> /// 更新相应的多对多关系 /// </summary> /// <param name="view"></param> private void UpdateRele(RoleView view) { string[] orgIds = view.OrganizationIds.Split(',').ToArray(); _revelanceApp.DeleteBy(Define.ROLEORG, view.Id); _revelanceApp.Assign(Define.ROLEORG, orgIds.ToLookup(u => view.Id)); }