Exemplo n.º 1
0
    protected void lbtnSaveChanges_Click(object sender, EventArgs e)
    {
        int wordId;

        if (Page.IsValid && Int32.TryParse(hdnCurrentWordId.Value.ToString(), out wordId)) // Edit word
        {
            if (ddlLanguage.SelectedValue == "1")
            {
                DictionaryModel.English_Bulgarian word = entities.English_Bulgarian.FirstOrDefault(w => w.Id == wordId);
                word.Word          = txtWord.Text;
                word.Тranscription = "[" + txtТranscription.Text + "]";
                word.Description   = txtDescription.Text;
            }
            else if (ddlLanguage.SelectedValue == "2")
            {
                DictionaryModel.Bulgarian_English word = entities.Bulgarian_English.FirstOrDefault(w => w.Id == wordId);
                word.Word          = txtWord.Text;
                word.Тranscription = txtТranscription.Text;// +"]";
                word.Description   = txtDescription.Text;
            }
            entities.SaveChanges();

            ClearAllControls();
            lblResult.Text = "Думата е променена успешно.";
        }

        else // Add new Word
        {
            if (ddlLanguage.SelectedValue == "1")
            {
                DictionaryModel.English_Bulgarian word = new DictionaryModel.English_Bulgarian();
                word.Word          = txtWord.Text;
                word.Тranscription = "[" + txtТranscription.Text + "]";
                word.Description   = txtDescription.Text;

                entities.English_Bulgarian.AddObject(word);
            }
            else if (ddlLanguage.SelectedValue == "2")
            {
                DictionaryModel.Bulgarian_English word = new DictionaryModel.Bulgarian_English();
                word.Word = txtWord.Text;
                //word.Тranscription = "[" + txtТranscription.Text + "]";
                word.Description = txtDescription.Text;

                entities.Bulgarian_English.AddObject(word);
            }
            entities.SaveChanges();

            ClearAllControls();
            lblResult.Text            = "Думата е добавена успешно.";
            pnlEditWord.Visible       = true;
            pnlExistingsWords.Visible = false;
            lbtnCancelChanges.Text    = "Назад";
        }
    }
Exemplo n.º 2
0
    protected void GridViewAllWords_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int wordId;

        if (Int32.TryParse(e.CommandArgument.ToString(), out wordId))
        {
            if (e.CommandName == "EditWord")
            {
                pnlExistingsWords.Visible = false;
                pnlEditWord.Visible       = true;

                if (ddlLanguage.SelectedValue == "1")
                {
                    DictionaryModel.English_Bulgarian word = entities.English_Bulgarian.FirstOrDefault(w => w.Id == wordId);
                    txtWord.Text           = word.Word;
                    txtТranscription.Text  = word.Тranscription == null ? string.Empty : word.Тranscription.Replace("]", "").Replace("[", "");
                    txtDescription.Text    = word.Description;
                    hdnCurrentWordId.Value = wordId.ToString();
                }
                else if (ddlLanguage.SelectedValue == "2")
                {
                    DictionaryModel.Bulgarian_English word = entities.Bulgarian_English.FirstOrDefault(w => w.Id == wordId);
                    txtWord.Text           = word.Word;
                    txtТranscription.Text  = word.Тranscription == null ? string.Empty : word.Тranscription.Replace("]", "").Replace("[", "");
                    txtDescription.Text    = word.Description;
                    hdnCurrentWordId.Value = wordId.ToString();
                }
            }
            else if (e.CommandName == "DeleteWord")
            {
                if (ddlLanguage.SelectedValue == "1")
                {
                    DictionaryModel.English_Bulgarian word = entities.English_Bulgarian.FirstOrDefault(w => w.Id == wordId);
                    entities.DeleteObject(word);
                }
                else if (ddlLanguage.SelectedValue == "2")
                {
                    DictionaryModel.Bulgarian_English word = entities.Bulgarian_English.FirstOrDefault(w => w.Id == wordId);
                    entities.DeleteObject(word);
                }


                entities.SaveChanges();
                DataBindGridViewAllWords();
                lblResult.Text = "Думата е изтрита успешно.";
            }
        }
    }