Exemplo n.º 1
0
 public static List <Journal> GetGames(string PlayerName = null, bool StatusGames = false)
 {
     using (JournalContext db = new JournalContext())
     {
         try
         {
             db.Records.Load();
             int            status = StatusGames ? 1 : 0;
             List <Journal> result = null;
             if (PlayerName is null)
             {
                 result = db.Records.Local.Where(x => x.End == StatusGames).OrderBy(x => x.Score).ToList();
             }
             else
             {
                 result = db.Records.Local.Where(x => x.End == StatusGames && x.Name == PlayerName).ToList();
             }
             return(result);
         }
         catch
         {
             return(null);
         }
     }
 }
Exemplo n.º 2
0
 public static Journal Loadgame(int IdGame)
 {
     using (JournalContext db = new JournalContext())
     {
         try
         {
             db.Records.Load();
             Journal result = db.Records.Local.Where(x => x.Id == IdGame).First();
             return(result);
         }
         catch
         {
             return(null);
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Сохранения результата в БД
 /// </summary>
 /// <param name="game"></param>
 private static void AsyncAdd(Game game)
 {
     Task.Run(() =>
     {
         using (JournalContext db = new JournalContext())
         {
             try
             {
                 Journal journal = new Journal
                 {
                     Answer   = String.Join("", game.Answer),
                     DateTime = DateTime.Now,
                     Name     = game.PlayerName,
                     Score    = game.Score,
                     History  = JsonConvert.SerializeObject(game.History),
                     End      = game.EndGame,
                 };
                 db.Records.Add(journal);
                 db.SaveChanges();
             }
             catch (DbEntityValidationException e)
             {
                 string s = "";
                 foreach (var eve in e.EntityValidationErrors)
                 {
                     s = String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                     foreach (var ve in eve.ValidationErrors)
                     {
                         s += String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                            ve.PropertyName, ve.ErrorMessage);
                     }
                 }
             }
         }
     });
 }
Exemplo n.º 4
0
        /// <summary>
        /// Загрузка игры
        /// </summary>
        /// <param name="IdGame">Id игры</param>
        /// <returns></returns>
        public Journal LoadGame(int IdGame)
        {
            Journal journal = JournalContext.Loadgame(IdGame);

            return(journal);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Загрузка игр
 /// </summary>
 /// <param name="StatusGames">Флаг состояния игр</param>
 /// <returns></returns>
 public object GetGames(bool StatusGames, string PlayerName = null)
 {
     return(JournalContext.GetGames(PlayerName, StatusGames));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Созранение игры
 /// </summary>
 /// <param name="game">Экземпляр игры</param>
 public void SaveGame(Game game)
 {
     JournalContext.Add(game);
 }