public async Task <IActionResult> GetOwnershipStatus(int id) { try{ DbUser usr = await this._userManager.GetUserAsync(this.User); if (usr != null) { UserAlbumOwnershipStatus status = await _repository.GetAlbumOwnershipStatusForUser(id, usr.Id, PublishStatus.PUBLISHED); if (status != null) { return(Ok(status)); } else { return(NotFound(new ApiErrorRep($"Album with ID {id} was nto found"))); } } else { return(Unauthorized()); } }catch (RepositoryException e) { return(BadRequest(new ApiErrorRep(e.Message))); }catch (Exception e) { _logger.LogError("GetArtist", e, "Error getting album"); return(StatusCode(500, new ApiErrorRep("Unknown error"))); } }
public async Task <UserAlbumOwnershipStatus> GetAlbumOwnershipStatusForUser(int albumId, string userId, PublishStatus statusFlags) { UserAlbumOwnershipStatus result = new UserAlbumOwnershipStatus(); var dbRecord = await _context.UserAlbums.SingleOrDefaultAsync(x => x.UserId == userId && x.AlbumId == albumId); if (dbRecord != null) { result.PurchaseDate = dbRecord.CreatedUtc; result.IsOwned = true; } return(result); }