public void UpdateTest() { Student student = new Student("Update1", "Surname1", new DateTime(2001, 01, 01)); List <Student> students = manager.Read(); int idToCheck = students[testRowIndex].Id; manager.Update(student, idToCheck); Student testStudent = manager.SelectStudentById(idToCheck); Assert.AreEqual("Update1", testStudent.Name); }
/// <summary> /// 保存学生 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_save_Click(object sender, EventArgs e) { Student studentEntity = new Student(); studentEntity.Name = this.txt_name.Text; int age; if (int.TryParse(this.txt_age.Text, out age)) { if (age <= 0 || age > 100) { MessageBox.Show("请输入正确的年龄!"); return; } studentEntity.Age = age; } else { MessageBox.Show("请输入正确的年龄!"); this.txt_age.Text = ""; return; } if (this.radioButton_man.Checked) { studentEntity.Sex = 1; } else { studentEntity.Sex = 2; } studentEntity.Birthday = this.dateTimePicker_birthday.Value.Date; //数据库操作 StudentDao studentDao = new StudentDao(); if (student == null) { var id = studentDao.Insert(studentEntity); studentEntity.Id = id; student = new StudentViewModel(studentEntity); } else { studentEntity.Id = student.Id; studentDao.Update(studentEntity); student.Name = studentEntity.Name; student.Age = studentEntity.Age; student.Sex = studentEntity.Sex == 1?"男":"女"; student.Birthday = studentEntity.Birthday; } this.DialogResult = DialogResult.OK; this.Close(); }
public void Update(string Name, string Surname, DateTime DateofBirth, string StudentId, string typo) { Student student = new Student(); student.Name = Name; student.Surname = Surname; student.DateofBirth = DateofBirth.ToString(); student.StudentId = Int32.Parse(StudentId); StudentDao studenCreator = FactoryProvider.GetFactory(typo).Creator(typo); studenCreator.Update(student); }
public ActionResult Edit(Model.EF.Student tmp) { var session = (AdminLogin)Session[CommonConstants.USER_SESSION]; if (session.id_permission != 1) { return(View("Error")); } ViewBag.AdminName = session.name; var dao = new StudentDao(); if (!dao.IsUserNameIDExist(tmp.username, tmp.id_student)) { ModelState.AddModelError("", "Tên đăng nhập đã tồn tại."); } else { if (!string.IsNullOrEmpty(tmp.password)) { var encryptedMd5Pas = Encryptor.MD5Hash(tmp.password); tmp.password = encryptedMd5Pas; } var id = dao.Update(tmp); if (id) { SetNotice("Hệ thống đã sửa thành công " + tmp.student_name + ".", "success"); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Cập nhật tài khoản không thành công."); } } SetViewBag(tmp.id_student); return(View()); }
public void Put([FromBody] Student student) { var repository = new StudentDao(); repository.Update(student); }