public async Task <IActionResult> Update([FromForm] UpdateCommunity input) { var token = GetToken(); var userId = LoginHelper.GetClaim(token, "UserId"); if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(userId)) { return(Unauthorized()); } input.ModeratorId = Guid.Parse(userId); var result = await _communityAppService.Update(input); return(Ok(result)); }
public async Task <Community> Update(UpdateCommunity input) { var isAdmin = await _communityUserRepository.GetAll() .FirstOrDefaultAsync(x => x.IsDeleted == false && x.IsAdmin && x.UserId == input.ModeratorId && x.Community.Slug == input.Slug); if (isAdmin == null) { throw new Exception("Bu kullanıcının yetkisi yok"); } var community = await _communityRepository.GetByIdAsync(isAdmin.CommunityId); if (input.Name != null) { community.Name = input.Name; } if (input.Description != null) { community.Description = input.Description; } if (input.Logo != null) { var path = await _blobService.InsertFile(input.Logo); community.LogoPath = path; } if (input.CoverPhoto != null) { var path = await _blobService.InsertFile(input.CoverPhoto); community.CoverImagePath = path; } await _communityRepository.UpdateAsync(community); return(community); }