Exemple #1
0
        private static void ShowScore()
        {
            VocabolaryDBContext context = new VocabolaryDBContext();
            var games = context.Games
                        .Select(g => new
            {
                GuesWords = g.GuesBulgarianWords + g.GuesEnglishWords,
                g.UserName,
                g.Points
            })
                        .Take(10)
                        .OrderByDescending(g => g.Points)
                        .ThenByDescending(g => g.GuesWords);

            Console.Clear();
            int count = 1;

            foreach (var game in games)
            {
                Console.WriteLine($"{count++}. User {game.UserName} - guuess words {game.GuesWords} - TOTAL POINTS - {game.Points}");
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemple #2
0
        private static void RemoveWordsFromDb(string input)
        {
            VocabolaryDBContext context = new VocabolaryDBContext();

            if (input.Contains("English"))
            {
                string inputEnglishWord    = GetInputForEnglishWord();
                var    englishWordToDelete = context.EnglishWords.FirstOrDefault(w => w.Word == inputEnglishWord);
                if (englishWordToDelete is null)
                {
                    Console.WriteLine($"Word {inputEnglishWord} dosn't exist!");
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                    return;
                }

                context.Remove(englishWordToDelete);
            }
            else
            {
                string inputbBulgarianWord   = GetInputForBulgarianWord();
                var    bulgarianWordToDelete = context.BulgarianWords.FirstOrDefault(w => w.Word == inputbBulgarianWord);
                if (bulgarianWordToDelete is null)
                {
                    Console.WriteLine($"Word {inputbBulgarianWord} dosn't exist!");
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                    return;
                }

                context.Remove(bulgarianWordToDelete);
            }
            context.SaveChanges();
        }
Exemple #3
0
        private static Dictionary <string, List <string> > GetAllWords(string input)
        {
            VocabolaryDBContext context = new VocabolaryDBContext();
            Dictionary <string, List <string> > result = new Dictionary <string, List <string> >();

            var words = context.BulgarianWordsEnglishWords
                        .Select(w => new
            {
                EnglishWord   = w.EnglishWord.Word,
                BulgarianWord = w.BulgarianWord.Word
            }).ToList();

            if (input.Contains("English"))
            {
                foreach (var word in words)
                {
                    if (!result.ContainsKey(word.EnglishWord))
                    {
                        result.Add(word.EnglishWord, new List <string>());
                    }

                    result[word.EnglishWord].Add(word.BulgarianWord);
                }
            }
            else
            {
                foreach (var word in words)
                {
                    if (!result.ContainsKey(word.BulgarianWord))
                    {
                        result.Add(word.BulgarianWord, new List <string>());
                    }

                    result[word.BulgarianWord].Add(word.EnglishWord);
                }
            }

            return(result);
        }
Exemple #4
0
        private static void AddNewScore(string userName, int guessCount, int points, string input)
        {
            int guessBulgarianWords     = 0;
            int guessEnglishWords       = 0;
            VocabolaryDBContext context = new VocabolaryDBContext();

            if (input == "Bulgarian")
            {
                guessBulgarianWords = guessCount;
            }
            else
            {
                guessEnglishWords = guessCount;
            }

            context.Games.Add(new Game
            {
                GuesBulgarianWords = guessBulgarianWords,
                GuesEnglishWords   = guessEnglishWords,
                Points             = points,
                UserName           = userName,
            });
            context.SaveChanges();
        }
Exemple #5
0
        private static void AddNewWordToDB(string input)
        {
            string inputEnglishWord;
            string inputbBulgarianWord;
            VocabolaryDBContext context = new VocabolaryDBContext();

            if (input.Contains("English"))
            {
                inputEnglishWord    = GetInputForEnglishWord();
                inputbBulgarianWord = GetInputForBulgarianWord();
            }
            else
            {
                inputbBulgarianWord = GetInputForBulgarianWord();
                inputEnglishWord    = GetInputForEnglishWord();
            }

            int?idEnglishWord   = null;
            int?idBulgarianWord = null;

            try
            {
                idEnglishWord   = context.EnglishWords.FirstOrDefault(w => w.Word == inputEnglishWord).EnglishWordId;
                idBulgarianWord = context.BulgarianWords.FirstOrDefault(w => w.Word == inputbBulgarianWord).BulgarianWordId;
            }
            catch (NullReferenceException ex)
            {
                //one or both words dosnt contain i DB
            }

            if (context.BulgarianWordsEnglishWords.Find(idEnglishWord, idBulgarianWord) != null)
            {
                Console.WriteLine("Words already exists!");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
                return;
            }

            EnglishWord   englishWord;
            BulgarianWord bulgarianWord;

            if (idEnglishWord is null)
            {
                englishWord = new EnglishWord {
                    Word = inputEnglishWord, Points = 1
                };
            }
            else
            {
                englishWord = context.EnglishWords.Find(idEnglishWord);
            }

            if (idBulgarianWord is null)
            {
                bulgarianWord = new BulgarianWord {
                    Word = inputbBulgarianWord, Points = 1
                };
            }
            else
            {
                bulgarianWord = context.BulgarianWords.Find(idBulgarianWord);
            }

            context.Add(new BulgarianWordEnglishWord
            {
                EnglishWord   = englishWord,
                BulgarianWord = bulgarianWord,
            });

            context.SaveChanges();
            //var englishWords = context.BulgarianWords.Where(w => w.Word == bulgarianWord).Select(w => w.EnglishWords).ToHashSet();
            //var bulgarianWords = context.EnglishWords.Where(w => w.Word == englishWord).Select(w => w.BulgarianWords).ToHashSet();
        }
        public static void CreateDB()
        {
            VocabolaryDBContext context = new VocabolaryDBContext();

            context.Database.EnsureCreated();
        }