|
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authorization; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Authorization; |
|
|
|
using Volo.Abp.BlobStoring; |
|
|
|
using Volo.Abp.Content; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.Identity; |
|
|
|
using Volo.Abp.Users; |
|
|
|
@ -52,12 +53,12 @@ namespace EventHub.Organizations |
|
|
|
organization.FacebookUsername = input.FacebookUsername; |
|
|
|
organization.InstagramUsername = input.InstagramUsername; |
|
|
|
organization.MediumUsername = input.MediumUsername; |
|
|
|
|
|
|
|
|
|
|
|
await _organizationRepository.InsertAsync(organization, true); |
|
|
|
|
|
|
|
if (input.ProfilePictureContent != null && input.ProfilePictureContent.Length > 0) |
|
|
|
|
|
|
|
if (input.ProfilePictureStreamContent != null && input.ProfilePictureStreamContent.ContentLength > 0) |
|
|
|
{ |
|
|
|
await SaveProfilePictureAsync(organization.Id, input.ProfilePictureContent); |
|
|
|
await SaveProfilePictureAsync(organization.Id, input.ProfilePictureStreamContent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -67,13 +68,13 @@ namespace EventHub.Organizations |
|
|
|
var organizationMemberQueryable = await _organizationMembershipsRepository.GetQueryableAsync(); |
|
|
|
|
|
|
|
var query = organizationQueryable; |
|
|
|
|
|
|
|
|
|
|
|
if (input.RegisteredUserId.HasValue) |
|
|
|
{ |
|
|
|
var registeredOrganization = organizationMemberQueryable |
|
|
|
.Where(x => x.UserId == input.RegisteredUserId) |
|
|
|
.Select(x => x.OrganizationId); |
|
|
|
|
|
|
|
|
|
|
|
var organizationIds = await AsyncExecuter.ToListAsync(registeredOrganization); |
|
|
|
query = query.Where(x => organizationIds.Contains(x.Id)); |
|
|
|
} |
|
|
|
@ -84,11 +85,6 @@ namespace EventHub.Organizations |
|
|
|
|
|
|
|
var organizationDto = ObjectMapper |
|
|
|
.Map<List<Organization>, List<OrganizationInListDto>>(await AsyncExecuter.ToListAsync(query)); |
|
|
|
|
|
|
|
foreach (var organization in organizationDto) |
|
|
|
{ |
|
|
|
organization.ProfilePictureContent = await GetProfilePictureAsync(organization.Id); |
|
|
|
} |
|
|
|
|
|
|
|
return new PagedResultDto<OrganizationInListDto>( |
|
|
|
totalCount, |
|
|
|
@ -104,7 +100,6 @@ namespace EventHub.Organizations |
|
|
|
var owner = await _userRepository.GetAsync(u => u.Id == organization.OwnerUserId); |
|
|
|
organizationProfileDto.OwnerUserName = owner.UserName; |
|
|
|
organizationProfileDto.OwnerEmail = owner.Email; |
|
|
|
organizationProfileDto.ProfilePictureContent = await GetProfilePictureAsync(organizationProfileDto.Id); |
|
|
|
|
|
|
|
return organizationProfileDto; |
|
|
|
} |
|
|
|
@ -116,17 +111,13 @@ namespace EventHub.Organizations |
|
|
|
|
|
|
|
var organizationDto = ObjectMapper.Map<List<Organization>, List<OrganizationInListDto>>(organizations); |
|
|
|
|
|
|
|
foreach (var organization in organizationDto) |
|
|
|
{ |
|
|
|
organization.ProfilePictureContent = await GetProfilePictureAsync(organization.Id); |
|
|
|
} |
|
|
|
|
|
|
|
return new ListResultDto<OrganizationInListDto>(organizationDto); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<bool> IsOrganizationOwnerAsync(Guid organizationId) |
|
|
|
{ |
|
|
|
return CurrentUser.Id.HasValue && await _organizationRepository.AnyAsync(x => x.Id == organizationId && x.OwnerUserId == CurrentUser.Id.Value); |
|
|
|
return CurrentUser.Id.HasValue && await _organizationRepository |
|
|
|
.AnyAsync(x => x.Id == organizationId && x.OwnerUserId == CurrentUser.Id.Value); |
|
|
|
} |
|
|
|
|
|
|
|
[Authorize] |
|
|
|
@ -148,35 +139,34 @@ namespace EventHub.Organizations |
|
|
|
organization.InstagramUsername = input.InstagramUsername; |
|
|
|
organization.FacebookUsername = input.FacebookUsername; |
|
|
|
organization.MediumUsername = input.MediumUsername; |
|
|
|
|
|
|
|
if (input.ProfilePictureContent != null && input.ProfilePictureContent.Length > 0) |
|
|
|
|
|
|
|
if (input.ProfilePictureStreamContent != null && input.ProfilePictureStreamContent.ContentLength > 0) |
|
|
|
{ |
|
|
|
await SaveProfilePictureAsync(organization.Id, input.ProfilePictureContent); |
|
|
|
await SaveProfilePictureAsync(organization.Id, input.ProfilePictureStreamContent); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await _organizationRepository.UpdateAsync(organization); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SaveProfilePictureAsync(Guid id, byte[] bytes) |
|
|
|
|
|
|
|
public async Task<IRemoteStreamContent> GetProfilePictureAsync(Guid id) |
|
|
|
{ |
|
|
|
var organization = await _organizationRepository.GetAsync(x => x.Id == id); |
|
|
|
var blobName = id.ToString(); |
|
|
|
|
|
|
|
var pictureContent = await _organizationBlobContainer.GetOrNullAsync(blobName); |
|
|
|
|
|
|
|
if (organization.OwnerUserId != CurrentUser.GetId()) |
|
|
|
if (pictureContent is null) |
|
|
|
{ |
|
|
|
throw new AbpAuthorizationException(EventHubErrorCodes.NotAuthorizedToUpdateOrganizationProfile) |
|
|
|
.WithData("Name", organization.DisplayName); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
var blobName = id.ToString(); |
|
|
|
|
|
|
|
await _organizationBlobContainer.SaveAsync(blobName, bytes, overrideExisting: true); |
|
|
|
|
|
|
|
return new RemoteStreamContent(pictureContent, blobName); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<byte[]> GetProfilePictureAsync(Guid id) |
|
|
|
private async Task SaveProfilePictureAsync(Guid id, IRemoteStreamContent streamContent) |
|
|
|
{ |
|
|
|
var blobName = id.ToString(); |
|
|
|
|
|
|
|
return await _organizationBlobContainer.GetAllBytesOrNullAsync(blobName); |
|
|
|
await _organizationBlobContainer.SaveAsync(blobName, streamContent.GetStream(), overrideExisting: true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |