示例#1
0
        public IActionResult Post([FromBody] SongDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = _songService.CreateSong(dto);

            return(Ok(new { id }));
        }
示例#2
0
 public async Task <Response <int> > CreateSong([FromBody] SongViewModel model)
 {
     return(await RequestHandler.ExecuteRequestAsync(async() =>
     {
         var songModel = new Song()
         {
             State = model.State,
             Name = model.Name,
             Genre = model.Genre,
             Band = model.Band,
             Url = model.Url
         };
         return await _songService.CreateSong(songModel);
     }));
 }
 public ActionResult <SongModel> CreateSong([FromBody] SongModel song)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         var newSong = service.CreateSong(song);
         return(Created($"api/songs/{newSong.Id}", newSong));
     }
     catch (BadOperationRequest ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
        public void Init()
        {
            _interpret1 = new InterpretDTO
            {
                Name     = "System of a down",
                Language = Language.English,
                ID       = 1,
                IsPublic = false
            };

            _interpret2 = new InterpretDTO
            {
                Name     = "Linkin Park",
                Language = Language.English,
                ID       = 2,
                IsPublic = false
            };

            _interpretService.CreateInterpret(_interpret1);
            _interpretService.CreateInterpret(_interpret2);

            _album1Id = 1;
            _album1   = new AlbumDTO
            {
                ID          = _album1Id,
                InterpretId = 1,
                Name        = "Toxicity",
                Year        = 2001
            };

            _album2Id = 2;
            _album2   = new AlbumDTO
            {
                ID          = _album2Id,
                InterpretId = 2,
                Name        = "Meteora",
                Year        = 2003
            };
            _albumService.CreateAlbum(_album1, _interpret1.ID);
            _albumService.CreateAlbum(_album2, _interpret2.ID);

            _song1Id = 1;
            _song1   = new SongDTO
            {
                ID       = _song1Id,
                Name     = "Prison Song",
                Added    = new DateTime(2016, 11, 6),
                AlbumId  = _album1Id,
                Genre    = Genre.Rock,
                IsPublic = false
            };

            _song2Id = 2;
            _song2   = new SongDTO
            {
                ID       = _song2Id,
                Name     = "Deer Dance",
                Added    = new DateTime(2016, 11, 6),
                AlbumId  = _album1Id,
                Genre    = Genre.Rock,
                IsPublic = false
            };

            _song3Id = 3;
            _song3   = new SongDTO
            {
                ID       = _song3Id,
                Name     = "Numb",
                Added    = new DateTime(2016, 11, 6),
                AlbumId  = _album2Id,
                Genre    = Genre.Rock,
                IsPublic = false
            };

            _songService.CreateSong(_song1, _album1Id);
            _songService.CreateSong(_song2, _album1Id);
            _songService.CreateSong(_song3, _album2Id);
        }
示例#5
0
        /// <summary>
        /// Creates a song with an album that corresponds with given name
        /// </summary>
        /// <param name="song">songDTO</param>
        /// <param name="albumName">album name</param>
        public void CreateSongWithAlbumName(SongDTO song, string albumName)
        {
            var albumId = albumService.GetAlbumIdByName(albumName);

            songService.CreateSong(song);
        }
示例#6
0
        public void Init()
        {
            _interpret1Id = 1;
            _interpret1   = new InterpretDTO
            {
                Name     = "System of a down",
                Language = Language.English,
                ID       = _interpret1Id
            };

            _interpret2Id = 2;
            _interpret2   = new InterpretDTO
            {
                Name     = "Linkin Park",
                Language = Language.English,
                ID       = _interpret2Id
            };

            _interpretService.CreateInterpret(_interpret1);
            _interpretService.CreateInterpret(_interpret2);

            _album1Id = 1;
            _album1   = new AlbumDTO
            {
                ID          = _album1Id,
                InterpretId = 1,
                Name        = "Toxicity",
                Year        = 2001
            };

            _album2Id = 2;
            _album2   = new AlbumDTO
            {
                ID          = _album2Id,
                InterpretId = 2,
                Name        = "Meteora",
                Year        = 2003
            };
            _albumService.CreateAlbum(_album1, _interpret1.ID);
            _albumService.CreateAlbum(_album2, _interpret2.ID);

            _song1Id = 1;
            _song1   = new SongDTO
            {
                ID      = _song1Id,
                Name    = "Prison Song",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album1Id,
                Genre   = Genre.Rock
            };

            _song2Id = 2;
            _song2   = new SongDTO
            {
                ID      = _song2Id,
                Name    = "Deer Dance",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album1Id,
                Genre   = Genre.Rock
            };

            _song3Id = 3;
            _song3   = new SongDTO
            {
                ID      = _song3Id,
                Name    = "Numb",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album2Id,
                Genre   = Genre.Rock
            };

            _songService.CreateSong(_song1, _album1Id);
            _songService.CreateSong(_song2, _album1Id);
            _songService.CreateSong(_song3, _album2Id);

            _songReview1Id = 1;
            _songReview1   = new SongReviewDTO
            {
                ID     = _songReview1Id,
                SongId = _song1.ID,
                Note   = "Perfect album",
                Rating = 9
            };

            _songReview2Id = 2;
            _songReview2   = new SongReviewDTO
            {
                SongId = _song2.ID,
                Note   = "Not bad",
                Rating = 8,
                ID     = _songReview2Id
            };

            _songReviewService.CreateSongReview(_songReview1, _song1Id);
            _songReviewService.CreateSongReview(_songReview2, _song2Id);
        }
示例#7
0
 public int CreateSong(SongDTO songDto, int albumId)
 {
     return(_songService.CreateSong(songDto, albumId));
 }
示例#8
0
        private static void TestSongService()
        {
            List <int> list = new List <int>();

            songService   = Container.Resolve <ISongService>();
            clientService = Container.Resolve <IClientService>();

            //Create
            songService.CreateSong(new SongDTO
            {
                Name       = "Hit The Floor",
                AlbumID    = albumID,
                CreatorID  = clientID,
                Duration   = new TimeSpan(0, 0, 3, 30),
                IsOfficial = true,
            });
            songService.CreateSong(new SongDTO
            {
                Name       = "4 Words",
                AlbumID    = albumID,
                CreatorID  = clientID,
                Duration   = new TimeSpan(0, 0, 3, 43),
                IsOfficial = true,
            });
            songService.CreateSong(new SongDTO
            {
                Name       = "All These Things I Hate",
                AlbumID    = albumID,
                CreatorID  = clientID2,
                Duration   = new TimeSpan(0, 0, 3, 45),
                IsOfficial = true,
            });


            //GetSongIdByName
            songID = songService.GetSongIdByName("Hit The Floor");
            int wordsID = songService.GetSongIdByName("4 Words");

            songID2 = songService.GetSongIdByName("All These Things I Hate");
            list.Add(songID);
            list.Add(wordsID);
            list.Add(songID2);
            Console.WriteLine(list.Count() == 3 ? "ClientService - GetSongIdByName - OK" : "ClientService - GetSongIdByName - FAIL");

            //GetSongById
            SongDTO floor  = songService.GetSong(songID);
            SongDTO words4 = songService.GetSong(wordsID);
            SongDTO hate   = songService.GetSong(songID2);

            Console.WriteLine(floor.Name == "Hit The Floor" ? "SongService - GetSongById - OK" : "SongService - GetSongById - FAIL");

            albumService = Container.Resolve <IAlbumService>();

            //AddSong
            songService.AddSong(floor);
            songService.AddSong(words4);
            songService.AddSong(hate);
            AlbumDTO album = albumService.GetAlbum(albumID);

            Console.WriteLine(album.SongIDs.Contains(songID) ?
                              "SongService - AddSong - OK" : "SongService - AddSong - FAIL");

            //GetAlbumOfSong
            AlbumDTO album2 = songService.GetAlbumOfSong(songID);

            Console.WriteLine(album2.ID == albumID ?
                              "SongService - GetAlbumOfSong - OK" : "SongService - GetAlbumOfSong - FAIL");

            //TestAlbumServisGetAllSongs
            Console.WriteLine(album.SongIDs.Count() == 3 ?
                              "AlbumService - TestAlbumServisGetAllSongs - OK" : "AlbumService - TestAlbumServisGetAllSongs - FAIL");

            ////ListAllSongs
            //var songs = songService.ListAllSongs(new SongFilter { AlbumID = albumID }, 1);
            //Console.WriteLine(songs.TotalResultCount == 3 ? "SongService - TestListAllSongs - OK" : "SongService - TestListAllSongs - FAIL");

            //ListAllSongss02
            var songs2 = songService.ListAllSongs();

            Console.WriteLine(songs2.Count() == 3 ? "SongService - ListAllSongss02 - OK" : "SongService - ListAllSongss02 - FAIL");

            //EditSong
            words4.Name = "Four Words";
            songService.EditSong(words4, albumID, words4.ReviewIDs);
            SongDTO words4FromDB = songService.GetSong(words4.ID);

            Console.WriteLine(words4FromDB.Name == "Four Words" ? "SongService - TestEditSong - OK" : "SongService - TestEditSong - FAIL");

            //DeleteSong
            songService.DeleteSong(wordsID);
            try {
                SongDTO wordsFromDB = songService.GetSong(wordsID);
                Console.WriteLine("SongService - TestDeleteSong - FAIL");
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("SongService - TestDeleteSong - OK");
            }

            //GetCreator
            ClientDTO creator = genreService.GetCreator(floor.ID);

            Console.WriteLine(creator.ID == clientID ? "SongService - GetCreator - OK" : "SongService - GetCreator - FAIL");
        }
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var song = new Song()
            {
                name        = Name.Text,
                description = Description.Text,
                author      = Author.Text,
                singer      = Single.Text,
                thumbnail   = Thumbnail.Text,
                link        = Link.Text
            };
            Dictionary <String, String> err = song.Validate();

            if (err.Count == 0)
            {
                songService.CreateSong(song, UserInformation._token);
                this.Frame.Navigate(typeof(MySong));
            }
            else
            {
                if (err.ContainsKey("name"))
                {
                    NameMessage.Text       = err["name"];
                    NameMessage.Visibility = Visibility.Visible;
                }
                else
                {
                    NameMessage.Visibility = Visibility.Collapsed;
                }
                if (err.ContainsKey("description"))
                {
                    DescriptionMessage.Text       = err["description"];
                    DescriptionMessage.Visibility = Visibility.Visible;
                }
                else
                {
                    DescriptionMessage.Visibility = Visibility.Collapsed;
                }
                if (err.ContainsKey("thumbnail"))
                {
                    ThumbnailMessage.Text       = err["thumbnail"];
                    ThumbnailMessage.Visibility = Visibility.Visible;
                }
                else
                {
                    ThumbnailMessage.Visibility = Visibility.Collapsed;
                }
                if (err.ContainsKey("single"))
                {
                    SingleMessage.Text       = err["single"];
                    SingleMessage.Visibility = Visibility.Visible;
                }
                else
                {
                    Single.Visibility = Visibility.Collapsed;
                }
                if (err.ContainsKey("author"))
                {
                    AuthorMessage.Text       = err["author"];
                    AuthorMessage.Visibility = Visibility.Visible;
                }
                else
                {
                    AuthorMessage.Visibility = Visibility.Collapsed;
                }
                if (err.ContainsKey("link"))
                {
                    LinkMeesaga.Text       = err["link"];
                    LinkMeesaga.Visibility = Visibility.Visible;
                }
                else
                {
                    LinkMeesaga.Visibility = Visibility.Collapsed;
                }
            }
        }
        public void Init()
        {
            var guid = _userAccountService.CreateAccount("Martin", "Password", "*****@*****.**");

            _userService.CreateUser(guid.ID);

            _playlist1Id = 1;
            _playlist1   = new PlaylistDTO
            {
                Name    = "Favorite songs",
                Created = new DateTime(2016, 10, 10),
                ID      = _playlist1Id,
                UserId  = 1
            };

            _playlist2Id = 2;
            _playlist2   = new PlaylistDTO
            {
                Name    = "Best songs",
                Created = new DateTime(2016, 1, 1),
                ID      = _playlist2Id,
                UserId  = 1
            };

            _playlistService.CreatePlaylist(_playlist1, 1);
            _playlistService.CreatePlaylist(_playlist2, 1);

            _interpret1 = new InterpretDTO
            {
                Name     = "System of a down",
                Language = Language.English,
                ID       = 1
            };

            _interpret2 = new InterpretDTO
            {
                Name     = "Linkin Park",
                Language = Language.English,
                ID       = 2
            };

            _interpretService.CreateInterpret(_interpret1);
            _interpretService.CreateInterpret(_interpret2);

            _album1Id = 1;
            _album1   = new AlbumDTO
            {
                ID          = _album1Id,
                InterpretId = 1,
                Name        = "Toxicity",
                Year        = 2001
            };

            _album2Id = 2;
            _album2   = new AlbumDTO
            {
                ID          = _album2Id,
                InterpretId = 2,
                Name        = "Meteora",
                Year        = 2003
            };
            _albumService.CreateAlbum(_album1, _interpret1.ID);
            _albumService.CreateAlbum(_album2, _interpret2.ID);

            _song1Id = 1;
            _song1   = new SongDTO
            {
                ID      = _song1Id,
                Name    = "Prison Song",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album1Id,
                Genre   = Genre.Rock
            };

            _song2Id = 2;
            _song2   = new SongDTO
            {
                ID      = _song2Id,
                Name    = "Deer Dance",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album1Id,
                Genre   = Genre.Rock
            };

            _song3Id = 3;
            _song3   = new SongDTO
            {
                ID      = _song3Id,
                Name    = "Numb",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album2Id,
                Genre   = Genre.Rock
            };

            _songService.CreateSong(_song1, _album1Id);
            _songService.CreateSong(_song2, _album1Id);
            _songService.CreateSong(_song3, _album2Id);

            _songlist1Id = 1;
            _songList1   = new SongListDTO
            {
                ID         = _songlist1Id,
                PlaylistId = _playlist1Id,
                SongId     = _song1Id
            };

            _songlist2Id = 2;
            _songList2   = new SongListDTO
            {
                ID         = _songlist2Id,
                PlaylistId = _playlist1Id,
                SongId     = _song2Id
            };

            _songlist3Id = 3;
            _songList3   = new SongListDTO
            {
                ID         = _songlist3Id,
                PlaylistId = _playlist2Id,
                SongId     = _song3Id
            };

            _songlistService.CreateSonglist(_songList1, _song1Id, _playlist1Id);
            _songlistService.CreateSonglist(_songList2, _song1Id, _playlist1Id);
            _songlistService.CreateSonglist(_songList3, _song1Id, _playlist2Id);
        }