Пример #1
0
        public ActionResult RemoveSong(int setListId, int setListSongId)
        {
            SetList setList = db.SetLists
                              .Include(s => s.SetListSongs)
                              .Where(s => s.SetListId == setListId)
                              .FirstOrDefault();
            var         setListSong         = db.SetListSongs.Find(setListSongId);
            SetListSong setListSongInternal = setList.SetListSongs.Where(s => s.SetListSongId == setListSongId).FirstOrDefault();

            setList.SetListSongs.Remove(setListSongInternal);
            db.SetListSongs.Remove(setListSong);
            db.SaveChanges();
            return(Json(setList.Name, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult Reorder(string jsonString, int setListId)
        {
            JArray             songArray    = JArray.Parse(jsonString);
            List <SetListSong> setListSongs = new List <SetListSong>();
            int count = 0;

            foreach (var item in songArray.Children())
            {
                var         itemProperties = item.Children <JProperty>();
                var         element        = itemProperties.First();
                int         songId         = element.Value.ToObject <int>();
                Song        song           = db.Songs.Find(songId);
                SetListSong setListSong    = new SetListSong();
                setListSong.SetListOrder = count;
                setListSong.Song         = song;
                setListSongs.Add(setListSong);
                count++;
            }
            SetList setList = db.SetLists
                              .Include(s => s.SetListSongs)
                              .Where(s => s.SetListId == setListId)
                              .FirstOrDefault();
            //Remove old set list songs from db
            List <SetListSong> setListSongsToDelete = setList.SetListSongs.ToList();

            for (int i = setListSongsToDelete.Count - 1; i >= 0; i--)
            {
                int         setListSongId       = setListSongsToDelete[i].SetListSongId;
                SetListSong setListSongToDelete = db.SetListSongs.Find(setListSongId);
                db.SetListSongs.Remove(setListSongToDelete);
            }
            db.SaveChanges();
            //Remove old set list songs from ICollection
            setList.SetListSongs.Clear();
            //Add new set list songs
            foreach (SetListSong newSetListSong in setListSongs)
            {
                setList.SetListSongs.Add(newSetListSong);
            }
            db.SaveChanges();
            string songsHtml = "";

            foreach (SetListSong setListSong in setList.SetListSongs)
            {
                songsHtml += GetSongHtml(setListSong);
            }
            return(Json(songsHtml, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public ActionResult Create(int bandId, int setListId, string songName)
        {
            string  json;
            SetList setList = db.SetLists
                              .Include(s => s.SetListSongs)
                              .Where(s => s.SetListId == setListId)
                              .FirstOrDefault();
            SetListSong setListSong = new SetListSong();

            setListSong.SetListOrder = setList.SetListSongs.Count;
            if (db.Songs.Any(s => s.BandId == bandId && s.Name == songName))
            {
                var  songFound     = db.Songs.First(s => s.BandId == bandId && s.Name == songName);
                bool duplicateSong = false;
                foreach (SetListSong existingSetListSong in setList.SetListSongs)
                {
                    if (songFound == existingSetListSong.Song)
                    {
                        duplicateSong = true;
                    }
                }
                if (!duplicateSong)
                {
                    setListSong.Song = songFound;
                    setList.SetListSongs.Add(setListSong);
                    db.SaveChanges();
                    string existingSongHtml = WebUtility.HtmlEncode(GetSongHtml(setListSong));
                    json = "{\"append\": true, \"newSong\": false, \"html\": \"" + existingSongHtml + "\"}";
                    return(Json(json, JsonRequestBehavior.AllowGet));
                }
                json = "{\"append\": false, \"newSong\": false, \"html\": \"\"}";
                return(Json(json, JsonRequestBehavior.AllowGet));
            }
            Song song = new Song();

            song.Name   = songName;
            song.BandId = bandId;
            db.Songs.Add(song);
            db.SaveChanges();

            setListSong.Song = song;
            setList.SetListSongs.Add(setListSong);
            db.SaveChanges();
            string songHtml = WebUtility.HtmlEncode(GetSongHtml(setListSong));

            json = "{\"append\": true, \"newSong\": true, \"html\": \"" + songHtml + "\"}";
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        private string GetSongHtml(SetListSong setListSong)
        {
            StringBuilder songHtml = new StringBuilder();

            songHtml.Append("<li class=\"list-group-item\" data-songId=\"" + setListSong.Song.SongId + "\">");
            songHtml.Append("<div class=\"row\">");
            songHtml.Append("<div class=\"col-md-1\">");
            songHtml.Append("<a class=\"btn btn-link btn-s\"><span class=\"glyphicon glyphicon-move\"></span></a>");
            songHtml.Append("</div>");
            songHtml.Append("<div class=\"col-md-10\">");
            songHtml.Append("<h4>" + setListSong.Song.Name + "</h4>");
            songHtml.Append("</div>");
            songHtml.Append("<div class=\"col-md-1\">");
            songHtml.Append("<a class=\"btn btn-danger btn-s removeSong\" data-setListSongId=\"" + setListSong.SetListSongId + "\"><span class=\"glyphicon glyphicon-trash\"></span></a>");
            songHtml.Append("</div>");
            songHtml.Append("</div>");
            songHtml.Append("</li>");

            return(songHtml.ToString());
        }