public ActionResult PlayList(int id, string searchValue, FormCollection collection) { //try //{ // TODO: Add insert logic here if (searchValue != "") { string searchString = searchValue.Replace(" ", "+"); string parameterS = "http://ws.spotify.com/search/1/track?q=" + searchString; List<Music> musicList = new List<Music>(); XmlDocument doc = new XmlDocument(); doc.Load(parameterS); XmlNodeList companyList = doc.GetElementsByTagName("track"); foreach (XmlNode node in companyList) { XmlElement companyElement = (XmlElement)node; string name = companyElement.GetElementsByTagName("name")[0].InnerText; //string tracknumber = companyElement.GetElementsByTagName("track-number")[0].InnerText; string length = companyElement.GetElementsByTagName("length")[0].InnerText; //string popularity = companyElement.GetElementsByTagName("popularity")[0].InnerText; //string xmlCompanyID = companyElement.Attributes["ID"].InnerText; string artist = companyElement.GetElementsByTagName("artist")[0].InnerText; string released = companyElement.GetElementsByTagName("released")[0].InnerText; string albumname = companyElement.GetElementsByTagName("album")[0].FirstChild.InnerText; Music m = new Music(); m.Name = name; m.Length = length; m.Artist = artist; Album a = new Album(); a.Artist = artist; a.Name = albumname; a.Year = released; m.album = a; musicList.Add(m); } ViewBag.MusicList = musicList; ViewBag.SearchParameter = searchValue; } var b = new PlayList { Id = id }; var playlist = _repo.GetById(b.Id); var playlists = _repo.GetAll(); //IEnumerable<SelectListItem> items; //items = playlists // .Select(c => new SelectListItem // { // Value = c.Name, // Text = c.Name, // Selected = false, // }); //ViewBag.PlayList_list = items; string uname = User.Identity.Name; User user = null; foreach (User u in _repoUser.GetAll()) { if (u.Nickname.Equals(uname)) { user = u; } } List<PlayList> ddList = new List<PlayList>(); foreach (PlayList p in playlists) { if (p.Owner == user.Nickname) { ddList.Add(p); } } IEnumerable<SelectListItem> items; items = ddList .Select(c => new SelectListItem { Value = c.Name, Text = c.Name, Selected = false, }); ViewBag.PlayList_list = items; var model = new Tuple<IEnumerable<User>, User, PlayList>(_repoUser.GetAll(), user, playlist); return View(model); }
public ActionResult AddMusics(int id, FormCollection collection) { var playlists = _repo.GetAll(); //IEnumerable<SelectListItem> items; //items = playlists // .Select(c => new SelectListItem // { // Value = c.Name, // Text = c.Name, // Selected = false, // }); //ViewBag.PlayList_list = items; var b = new PlayList { Id = id }; var playlist = _repo.GetById(b.Id); List<Music> list = playlist.Lists; if (list == null) { list = new List<Music>(); } int count = 0; foreach (string result in collection) { if (result.Contains("#&#") && collection[count].Contains("true")) { Music m = new Music(); Album a = new Album(); string[] res = Regex.Split(result, "#&#"); m.Name = res[0]; m.Length = res[1]; m.Artist = res[2]; a.Artist = res[2]; a.Name = res[3]; a.Year = res[4]; m.album = a; m.Id = list.Count; list.Add(m); } ++count; } playlist.Lists = list; string uname = User.Identity.Name; User user = null; foreach (User u in _repoUser.GetAll()) { if (u.Nickname.Equals(uname)) { user = u; } } List<PlayList> ddList = new List<PlayList>(); foreach (PlayList p in playlists) { if (p.Owner == user.Nickname) { ddList.Add(p); } } IEnumerable<SelectListItem> items; items = ddList .Select(c => new SelectListItem { Value = c.Name, Text = c.Name, Selected = false, }); ViewBag.PlayList_list = items; var model = new Tuple<IEnumerable<User>, User, PlayList>(_repoUser.GetAll(), user, playlist); return View("PlayList", model); //return View("PlayList",playlist); }
public ActionResult MoveUp(int id, int musicId) { var playlists = _repo.GetAll(); //IEnumerable<SelectListItem> items; //items = playlists // .Select(c => new SelectListItem // { // Value = c.Name, // Text = c.Name, // Selected = false, // }); //ViewBag.PlayList_list = items; var b = new PlayList { Id = id }; var playlist = _repo.GetById(b.Id); if (musicId != 0) { Music tempMusic = new Music(); Album tempAlbum = new Album(); tempMusic.Id = playlist.Lists.ElementAt(musicId).Id; tempMusic.Name = playlist.Lists.ElementAt(musicId).Name; tempMusic.Length = playlist.Lists.ElementAt(musicId).Length; tempMusic.Artist = playlist.Lists.ElementAt(musicId).Artist; tempAlbum.Artist = playlist.Lists.ElementAt(musicId).album.Artist; tempAlbum.Name = playlist.Lists.ElementAt(musicId).album.Name; tempAlbum.Year = playlist.Lists.ElementAt(musicId).album.Year; playlist.Lists.ElementAt(musicId).Id = playlist.Lists.ElementAt(musicId-1).Id; playlist.Lists.ElementAt(musicId).Name = playlist.Lists.ElementAt(musicId-1).Name; playlist.Lists.ElementAt(musicId).Length = playlist.Lists.ElementAt(musicId-1).Length; playlist.Lists.ElementAt(musicId).Artist = playlist.Lists.ElementAt(musicId-1).Artist; playlist.Lists.ElementAt(musicId).album.Artist = playlist.Lists.ElementAt(musicId-1).album.Artist; playlist.Lists.ElementAt(musicId).album.Name = playlist.Lists.ElementAt(musicId-1).album.Name; playlist.Lists.ElementAt(musicId).album.Year = playlist.Lists.ElementAt(musicId-1).album.Year; playlist.Lists.ElementAt(musicId - 1).Id = tempMusic.Id; playlist.Lists.ElementAt(musicId - 1).Name = tempMusic.Name; playlist.Lists.ElementAt(musicId - 1).Length = tempMusic.Length; playlist.Lists.ElementAt(musicId - 1).Artist = tempMusic.Artist; playlist.Lists.ElementAt(musicId - 1).album.Artist = tempAlbum.Artist; playlist.Lists.ElementAt(musicId - 1).album.Name = tempAlbum.Name; playlist.Lists.ElementAt(musicId - 1).album.Year = tempAlbum.Year; //_repo.Swap(cardId, cardId - 1); int count = 0; foreach (Music m in playlist.Lists) { m.Id = count; ++count; } } string uname = User.Identity.Name; User user = null; foreach (User u in _repoUser.GetAll()) { if (u.Nickname.Equals(uname)) { user = u; } } List<PlayList> ddList = new List<PlayList>(); foreach (PlayList p in playlists) { if (p.Owner == user.Nickname) { ddList.Add(p); } } IEnumerable<SelectListItem> items; items = ddList .Select(c => new SelectListItem { Value = c.Name, Text = c.Name, Selected = false, }); ViewBag.PlayList_list = items; var model = new Tuple<IEnumerable<User>, User, PlayList>(_repoUser.GetAll(), user, playlist); return View("PlayList", model); //return View("PlayList", playlist); }
public ActionResult MoveToList(int id, int musicId, FormCollection collection) { var playlists = _repo.GetAll(); //IEnumerable<SelectListItem> items; //items = playlists // .Select(c => new SelectListItem // { // Value = c.Name, // Text = c.Name, // Selected = false, // }); //ViewBag.PlayList_list = items; var b = new PlayList { Id = id }; var playlist = _repo.GetById(b.Id); //Get Music Info //------------------ Music tempMusic = new Music(); Album tempAlbum = new Album(); tempMusic.Id = playlist.Lists.ElementAt(musicId).Id; tempMusic.Name = playlist.Lists.ElementAt(musicId).Name; tempMusic.Length = playlist.Lists.ElementAt(musicId).Length; tempMusic.Artist = playlist.Lists.ElementAt(musicId).Artist; tempAlbum.Artist = playlist.Lists.ElementAt(musicId).album.Artist; tempAlbum.Name = playlist.Lists.ElementAt(musicId).album.Name; tempAlbum.Year = playlist.Lists.ElementAt(musicId).album.Year; //------------------ //Remove Music from current playlist //---------------------------------- playlist.Lists.RemoveAt(musicId); int count = 0; foreach (Music m in playlist.Lists) { m.Id = count; ++count; } //---------------------------------- //Add Music to selected Playlist //------------------------------- var selected_playlist = _repo.GetPlayListByName(collection[0]); List<Music> list = selected_playlist.Lists; if (list == null) { list = new List<Music>(); } Music sm = new Music(); Album sa = new Album(); sm.Name = tempMusic.Name; sm.Length = tempMusic.Length; sm.Artist = tempMusic.Artist; sa.Artist = tempAlbum.Artist; sa.Name = tempAlbum.Name; sa.Year = tempAlbum.Year; sm.album = sa; sm.Id = list.Count; list.Add(sm); selected_playlist.Lists = list; //------------------------------- string uname = User.Identity.Name; User user = null; foreach (User u in _repoUser.GetAll()) { if (u.Nickname.Equals(uname)) { user = u; } } List<PlayList> ddList = new List<PlayList>(); foreach (PlayList p in playlists) { if (p.Owner == user.Nickname) { ddList.Add(p); } } IEnumerable<SelectListItem> items; items = ddList .Select(c => new SelectListItem { Value = c.Name, Text = c.Name, Selected = false, }); ViewBag.PlayList_list = items; var model = new Tuple<IEnumerable<User>, User, PlayList>(_repoUser.GetAll(), user, playlist); return View("PlayList", model); //return View("PlayList", playlist); }