public static void RemoveUser(UserContext userContext, VocabularyContext vocabularyContext, ref User user) { try { VocabularyController.RemoveVocabulary(vocabularyContext, user); vocabularyContext.SaveChanges(); userContext.Users.Remove(user); userContext.SaveChanges(); user = null; } catch (Exception e) { Exceptions.Catching(e); } }
public static void OpsMenu(User currentUser) { do { UsefulFunctions.PrepareForView(); string buff; byte chooseOps; for (int i = 0; i < _vocabularyMenu.Length; i++) { Console.WriteLine("{0}. {1}", i + 1, _vocabularyMenu[i]); } buff = Console.ReadLine(); if (!Byte.TryParse(buff, out chooseOps)) { continue; } if (chooseOps == 1) { Vocabulary row = createRow(currentUser); VocabularyController.AddRow(_vocabularyContext, row); Console.WriteLine("Row successfully added."); Console.ReadKey(); } else if (chooseOps == 2) { Console.WriteLine("Foreign Word\tTranscription\tLocal word"); var userVoc = _vocabularyContext.Vocabularies.ToList(); foreach (var row in userVoc) { if (row.UserID == currentUser.Id) { if (row.Transcription.Length == 0) { Console.WriteLine("{0}\t\t{1}\t\t{2}", row.ForeignWord, "-", row.LocalWord); } else { Console.WriteLine("{0}\t\t{1}\t\t{2}", row.ForeignWord, row.Transcription, row.LocalWord); } } } Console.ReadKey(); } else if (chooseOps == 3) { string key; Vocabulary editRow; string text = "Choose the key for find word: \n" + "1. Foreign word;\n2. Transcription;\n3. Local word"; byte editChoose = UsefulFunctions.Choose(text, 1, 3); key = UsefulFunctions.GetKey(); try { editRow = VocabularyController.FindRow(key, editChoose, _vocabularyContext); Console.WriteLine("Row successfully found"); string change; for (int i = 0; i < 3; i++) { if (i == 0) { Console.WriteLine("Edit foreign word. Current is {0}", editRow.ForeignWord); } else if (i == 1) { Console.WriteLine("Edit transcription. Current is {0}", editRow.Transcription); } else { Console.WriteLine("Edit local word. Current is {0}", editRow.LocalWord); } change = Console.ReadLine(); if (change.Length != 0 && i == 0) { editRow.ForeignWord = change; } else if (change.Length != 0 && i == 1) { editRow.Transcription = change; } else if (change.Length != 0 && i == 2) { editRow.LocalWord = change; } } VocabularyController.UpdateRow(_vocabularyContext, editRow); } catch (Exception e) { Exceptions.Catching(e); } if (Exceptions.IsError == EMPTY) { Console.WriteLine("Row successfully updated"); } } else if (chooseOps == 4) { string text = "Choose the key for delete word: \n" + "1. Foreign word;\n2. Transcription;\n3. Local word"; byte deleteChoose = UsefulFunctions.Choose(text, 1, 3); string key = UsefulFunctions.GetKey(); try { Vocabulary foundRow = VocabularyController.FindRow(key, deleteChoose, _vocabularyContext); VocabularyController.RemoveRow(_vocabularyContext, foundRow); } catch (Exception e) { Exceptions.Catching(e); } if (Exceptions.IsError == EMPTY) { Console.WriteLine("Row successfully deleted"); } } else if (chooseOps == 5) { //bool sure = false; Console.WriteLine("Are you sure to delete the vocabulary?\n y - yes, n - no"); var chooseDelete = Console.ReadLine(); if (chooseDelete.Length == 1 && chooseDelete == "n") { VocabularyController.RemoveVocabulary(_vocabularyContext, currentUser); } } else if (chooseOps == 6) { GameMenu(currentUser); } else if (chooseOps == 7) { currentUser = SettingMenu(currentUser); if (currentUser == null) { break; } } else if (chooseOps == 8) { break; } } while (true); }