示例#1
0
        // update each song
        public void UpdateSong(SacramentMeetingContext context, Meeting meetingToUpdate,
                               ICollection <SongSelection> songSelection, SongPosition schedule, string songID = null)
        {
            if (songID == null)                         // if songID is null, need to delete song if there is one in songPosition.
            {
                foreach (var item in songSelection)     // check songPosition in songSelections.
                {
                    if (item.Schedule.Equals(schedule)) // if there is a song in songPosition, delete it
                    {
                        SongSelection songToRemove
                            = meetingToUpdate
                              .SongSelections
                              .SingleOrDefault(i => i.SongID == item.SongID && i.Schedule == schedule);
                        context.Remove(songToRemove);
                        songSelection.Remove(songToRemove);
                        return;
                    } // if there is no song, do nothing because it is already empty
                }
            }
            else // if songID is not empty
            {
                int songIDInt = int.Parse(songID); // change songID to int
                int count     = 0;                  // count to see if songPosition is empty
                foreach (var item in songSelection) // check each songSelection in meeting for correct songPosition
                {
                    if (item.Schedule.Equals(schedule))
                    {
                        count++; // there is song in songPosition


                        if (songIDInt != item.SongID)  // if wrong song is in songPosition
                        {
                            SongSelection songToRemove // remove wrong song
                                = meetingToUpdate
                                  .SongSelections
                                  .SingleOrDefault(i => i.SongID == item.SongID && i.Schedule == schedule);
                            context.Remove(songToRemove);
                            songSelection.Remove(songToRemove);

                            meetingToUpdate.SongSelections.Add( // add the correct song
                                new SongSelection
                            {
                                SongID   = songIDInt,
                                Schedule = schedule
                            });
                            return;
                        }
                    }
                }
                if (count == 0) // the song position is empty
                {
                    meetingToUpdate.SongSelections.Add(
                        new SongSelection
                    {
                        SongID   = songIDInt,
                        Schedule = schedule
                    });
                }
            }
        }
示例#2
0
    //enforce singleton
    private void Awake()
    {
        //Check if instance already exists
        if (instance == null)
        {
            //if not, set instance to this
            instance = this;
        }

        //If instance already exists and it's not this:
        else if (instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }

        //Sets this to not be destroyed when reloading scene
        //DontDestroyOnLoad(gameObject);
    }
示例#3
0
 public async Task AddSongPositionRelation(SongPosition songPositionRelation)
 {
     await SQLiteNetExtensionsAsync.Extensions.WriteOperations.InsertWithChildrenAsync(_connection, songPositionRelation, false);
 }