Exemplo n.º 1
0
        /// <summary>
        /// this is to create player stat's notes if they do not exist
        /// </summary>
        /// <param name="scorecontext"></param>
        /// <param name="usercontext"></param>
        /// <param name="userManager"></param>
        public static void SeedNotes(GameDataContext notescontext)
        {
            // Look for any stats
            if (notescontext.StatNotes.Any())
            {
                return;   // DB has been seeded
            }
            //get these stats that we want to attach notes to
            PlayerStats firststat  = notescontext.PlayerStats.Where(s => s.UserName == "*****@*****.**").ToList()[0];
            PlayerStats secondstat = notescontext.PlayerStats.Where(s => s.UserName == "*****@*****.**").ToList()[0];
            //Initialize these stat notes
            var notes = new StatNotes[]
            {
                new StatNotes {
                    Note         = "Congrats on your great score!",
                    TimeModified = DateTime.Now,
                    Liked        = 2,
                    UserName     = "******",
                    StatID       = firststat.PlayerStatsID,
                },
                new StatNotes {
                    Note         = "Go back to space!",
                    TimeModified = DateTime.Now,
                    Liked        = 100,
                    UserName     = "******",
                    StatID       = secondstat.PlayerStatsID,
                },
            };

            //add each note to the DB
            foreach (StatNotes n in notes)
            {
                notescontext.StatNotes.Add(n);
            }
            //try saving the db
            try
            {
                notescontext.SaveChanges();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                throw;
            }
        }
        public JsonResult ChangeStatNote(string passednote, int note_id, int statID)
        {
            DateTime time = DateTime.Now;

            //no note exists
            if (note_id == 0)
            {
                StatNotes note_from_db = new StatNotes
                {
                    Note         = passednote,
                    StatID       = statID,
                    TimeModified = time,
                };
                _gamedatacontext.StatNotes.Add(note_from_db);
            }
            //updating a note
            else
            {
                StatNotes note_from_db = _gamedatacontext.StatNotes.Where(o => o.NoteID == note_id).Single();
                note_from_db.Note         = passednote;
                note_from_db.TimeModified = time;
                _gamedatacontext.Update(note_from_db);
            }
            _gamedatacontext.SaveChanges();

            if (note_id == 0)
            {
                note_id = _gamedatacontext.StatNotes.Where(o => o.Note == passednote).Single().NoteID;
            }

            return(Json(new
            {
                success = true,
                note = passednote,
                id = note_id,
                time = time.ToString()
            }));
        }