Esempio n. 1
0
        public void CreateSonglist(SonglistDTO songlistDTO)
        {
            if (songlistDTO == null)
            {
                throw new ArgumentNullException("Songlist Service - CreateSonglist(...) songlistDTO cannot be null");
            }

            Songlist songlist = Mapper.Map <Songlist>(songlistDTO);

            using (var uow = UnitOfWorkProvider.Create())
            {
                if (songlistDTO.SongIDs != null)
                {
                    foreach (int ID in songlistDTO.SongIDs)
                    {
                        if (songlist.Songs == null)
                        {
                            songlist.Songs = new List <Song>();
                        }
                        Song song = GetSonglistSong(ID);
                        songlist.Songs.Add(song);
                    }
                }

                songlist.Owner = GetSonglistCreator(songlistDTO.OwnerID);

                songlistRepository.Insert(songlist);
                uow.Commit();
            }
        }
Esempio n. 2
0
        public void EditSonglist(SonglistDTO songlistDTO, List <int> songIds)
        {
            if (songlistDTO == null)
            {
                throw new ArgumentNullException("Songlist Service - EditSonglist(...) songlistDTO cannot be null");
            }

            using (var uow = UnitOfWorkProvider.Create())
            {
                var songlist = songlistRepository.GetByID(songlistDTO.ID);

                if (songIds != null && songIds.Any())
                {
                    var songs = songRepository.GetByIDs(songIds);
                    songlist.Songs.RemoveAll(song => !songs.Contains(song));
                    songlist.Songs.AddRange(
                        songs.Where(song => !songlist.Songs.Contains(song)));
                }
                else
                {
                    songlist.Songs.Clear();
                }

                songlistRepository.Update(songlist);
                uow.Commit();
            }
        }
Esempio n. 3
0
 public void EditSonglist(SonglistDTO songlistDTO, List <int> songIds)
 {
     songlistService.EditSonglist(songlistDTO, songIds);
 }
Esempio n. 4
0
 /// <summary>
 /// Creates an songlist
 /// </summary>
 /// <param name="songlist">songlist</param>
 public void CreateSonglist(SonglistDTO songlist)
 {
     songlistService.CreateSonglist(songlist);
 }
Esempio n. 5
0
        private static void TestSonglistService()
        {
            List <int> list = new List <int>();

            songlistService = Container.Resolve <ISonglistService>();
            clientService   = Container.Resolve <IClientService>();

            //Create
            songlistService.CreateSonglist(new SonglistDTO
            {
                Name    = "Matthew:LongList",
                OwnerID = clientID,
                SongIDs = new List <int> {
                    songID, songID2
                }
            });
            songlistService.CreateSonglist(new SonglistDTO
            {
                Name    = "Matthew:ShortList",
                OwnerID = clientID,
                SongIDs = new List <int> {
                    songID
                }
            });
            songlistService.CreateSonglist(new SonglistDTO
            {
                Name    = "Padge:ShortList",
                OwnerID = clientID2,
                SongIDs = new List <int> {
                    songID
                }
            });

            //GetSonglistIdByName
            songlistID = songlistService.GetSonglistIdByName("Matthew:LongList");
            int mattShortListID = songlistService.GetSonglistIdByName("Matthew:ShortList");

            songlistID2 = songlistService.GetSonglistIdByName("Padge:ShortList");
            list.Add(songlistID);
            list.Add(mattShortListID);
            list.Add(songlistID2);
            Console.WriteLine(list.Count() == 3 ? "ClientService - TestGetSonglistIdByName - OK" : "ClientService - TestGetSonglistIdByName - FAIL");



            //GetSonglistById
            SonglistDTO mattLongList = songlistService.GetSonglist(songlistID);

            Console.WriteLine(mattLongList.Name == "Matthew:LongList" ? "SonglistService - TestGetSonglistById - OK" : "SonglistService - TestGetSonglistById - FAIL");

            ////ListAllSonglists01
            // var songlists = songlistService.ListAllSonglists(new SonglistFilter { OwnerID = clientID }, 1);
            //Console.WriteLine(songlists.TotalResultCount == 2 ? "SonglistService - TestListAllSonglists01 - OK" : "SonglistService - TestListAllSonglists01 - FAIL");

            //ListAllSonglists02
            var songlists2 = songlistService.ListAllSonglists();

            Console.WriteLine(list.Count() == 3 ? "ClientService - TestListAllSonglists02 - OK" : "ClientService - TestListAllSonglists02 - FAIL");


            //EditSonglist
            mattLongList.Name = "longLongList";
            songlistService.EditSonglist(mattLongList, mattLongList.SongIDs);
            SonglistDTO listFromDB = songlistService.GetSonglist(mattLongList.ID);

            Console.WriteLine(listFromDB.Name == "longLongList" ? "SonglistService - TestEditSonglist - OK" : "SonglistService - TestEditSonglist - FAIL");

            //DeleteSonglist
            songlistService.DeleteSonglist(mattShortListID);
            try {
                SonglistDTO listIDFromDB = songlistService.GetSonglist(mattShortListID);
                Console.WriteLine("SonglistService - TestDeleteSonglist - FAIL");
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("SonglistService - TestDeleteSonglist - OK");
            }

            //GetCreator
            ClientDTO creator = songlistService.GetCreator(mattLongList.ID);

            Console.WriteLine(creator.ID == clientID ? "SonglistService - TestGetCreator - OK" : "SonglistService - TestGetCreator - FAIL");

            //GetSonglistSongs
            var songs = songlistService.GetSonglistSongs(songlistID);

            Console.WriteLine(songs.Count() == 2 ? "SonglistService - TestGetSonglistSongs - OK" : "SonglistService -Test GetSonglistSongs - FAIL");
        }