Example #1
0
        public async Task <IActionResult> Create(
            string artistSlug)
        {
            string userId = User
                            .GetUserId()
                            .ToString();

            ArtistViewModel artist = await _artistsService
                                     .GetArtistDetailsAsync(artistSlug, userId);

            CreateLyricViewModel viewModel = new CreateLyricViewModel();

            viewModel.Artist = artist;

            return(View(viewModel));
        }
Example #2
0
        public async Task <ArtistLyricsViewModel> GetLyricsAsync(
            string artistSlug,
            string userId)
        {
            ArtistLyricsViewModel viewModel = new ArtistLyricsViewModel();

            ArtistViewModel artistViewModel = await _artistsService
                                              .GetArtistDetailsAsync(artistSlug, userId);

            if (artistViewModel != null)
            {
                string sqlCommand = "select l.title as lyric_title, lslugs.name as lyric_slug, l.is_approved, l.is_verified from lyrics as l inner join lyric_slugs as lslugs on lslugs.lyric_id = l.id where case when @user_id <> '' then l.user_id = @user_id or l.is_approved = true else l.is_approved = true end and artist_id = @artist_id and l.is_deleted = false and lslugs.is_primary = true order by l.title asc;";

                List <LyricCardViewModel> lyricCardViewModels = new List <LyricCardViewModel>();

                await using NpgsqlConnection connection = new NpgsqlConnection(_databaseOptions.ConnectionString);
                await connection.OpenAsync();

                await using NpgsqlCommand command = new NpgsqlCommand(sqlCommand, connection);

                command.Parameters.AddWithValue("@user_id", userId);
                command.Parameters.AddWithValue("@artist_id", artistViewModel.Id);

                await using NpgsqlDataReader reader = await command.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    while (await reader.ReadAsync())
                    {
                        LyricCardViewModel lyricCardViewModel = new LyricCardViewModel();

                        string title       = Convert.ToString(reader[0]);
                        string primarySlug = Convert.ToString(reader[1]);
                        bool   isApproved  = Convert.ToBoolean(reader[2]);
                        bool   isVerified  = Convert.ToBoolean(reader[3]);

                        lyricCardViewModel.Title = title;
                        lyricCardViewModel.Slug  = primarySlug;
                        lyricCardViewModel.IsAwaitingApproval = !isApproved;
                        lyricCardViewModel.IsVerified         = isVerified;

                        lyricCardViewModels.Add(lyricCardViewModel);
                    }

                    viewModel.LyricCount = lyricCardViewModels.Count == 1 ? "1 Lyric" : $"{lyricCardViewModels.Count} Lyrics";
                    viewModel.Lyrics     = lyricCardViewModels;
                }
                else
                {
                    viewModel.Lyrics     = new List <LyricCardViewModel>();
                    viewModel.LyricCount = "0 Lyrics";
                }

                viewModel.Artist = artistViewModel;
            }
            else
            {
                viewModel = null;
            }

            return(viewModel);
        }