public StudentViewModel(Student student) { if (student == null) { throw new ArgumentNullException("student"); } _student = student; }
public void SaveStudent(Student student) { // If current student is a new record, it means this student is a new tuple, so we // need to add it into table if (student.IsNew) { AddStudent(student); } else { // Otherwise, the student may have existed, we need to find it and update its values to current values // Here, we use LINQ to search the student. var target = Students.AsEnumerable().FirstOrDefault(p => p.Field<Guid>(Student.StudentIDPropertyName) == student.StudentID); if (target != null) // We indeed found our wanted student record, so update it { target.SetField<string>(Student.NamePropertyName, student.Name); target.SetField<int>(Student.AgePropertyName, student.Age); target.SetField<Gender>(Student.GenderPropertyName, student.Gender); target.SetField<string>(Student.DescriptionPropertyName, student.Description); } } _data.AcceptChanges(); this.Save(); }
/// <summary> /// Adds one student as a new row to Students table /// </summary> /// <param name="student"></param> private void AddStudent(Student student) { Students.Rows.Add(new object[] { student.StudentID, student.Name, student.Age, student.Gender, student.Description }); }
public StudentViewModel() { Student newStudent = Student.CreateNewStudent(string.Empty, 18, Gender.Male, string.Empty); _student = newStudent; }