public ActionResult ChangingWord(string key, string choosedRow, Vocabulary changes)
        {
            Vocabulary changedRow   = new Vocabulary();
            User       valueSession = (User)Session["User"];

            IsUserAuth(valueSession);


            changedRow = VocabularyController.FindRow(choosedRow, Byte.Parse(key), _vocabularyContext);



            if (changedRow != null)
            {
                if (changes.ForeignWord != null && changes.ForeignWord != "")
                {
                    changedRow.ForeignWord = changes.ForeignWord;
                }
                if (changes.Transcription != null && changes.Transcription != "")
                {
                    changedRow.Transcription = changes.Transcription;
                }
                if (changes.LocalWord != null && changes.LocalWord != "")
                {
                    changedRow.LocalWord = changes.LocalWord;
                }
            }
            else
            {
                throw new Exception("This translate doesn't exist!");
            }

            VocabularyController.UpdateRow(_vocabularyContext, changedRow);
            return(RedirectToAction("Index", "Vocabularies"));
        }
Example #2
0
        private void Update_Click(object sender, RoutedEventArgs e)
        {
            var rows = (List <VocabularyView>)TableView.ItemsSource;

            foreach (var row in rows)
            {
                Vocabulary updatedRow = new Vocabulary
                {
                    Id            = row.getID(),
                    ForeignWord   = row.ForeignWord,
                    Transcription = row.Transcription,
                    LocalWord     = row.LocalWord,
                    UserID        = currentUser.Id
                };
                VocabularyController.UpdateRow(_vocabularyContext, updatedRow);
            }
        }
Example #3
0
        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);
        }