You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using xUnitStudy.IDal;
|
|
|
|
|
using xUnitStudy.Model;
|
|
|
|
|
|
|
|
|
|
namespace xUnitStudy.Dal
|
|
|
|
|
{
|
|
|
|
|
public class StudentDal : IStudentDal
|
|
|
|
|
{
|
|
|
|
|
public StudentDal()
|
|
|
|
|
{
|
|
|
|
|
students = new List<Student>()
|
|
|
|
|
{
|
|
|
|
|
new Student(){Id=1,Name="王高峰",Age=20 },
|
|
|
|
|
new Student(){ Id=2,Name="张三",Age=35 },
|
|
|
|
|
new Student(){ Id=3,Name="李四",Age=15 },
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Student> students;
|
|
|
|
|
|
|
|
|
|
public List<Student> Students
|
|
|
|
|
{
|
|
|
|
|
get { return students; }
|
|
|
|
|
set { value = students; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public (bool result, Student student) AddStudent(Student student)
|
|
|
|
|
{
|
|
|
|
|
var find = Students.FirstOrDefault(s => s.Id == student.Id);
|
|
|
|
|
if (find != null)
|
|
|
|
|
{
|
|
|
|
|
return (false, null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Students.Add(student);
|
|
|
|
|
|
|
|
|
|
return (true, student);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Student> GetAll()
|
|
|
|
|
{
|
|
|
|
|
return this.Students;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Student GetStudentById(int studentId)
|
|
|
|
|
{
|
|
|
|
|
var student = Students.FirstOrDefault(s => s.Id == studentId);
|
|
|
|
|
return student;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public (bool result, Student student) UpdateStudent(Student student)
|
|
|
|
|
{
|
|
|
|
|
var find = Students.FirstOrDefault(s => s.Id == student.Id);
|
|
|
|
|
|
|
|
|
|
if (find != null)
|
|
|
|
|
{
|
|
|
|
|
Students.Remove(find);
|
|
|
|
|
Students.Add(student);
|
|
|
|
|
return (true, student);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (false, student);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteStudent(int studentId)
|
|
|
|
|
{
|
|
|
|
|
var student = Students.FirstOrDefault(s => s.Id == studentId);
|
|
|
|
|
if (student == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Students.Remove(student);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|