Esempio n. 1
0
        public void changeButton_Click(object sender, EventArgs e)
        {
            if (!(dataGridView1.SelectedRows.Count > 0))
            {
                return;
            }
            AddReaderForm    addReaderForm    = new AddReaderForm();
            ReaderRepository readerRepository = new ReaderRepository();

            int  index     = dataGridView1.SelectedRows[0].Index;
            int  id        = 0;
            bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);

            if (converted == false)
            {
                return;
            }

            Reader reader = readerRepository.FindById(id);

            addReaderForm.nameTextBox.Text       = reader.Name;
            addReaderForm.surnameTextBox.Text    = reader.Surname;
            addReaderForm.patronymicTextBox.Text = reader.Patronymic;
            addReaderForm.dateTimePicker.Value   = reader.DateOfBirth;
            addReaderForm.emailTextBox.Text      = reader.Email;
            addReaderForm.telNumberTextBox.Text  = reader.TelephoneNumber;

            DialogResult dialogResult = addReaderForm.ShowDialog(this);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }

            string   name       = addReaderForm.nameTextBox.Text;
            string   surname    = addReaderForm.surnameTextBox.Text;
            string   patronymic = addReaderForm.patronymicTextBox.Text;
            DateTime DoB        = addReaderForm.dateTimePicker.Value;
            string   email      = addReaderForm.emailTextBox.Text;
            string   telNumber  = addReaderForm.telNumberTextBox.Text;


            reader.Name            = name;
            reader.Surname         = surname;
            reader.Patronymic      = patronymic;
            reader.DateOfBirth     = DoB;
            reader.Email           = email;
            reader.TelephoneNumber = telNumber;


            readerRepository.Update(reader);

            _db.SaveChanges();
            SetDataGridView();
        }
Esempio n. 2
0
        public ActionResult Edit(EditProfile Ep)
        {
            ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString);
            Reader           R  = MapToDbModels.EditReader(Ep);

            if (Rr.Update(R))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }