示例#1
0
        public void should_Add_Student()
        {
            using (var dbContextTransaction = _dbContext.Database.BeginTransaction())
            {
                var student = new Student()
                {
                    RefNo = "12456343", FirstName = "John", LastName = "Smith", DateOfBirth = DateTime.Now.AddYears(-10), CampusID = 1
                };
                _studentService.Insert(student);
                Assert.True(student.StudentID > 0);

                dbContextTransaction.Rollback();
            }
        }
示例#2
0
        public async Task <IActionResult> PostStudent(Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await StudentsService.Insert(student);

                    return(CreatedAtAction(nameof(GetStudent), new { id = student.ID }, student));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log)
                ModelState.AddModelError("", "Unable to saves changes. " +
                                         "Try again, and if the problems persists " +
                                         "see your system administrator");
            }
            return(BadRequest());
        }
示例#3
0
 //添加
 public static int Add(Students students)
 {
     return(service.Insert(students));
 }