Beispiel #1
0
        public int SaveFavoriteAlbum(Entities.Album album, int userId)
        {
            int favoriteAlbumId;

            const string queryString =
                @"IF NOT EXISTS 
			(SELECT  [Id]
			FROM [dbo].[FavoriteAlbum]
			WHERE [Name] = @AlbumName AND [ArtistName] = @ArtistName AND [UserId] = @UserId)
			BEGIN
				INSERT  INTO [dbo].[FavoriteAlbum] ([Name], [ArtistName], [Url], [Image], [UserId]) 
				OUTPUT INSERTED.ID
				VALUES (@AlbumName, @ArtistName, @Url, @Image, @UserId)
			END; "            ;

            string imageUrl;
            var    image = System.Array.Find(album.Image, i => string.Equals(i.Size, LargeImageSize));

            if (image != null)
            {
                imageUrl = image.Text;
            }
            else
            {
                image    = album.Image.FirstOrDefault();
                imageUrl = image?.Text;
            }

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                using (SqlCommand command = new SqlCommand(queryString, connection))
                {
                    command.Parameters.AddWithValue("@AlbumName", album.Name);
                    command.Parameters.AddWithValue("@ArtistName", album.Artist);
                    command.Parameters.AddWithValue("@Url", album.Url);
                    command.Parameters.AddWithValue("@Image", imageUrl);
                    command.Parameters.AddWithValue("@UserId", userId);
                    connection.Open();

                    favoriteAlbumId = (int)command.ExecuteScalar();

                    connection.Close();
                }
            }

            return(favoriteAlbumId);
        }
 public int SaveFavoriteAlbum(Entities.Album album, int userId) =>
 _sqlFavoriteAlbumRepository.SaveFavoriteAlbum(album, userId);
Beispiel #3
0
 public int SaveFavoriteAlbum(Entities.Album album, int userId)
 {
     throw new System.NotImplementedException();
 }