Пример #1
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();
        }
Пример #2
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();
        }
Пример #3
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();
        }