Exemplo n.º 1
0
    /// <summary>
    /// Tries to add a song director.
    /// </summary>
    /// <param name="request">The add song director request.</param>
    /// <returns>The result of the request.</returns>
    private async Task <TOutput> TryAddSongDirector(AddSongDirectorRequest request)
    {
        // Validate the new song director
        Result <SongDirector> createSongDirectorResult = SongDirector.TryCreate(
            request.FullName,
            request.EmailAddress,
            request.PhoneNumber,
            request.RankName,
            request.IsActive);

        // Validation failure
        if (createSongDirectorResult.IsFailed)
        {
            return(ValidationFailure(createSongDirectorResult));
        }

        SongDirector songDirector = createSongDirectorResult.Value;

        // Add the song director
        Result <SongDirector> addSongDirectorResult = await _songDirectorRepository
                                                      .TryAddAsync(songDirector)
                                                      .ConfigureAwait(false);

        if (addSongDirectorResult.IsFailed)
        {
            return(FailedToAddSongDirector(addSongDirectorResult));
        }

        SongDirectorUseCaseModel addedSongDirector = SongDirectorUseCaseModel
                                                     .GrandmasterView(songDirector);

        return(SongDirectorAdded(addedSongDirector));
    }
Exemplo n.º 2
0
        /// <summary>
        /// Converts a song director to a model.
        /// </summary>
        /// <param name="songDirector">The song director to convert.</param>
        /// <param name="requesterId">Requester id.</param>
        /// <param name="requesterRank">Requester rank.</param>
        /// <returns><see cref="SongDirectorUseCaseModel"/>.</returns>
        public static SongDirectorUseCaseModel ConvertToUseCaseModel(
            this SongDirector songDirector, string?requesterId, Rank?requesterRank)
        {
            if (songDirector.Id == requesterId)
            {
                return(SongDirectorUseCaseModel.Self(songDirector, requesterRank));
            }

            if (requesterRank == Rank.Grandmaster)
            {
                return(SongDirectorUseCaseModel.GrandmasterView(songDirector));
            }

            return(SongDirectorUseCaseModel.ReadOnly(songDirector));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Returns output indicating that a song director was added.
 /// </summary>
 /// <param name="addedSongDirector">The added song director.</param>
 /// <returns>The output.</returns>
 private TOutput SongDirectorAdded(SongDirectorUseCaseModel addedSongDirector)
 {
     return(_boundary.SongDirectorAdded(
                AddSongDirectorResponse.SongDirectorAdded(addedSongDirector)));
 }