Exemplo n.º 1
0
/*+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 * TOOLBAR
 *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*/

    void DrawToolBar()
    {
        GUIStyle b = new GUIStyle(GUI.skin.button);

        GUILayout.BeginArea(toolbarSection);
        GUILayout.BeginHorizontal();

        // Create Simple Ball
        ChangeColor(Color.green);
        if (GUILayout.Button("+ Simple Ball", b, GUILayout.Width(100)))
        {
            BallData new_ball = SongEdit.CreateBall(typeof(SimpleBallData));
            ballList.Add(new_ball);
        }
        ResetColor();

        // Sort Balls
        ChangeColor(new Color(0.909f, 0.635f, 0.066f));
        if (GUILayout.Button("Sort Balls", b, GUILayout.Width(80)))
        {
            game.SortBalls();
        }
        ResetColor();

        // Sort Notes
        ChangeColor(new Color(0.717f, 0.262f, 0.937f));
        if (GUILayout.Button("Sort Notes", b, GUILayout.Width(80)))
        {
            game.SortNotes();
        }
        ResetColor();

        GUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            CheckConcurrentEdit(EntryType.Song, id);

            var model = new SongEdit(Service.GetSongForEdit(id));

            return(View(model));
        }
Exemplo n.º 3
0
 //EDIT
 public bool EditSong(SongEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity = ctx.
                      Songs
                      .Single(s => s.SongId == model.SongId);
         entity.Title = model.Title;
         return(ctx.SaveChanges() == 1);
     }
 }
Exemplo n.º 4
0
        public async Task <SongEdit> EditSong([FromBody] Song song)
        {
            var user = await GetUserOrThrow();

            if (song.Id == null)
            {
                throw new ArgumentException("Song must have an ID");
            }

            var existingSong = await DbSession.LoadRequiredAsync <Song>(song.Id);

            var songEditId = GetSongEditId(existingSong.Id !, user.Id);
            var songEdit   = new SongEdit(existingSong, song)
            {
                Id     = songEditId,
                UserId = user.Id
            };

            if (songEdit.HasAnyChanges())
            {
                // Admins don't need approval; apply the change straight away.
                if (user.IsAdmin())
                {
                    songEdit.Apply(existingSong);
                }
                else // the user isn't an admin.
                {
                    // Store the song edit and await admin approval.
                    await DbSession.StoreAsync(songEdit);

                    DbSession.SetRavenExpiration(songEdit, DateTime.UtcNow.AddDays(30 * 6));

                    // Notify admins that a new song edit needs approval.
                    var admins = await DbSession.Query <AppUser>()
                                 .Where(u => u.Roles.Contains(AppUser.AdminRole))
                                 .ToListAsync();

                    var editNeedsApprovalNotification = Notification.SongEditsNeedApproval(appOptions.PushNotificationsImageUrl);
                    foreach (var admin in admins)
                    {
                        // If the admin already has a "song edits need approval" notification item, replace it with the unread one.
                        var existing = admin.Notifications.FirstOrDefault(n => n.Title == editNeedsApprovalNotification.Title);
                        if (existing != null)
                        {
                            admin.Notifications.Remove(existing);
                        }

                        admin.AddNotification(editNeedsApprovalNotification);
                    }
                }
            }

            return(songEdit);
        }
Exemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            var service = CreateSongService();
            var detail  = service.GetSongById(id);
            var model   =
                new SongEdit
            {
                SongId = detail.SongId,
                Title  = detail.Title,
            };

            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult Edit(SongEdit model)
        {
            if (!ModelState.IsValid)
            {
                var oldContract = Service.GetSongForEdit(model.Id);
                model.CopyNonEditableFields(oldContract);
                return(View(model));
            }

            var contract = model.ToContract();

            Service.UpdateBasicProperties(contract);

            return(RedirectToAction("Details", new { id = model.Id }));
        }
Exemplo n.º 7
0
        public ActionResult Edit(int id)
        {
            //ViewBag
            ViewBag.Albums = new SelectList(_db.Albums.ToList(), "AlbumID", "AlbumID");
            var service = CreateSongService();
            var detail  = service.GetSongById(id);
            var model   =
                new SongEdit
            {
                SongID   = detail.SongID,
                AlbumID  = detail.AlbumID,
                SongName = detail.SongName
            };

            return(View(model));
        }
