示例#1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            //Get value from UI
            string   name      = textBoxName.Text.Trim();
            string   rollno    = textBoxRollNo.Text.Trim();
            string   grade     = comboBoxGrade.SelectedItem.ToString();
            DateTime enrolDate = dateTimePickerEnrolDate.Value;
            bool     isActive  = checkBoxIsActive.Checked;

            //Save to database
            Student s = new Student();

            s.Name      = name;
            s.RollNo    = Convert.ToInt32(rollno);
            s.Grade     = grade;
            s.EnrolDate = enrolDate;
            s.Active    = isActive;

            StudentApp app     = new StudentApp();
            bool       success = app.CreateStudent(s);

            //Show the result
            if (success == true)
            {
                MessageBox.Show("Save succesful");
            }
            else
            {
                MessageBox.Show("Save failed");
            }
        }
        public ActionResult Create(StudentModel student)
        {
            StudentApp app = new StudentApp();

            //save to database
            Student s = new Student();

            s.Name      = student.Name;
            s.RollNo    = student.RollNo;
            s.EnrolDate = student.EnrolDate;
            s.Grade     = student.Grade;
            s.Active    = student.Active;

            bool success = app.CreateStudent(s);

            //show result
            if (success == true)
            {
                return(RedirectToAction("Success"));
            }
            else
            {
                return(RedirectToAction("Fail"));
            }
        }