/// <summary> /// 添加用户 /// </summary> /// <param name="vUser">用户信息</param> /// <returns></returns> public string AddUser(UserAddDto vUser) { vUser = StringManage.EmptyStringSetNull(vUser); if (vUser.Password != null && !vUser.IsNoEncryptPassword) { vUser.Password = StringManage.EncryptPassword(vUser.Password); } if (vUser.UserType == 1) { vUser.OrganizationIds = new List <UserPositionDto>(); vUser.OrganizationIds.Add(new UserPositionDto { OrganizationId = IocUnity.Get <RepositoryOrganization>().GetOrganizationId("非机构", vUser.SystemCode, "APP"), OrganizationName = "APP" }); } else if (vUser.UserType == 2 || vUser.UserType == 4) { vUser.OrganizationIds = new List <UserPositionDto>(); vUser.OrganizationIds.Add(new UserPositionDto { OrganizationId = IocUnity.Get <RepositoryOrganization>().GetOrganizationId("非机构", vUser.SystemCode, "微信"), OrganizationName = "微信" }); } else if (vUser.UserType == 3) { vUser.OrganizationIds = new List <UserPositionDto>(); vUser.OrganizationIds.Add(new UserPositionDto { OrganizationId = IocUnity.Get <RepositoryOrganization>().GetOrganizationId("非机构", vUser.SystemCode, "QQ"), OrganizationName = "QQ" }); } vUser.OrganizationIds = CompleteUserPositionDto(vUser.OrganizationIds); TUser user = AutoMapperExtensions.MapTo <TUser>(vUser); Dictionary <string, object> keyValuePairs = new Dictionary <string, object>(); if (vUser.ExtendAttribution != null) { foreach (KeyValueItem keyValue in vUser.ExtendAttribution) { keyValuePairs.Add(keyValue.Key, keyValue.Value); } } user.ExtendAttribution = SerializationUtility.ObjectToJson(keyValuePairs); if (string.IsNullOrEmpty(user.Id)) { user.Id = IdentityHelper.NewSequentialGuid().ToString("N"); } if (string.IsNullOrEmpty(user.SystemId) && !string.IsNullOrEmpty(user.SystemCode)) { user.SystemId = IocUnity.Get <RepositorySystem>().GetId(user.SystemCode); } if (!string.IsNullOrEmpty(user.SystemId) && string.IsNullOrEmpty(user.SystemCode)) { user.SystemCode = IocUnity.Get <RepositorySystem>().GetCode(user.SystemId); } IList <TRelationUserOrganization> relationUserPositions = new List <TRelationUserOrganization>(); if (vUser.OrganizationIds != null) { foreach (UserPositionDto od in vUser.OrganizationIds) { TRelationUserOrganization relationUserOrganization = AutoMapperExtensions.MapTo <TRelationUserOrganization>(od); relationUserOrganization.Id = IdentityHelper.NewSequentialGuid().ToString("N"); relationUserOrganization.UserId = user.Id; if (!string.IsNullOrEmpty(relationUserOrganization.OrganizationId) && !string.IsNullOrEmpty(relationUserOrganization.DepartmentId) && !string.IsNullOrEmpty(relationUserOrganization.PositionId)) { relationUserOrganization.OrganizationIdO = relationUserOrganization.PositionId; } else if (!string.IsNullOrEmpty(relationUserOrganization.OrganizationId) && !string.IsNullOrEmpty(relationUserOrganization.DepartmentId) && string.IsNullOrEmpty(relationUserOrganization.PositionId)) { relationUserOrganization.OrganizationIdO = relationUserOrganization.DepartmentId; } else if (!string.IsNullOrEmpty(relationUserOrganization.OrganizationId) && string.IsNullOrEmpty(relationUserOrganization.DepartmentId) && string.IsNullOrEmpty(relationUserOrganization.PositionId)) { relationUserOrganization.OrganizationIdO = relationUserOrganization.OrganizationId; } else if (!string.IsNullOrEmpty(relationUserOrganization.OrganizationId) && string.IsNullOrEmpty(relationUserOrganization.DepartmentId) && !string.IsNullOrEmpty(relationUserOrganization.PositionId)) { relationUserOrganization.OrganizationIdO = relationUserOrganization.PositionId; } relationUserPositions.Add(relationUserOrganization); } } IocUnity.Get <RepositoryUser>().DapperRepository.ExcuteTransaction(tranc => { IocUnity.Get <RepositoryUser>().Insert(user); IocUnity.Get <RepositoryRelationUserOrganization>().Insert(relationUserPositions); }); return(user.Id); }
/// <summary> /// /// </summary> /// <param name="userUpdateDto"></param> /// <returns></returns> public int UpdateUser(UserUpdateDto userUpdateDto) { userUpdateDto = StringManage.EmptyStringSetNull(userUpdateDto); if (userUpdateDto.UserType == 1) { userUpdateDto.OrganizationIds = new List <UserPositionDto> { new UserPositionDto { OrganizationId = IocUnity.Get <RepositoryOrganization>().GetOrganizationId("非机构", IocUnity.Get <RepositoryUser>().GetUserSystemCode(userUpdateDto.Id), "APP"), OrganizationName = "APP" } }; } else if (userUpdateDto.UserType == 2) { userUpdateDto.OrganizationIds = new List <UserPositionDto> { new UserPositionDto { OrganizationId = IocUnity.Get <RepositoryOrganization>().GetOrganizationId("非机构", IocUnity.Get <RepositoryUser>().GetUserSystemCode(userUpdateDto.Id), "微信"), OrganizationName = "微信" } }; } else if (userUpdateDto.UserType == 3) { userUpdateDto.OrganizationIds = new List <UserPositionDto> { new UserPositionDto { OrganizationId = IocUnity.Get <RepositoryOrganization>().GetOrganizationId("非机构", IocUnity.Get <RepositoryUser>().GetUserSystemCode(userUpdateDto.Id), "QQ"), OrganizationName = "QQ" } }; } userUpdateDto.OrganizationIds = CompleteUserPositionDto(userUpdateDto.OrganizationIds); TUserUpdate user = userUpdateDto.MapTo <TUserUpdate>(); Dictionary <string, object> keyValuePairs = new Dictionary <string, object>(); if (userUpdateDto.ExtendAttribution != null) { foreach (KeyValueItem keyValue in userUpdateDto.ExtendAttribution) { keyValuePairs.Add(keyValue.Key, keyValue.Value); } } user.ExtendAttribution = SerializationUtility.ObjectToJson(keyValuePairs); IList <TRelationUserOrganization> relationUserPositions = new List <TRelationUserOrganization>(); if (userUpdateDto.OrganizationIds != null) { foreach (UserPositionDto od in userUpdateDto.OrganizationIds) { TRelationUserOrganization relationUserOrganization = od.MapTo <TRelationUserOrganization>(); relationUserOrganization.Id = IdentityHelper.NewSequentialGuid().ToString("N"); relationUserOrganization.UserId = user.Id; if (relationUserOrganization.OrganizationId != null && relationUserOrganization.DepartmentId != null && relationUserOrganization.PositionId != null) { relationUserOrganization.OrganizationIdO = relationUserOrganization.PositionId; } else if (relationUserOrganization.OrganizationId != null && relationUserOrganization.DepartmentId != null && relationUserOrganization.PositionId == null) { relationUserOrganization.OrganizationIdO = relationUserOrganization.DepartmentId; } else if (relationUserOrganization.OrganizationId != null && relationUserOrganization.DepartmentId == null && relationUserOrganization.PositionId == null) { relationUserOrganization.OrganizationIdO = relationUserOrganization.OrganizationId; } relationUserPositions.Add(relationUserOrganization); } } int count = 0; IocUnity.Get <RepositoryUser>().DapperRepository.ExcuteTransaction(tranc => { IocUnity.Get <RepositoryRelationUserOrganization>().DeleteUserOrganization(userUpdateDto.Id); IocUnity.Get <RepositoryRelationUserOrganization>().Insert(relationUserPositions); count = IocUnity.Get <RepositoryUser>().UpdateUser(user); }); return(count); }