Exemplo n.º 8
0
        public bool UpdateSong(SongEdit model)
        {
            using (var db = new ApplicationDbContext())
            {
                var entity =
                    db
                    .Songs
                    .Single(e => e.SongID == model.SongID);

                entity.SongID   = model.SongID;
                entity.AlbumID  = model.AlbumID;
                entity.SongName = model.SongName;

                return(db.SaveChanges() == 1);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Updates a Song
        /// </summary>
        /// <param name="song"></param>
        /// <returns></returns>
        public IHttpActionResult Put(SongEdit song)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateSongService();

            if (!service.UpdateSong(song))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Exemplo n.º 10
0
        public bool UpdateSong(SongEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Songs
                             .Single(e => e.SongId == model.SongId && e.Id == _userId);
                entity.SongName    = model.SongName;
                entity.SongArtist  = model.SongArtist;
                entity.SongAlbum   = model.SongAlbum;
                entity.ReleaseYear = model.ReleaseYear;
                entity.ModifiedUTC = DateTimeOffset.UtcNow;
                entity.PlaylistId  = model.PlaylistId;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 11
0
        // UPDATE: Song
        public ActionResult Edit(int id)
        {
            var service = CreateSongService();
            var detail  = service.GetSongById(id);
            var model   = new SongEdit
            {
                SongId      = detail.SongId,
                SongName    = detail.SongName,
                SongArtist  = detail.SongArtist,
                SongAlbum   = detail.SongAlbum,
                ReleaseYear = detail.ReleaseYear,
                PlaylistId  = detail.PlaylistId
            };

            return(View(model));
        }
        //GET /Edit
        public ActionResult Edit(int id)
        {
            var service = new SongService();
            var detail  = service.GetSongByID(id);
            var model   =
                new SongEdit
            {
                Title    = detail.Title,
                Genre    = detail.Genre,
                ArtistID = detail.ArtistID,
                AlbumID  = detail.AlbumID,
                Runtime  = detail.Runtime,
                Language = detail.Language
            };

            return(View(model));
        }
Exemplo n.º 13
0
        public bool UpdateSong(SongEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Songs
                    .Single(e => e.SongId == model.SongId);

                entity.Title     = model.Title;
                entity.AlbumID   = model.AlbumId;
                entity.ProfileId = model.ProfileId;
                // entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 14
0
        public ActionResult CreateSong(SongEdit newSong)
        {
            if (ModelState.IsValid)
            {
                var song = libContext.Songs.FirstOrDefault(p => p.Name == newSong.Name);
                if (song != null)   // if song exists
                {
                    return(View("CreateSong"));
                }

                var artist = libContext.Artists.FirstOrDefault(p => p.Name == newSong.Artist);
                if (artist == null) // if artist is not exist
                {
                    artist = libContext.Artists.Add(
                        new Artist
                    {
                        Name = newSong.Artist
                    });
                }

                var genre = libContext.Genres.FirstOrDefault(p => p.Name == newSong.Genre);
                if (genre == null)   //  if genre is not exist
                {
                    genre = libContext.Genres.Add(
                        new Genre
                    {
                        Name = newSong.Genre
                    });
                }

                libContext.Songs.Add(
                    new Song
                {
                    Name        = newSong.Name,
                    Cover       = newSong.Cover,
                    CreatedDate = DateTime.Now,
                    Src         = newSong.Src,
                    ArtistId    = artist.Id,
                });

                //Adding info at GenreSongs

                libContext.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 15
0
        //EditSong
        public bool EditSong(SongEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var song = ctx.Songs
                           .Single(s => s.SongID == model.SongID);

                song.Title    = model.Title;
                song.Genre    = model.Genre;
                song.ArtistID = model.ArtistID;
                song.AlbumID  = model.AlbumID;
                song.Runtime  = model.Runtime;
                song.Language = model.Language;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 16
0
 //UPDATE
 public bool UpdateSong(SongEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             ctx
             .Songs
             .Single(e => e.SongId == model.SongId);
         entity.SongName         = model.SongName;
         entity.Rating           = model.Rating;
         entity.CulumativeRating = model.CulumativeRating;
         entity.NumberOfRatings  = model.NumberOfRatings;
         entity.AlbumId          = model.AlbumId;
         //entity.AlbumName = AlbumNameUpdate(model);
         return(ctx.SaveChanges() == 1);
     }
 }
        public bool UpdateSong(SongEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Songs
                    .Single(e => e.SongId == model.SongId);

                entity.SongName   = model.SongName;
                entity.ArtistName = model.ArtistName;
                entity.AlbumName  = model.AlbumName;
                entity.SongLength = model.SongLength;
                entity.SongGenre  = model.SongGenre;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 18
0
        public async Task <SongEdit> Approve([FromBody] SongEdit songEdit)
        {
            var song = await DbSession.LoadAsync <Song>(songEdit.SongId);

            if (song != null)
            {
                songEdit.Apply(song);
                songEdit.Status = SongEditStatus.Approved;
                await DbSession.StoreAsync(songEdit);

                logger.LogInformation("Applied song edit", songEdit);

                // Notify the user.
                var user = await DbSession.LoadAsync <AppUser>(songEdit.UserId);

                user?.AddNotification(Notification.SongEditApproved(song));
            }

            return(songEdit);
        }
        public ActionResult Edit(int id, SongEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.SongID != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                return(View(model));
            }

            var service = new SongService();

            if (service.EditSong(model))
            {
                TempData["SaveResult"] = "Song was updated";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Song could not be updated");
            return(View());
        }
Exemplo n.º 20
0
        public ActionResult Edit(int id, SongEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.SongID != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateSongService();

            if (service.UpdateSong(model))
            {
                TempData["SaveResult"] = $" {model.SongName} was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", $" {model.SongName} could not be updated.");
            return(View(model));
        }
Exemplo n.º 21
0
    void DrawBallDataList(Color color)
    {
        ballList = game.GetBallData();

        GUIStyle s = new GUIStyle(GUI.skin.button);
        GUIStyle b = new GUIStyle(GUI.skin.button);

        s.alignment = TextAnchor.MiddleLeft;
        b.alignment = TextAnchor.MiddleCenter;
        var w      = GUILayout.Width(100);
        var line_h = GUILayout.Height(20);

        float            yPos   = 0;
        List <BallLabel> labels = new List <BallLabel>();

        newBalls.Clear();
        deleteBalls.Clear();
        typeChangeBalls.Clear();

        //Ball Field
        foreach (BallData ball in ballList)
        {
            BallLabel ballLabel = new BallLabel(ball, yPos);

            if (isLabelVisible(ballLabel))
            {
                DrawUILine(dividerLineColor);

                EditorGUILayout.BeginHorizontal();

                yPos += ballLabel.height;

                //________Create New Ball___________________
                ResetColor();
                ChangeColor(Color.green);
                if (GUILayout.Button("+", b, GUILayout.Width(25), line_h))
                {
                    newBalls.Add(ball, ballList.IndexOf(ball));
                }
                ResetColor();

                //________Delete Ball___________________
                ChangeColor(Color.red);
                if (GUILayout.Button("-", b, GUILayout.Width(25), line_h))
                {
                    deleteBalls.Add(ball);
                }
                ResetColor();

                //________Refresh Ball___________________
                ChangeColor(Color.yellow);
                if (GUILayout.Button("R", b, GUILayout.Width(25), line_h))
                {
                    //SongData.DeleteBall(ball);
                    BallData repairedBall;
                    if (ball.GetType() == typeof(SimpleBallData))
                    {
                        repairedBall = SongEdit.CreateBall(typeof(SimpleBallData), ball.notes);
                    }
                    else
                    {
                        Debug.Log("its a bounce ball");
                        repairedBall = SongEdit.CreateBall(typeof(BounceBallData), ball.notes);
                    }

                    ballList.Add(repairedBall);

                    SongEdit.DeleteBallAndNotes(ball);
                    ballList.Remove(ball);

                    game.SortBalls();
                }
                ResetColor();

                //________Ball Type___________________
                GUILayout.Label("type:", GUILayout.Width(40), line_h);
                BallTypes ball_type = (BallTypes)EditorGUILayout.EnumPopup("", ball.type, s, w);
                if (ball_type != ball.type)
                {
                    ball.type = ball_type;     // if new type selected, set equal to type
                    typeChangeBalls.Add(ball, ballList.IndexOf(ball));
                    EditorUtility.SetDirty(ball);
                }

                //________Enabled / Disabled Field___________________
                //ball.enabled = GUILayout.Toggle(ball.enabled, "Enabled", s, w);

                if (Application.isPlaying)
                {
                    float timeDiff = ball.notes[0].hitBeat - songController.GetSongTimeBeats();

                    if (Mathf.Abs(timeDiff) < 4.0f && timeDiff > 0.0f)
                    {
                        ChangeColor(Color.cyan);
                    }
                    else if (Mathf.Abs(timeDiff) < 2.0f)
                    {
                        ChangeColor(Color.yellow);
                    }

                    EditorGUILayout.ObjectField(ball, typeof(Object), true);

                    ResetColor();
                }

                EditorGUILayout.EndHorizontal();

                DrawOptions(ball);

                if (ball.notes != null)
                {
                    int numNotes = DrawNotes(ball);
                }
            }
            else
            {
                GUILayout.Space(60);
                yPos += 60;
            }
        }
        // --------- END BALL ITERATION --------------------------

        foreach (KeyValuePair <BallData, int> pair in newBalls)
        {
            BallData new_ball = SongEdit.CreateBall(typeof(SimpleBallData));
            ballList.Insert(pair.Value + 1, new_ball);
        }

        foreach (BallData ball in deleteBalls)
        {
            SongEdit.DeleteBallAndNotes(ball);
            ballList.Remove(ball);
        }

        foreach (KeyValuePair <BallData, int> pair in typeChangeBalls)
        {
            BallData ball     = pair.Key;
            BallData new_ball = SongEdit.ChangeBallType(ball, ball.type); // create new ball and copy info
            ballList.Insert(pair.Value, new_ball);

            SongEdit.DeleteBallAndNotes(ball);
            ballList.Remove(ball);
        }
    }
Exemplo n.º 22
0
    int DrawNotes(BallData ball)
    {
        // STYLE
        GUIStyle s = new GUIStyle(GUI.skin.button);

        s.alignment = TextAnchor.MiddleLeft;

        GUIStyle b = new GUIStyle(GUI.skin.button);

        b.alignment = TextAnchor.MiddleCenter;

        var col_field_width  = GUILayout.Width(40);
        var beat_field_width = GUILayout.Width(45);
        var dir_field_width  = GUILayout.Width(100);
        var line_h           = GUILayout.Height(20);

        deleteNotes.Clear();
        newNotes.Clear();

        // --------- BEGIN NOTES ITERATION --------------------------
        foreach (NoteData note in ball.notes)
        {
            if (note == null)
            {
                deleteNotes.Add(note);
                Debug.LogWarning("Deleted a null note from " + songData.name);
                break;
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(31.0f);

            GUIStyle cool = new GUIStyle(GUI.skin.button);
            cool.padding = new RectOffset(2, 2, 2, 2);

            ChangeColor(Color.green);
            //________Add New Note___________________
            if (GUILayout.Button(addNoteTexture, cool, GUILayout.Width(20), line_h))
            {
                newNotes.Add(note);     // Mark note to be added after iteration
            }
            ResetColor();

            //________Remove Note___________________
            ChangeColor(Color.red);
            if (GUILayout.Button(deleteNoteTexture, cool, GUILayout.Width(20), line_h))
            {
                deleteNotes.Add(note);     // Mark note to be deleted after iteration
            }
            ResetColor();

            //________Set Column___________________
            GUILayout.Label("Col:", GUILayout.Width(25), line_h);
            int new_col = EditorGUILayout.IntField("", note.hitPosition, s, col_field_width, line_h);
            if (note.hitPosition != new_col)
            {
                note.hitPosition = new_col;
                EditorUtility.SetDirty(note);
            }

            //________Set Hit Beat___________________
            GUILayout.Label("Beat:", GUILayout.Width(32), line_h);
            float new_beat = EditorGUILayout.FloatField("", note.hitBeat, s, beat_field_width, line_h);
            if (note.hitBeat != new_beat)
            {
                note.hitBeat = new_beat;
                EditorUtility.SetDirty(note);
                //ball.SortNotes();
            }

            //________Set Direction___________________
            GUILayout.Label("Direction:", GUILayout.Width(56), line_h);
            note.noteDirection = (Direction)EditorGUILayout.EnumPopup("", note.noteDirection, s, dir_field_width, line_h);

            GUILayout.EndHorizontal();
        }
        // --------- END NOTES ITERATION --------------------------

        // Delete all notes marked to be deleted
        foreach (NoteData note in deleteNotes)
        {
            SongEdit.DeleteNote(ball, note);
        }

        // Add all notes marked to be added
        foreach (NoteData note in newNotes)
        {
            SongEdit.InsertNote(ball, note, ball.notes.IndexOf(note));
        }

        ResetColor();

        return(ball.notes.Count);
    }