本文整理汇总了C#中Student.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Student.Save方法的具体用法?C# Student.Save怎么用?C# Student.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Student
的用法示例。
在下文中一共展示了Student.Save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(Student student)
{
if (ModelState.IsValid && student.Save())
{
return RedirectToAction("Edit", "Groups", new { id=student.GroupId});
}
else
{
ViewBag.Group = student.Group;
ViewBag.Instructor = student.Group.Instructor;
ViewBag.OrganizationId = new SelectList(Organization.All(), "Id", "Name");
ViewBag.EmployeeId = new SelectList(Employee.FindByOrganization(-1));
return View(student);
}
}
示例2: HomeModule
public HomeModule()
{
Get["/"]=_=>View["index.cshtml"];
Get["/courses"]=_=>
{
List<Course> allCourses = Course.GetAll();
return View["courses.cshtml", allCourses];
};
Get["/courses/new"]=_=>{
List<Department> departments = Department.GetAll();
return View["course_new.cshtml" , departments];
};
Post["/courses/new"]=_=>
{
Course newCourse = new Course(Request.Form["course-name"], Request.Form["department"]);
newCourse.Save();
List<Course> allCourses = Course.GetAll();
return View["courses.cshtml", allCourses];
};
// Get["courses/{id}"] = parameters =>
// {
// Course course = Course.Find(parameters.id);
// return View["course.cshtml", course];
// };
Get["students/{id}"] = parameters =>
{
Student student = Student.Find(parameters.id);
return View["student.cshtml", student];
};
Get["/students"]=_=>
{
List<Student> allStudents = Student.GetAll();
return View["students.cshtml", allStudents];
};
Get["/students/new"]=_=>View["student_new.cshtml"];
Post["/students/new"]=_=>
{
Student newStudent = new Student(Request.Form["student-name"], Request.Form["enrollment-date"]);
newStudent.Save();
List<Student> allStudents = Student.GetAll();
return View["students.cshtml", allStudents];
};
Post["/students/{id}/addCourse"] = parameters =>
{
Student student = Student.Find(parameters.id);
student.AddCourse(Request.Form["course"]);
return View["student.cshtml", student];
};
Post["/students/{id}/deleteCourse"] = parameters =>
{
Student student = Student.Find(parameters.id);
student.DropCourse(Request.Form["course"]);
return View["student.cshtml", student];
};
Post["/students/{id}/updatemajors"]=parameters=>
{
Student student = Student.Find(parameters.id);
int majorCount = student.GetMajors().Count;
if(majorCount == 0 && Request.Form["new-major"] !=0)
{
student.AddMajor(Request.Form["new-major"]);
}
else if(majorCount == 1)
{
if(Request.Form["current-major"]==0)
{
student.DropMajor(Request.Form["current-major"]);
}
else if(Request.Form["current-major"]!=student.GetMajors()[0].GetId())
{
student.DropMajor(student.GetMajors()[0].GetId());
student.AddMajor(Request.Form["current-major"]);
}
if(Request.Form["additional-major"] !=0)
{
student.AddMajor(Request.Form["additonal-major"]);
}
}
else
{
if(Request.Form["first-major"]==0)
{
student.DropMajor(Request.Form["first-major"]);
}
else if(Request.Form["first-major"]!=student.GetMajors()[0].GetId())
{
student.DropMajor(student.GetMajors()[0].GetId());
student.AddMajor(Request.Form["first-major"]);
}
if(Request.Form["second-major"]==0)
{
//.........这里部分代码省略.........
示例3: Save_WithAnExistingStudentImproperlyCreated_ExpectInvalidOperationException
public void Save_WithAnExistingStudentImproperlyCreated_ExpectInvalidOperationException()
{
// Arrange
var today = new DateTime(2003, 5, 17);
const int ExpectedStudentId = 897931;
var stubIndividualRepo = MockRepository.GenerateStub<IRepository<IndividualEntity>>();
stubIndividualRepo
.Stub(e => e.Update(Arg<IndividualEntity>.Is.Anything));
var stubStudentRepo = MockRepository.GenerateStub<IRepository<StudentEntity>>();
stubStudentRepo
.Stub(e => e.Retrieve(ExpectedStudentId))
.Return(null);
stubStudentRepo
.Stub(e => e.Create(Arg<StudentEntity>.Is.Anything))
.Return(23);
var classUnderTest =
new Student(stubIndividualRepo, stubStudentRepo)
{
Id = ExpectedStudentId,
Today = today,
DateOfBirth = today.AddYears(-19),
};
// Act
TestDelegate act = () => classUnderTest.Save();
// Assert
Assert.Throws<InvalidOperationException>(act);
}
示例4: SaveStudent
public ActionResult SaveStudent(AdminEditstudentViewModel m)
{
Student myStudent = new Student();
try
{
if (ModelState.IsValid)
{
myStudent.code = m.Code;
myStudent.firstName = m.FirstName;
myStudent.lastName = m.LastName;
myStudent.email = m.Email;
myStudent.grade = m.Grade;
myStudent.gender = m.Gender;
myStudent.musicalID = m.MusicalID;
myStudent.studentID = m.StudentID;
List<int> DesiredRoles = new List<int>();
DesiredRoles.Add(m.RoleID);
myStudent.Save(DesiredRoles);
StudentTime st = new StudentTime();
st.studentID = myStudent.studentID;
st.timeID = m.TimeID;
if (!st.IsAvailable())
throw new Exception("Too slow! This time has filled up. Please select another time.");
st.Save();
}
else
{
m.RoleList = MusicalRole.AllRoles(m.MusicalID).Select(r => new SelectListItem()
{
Text = r.name,
Value = r.roleID.ToString()
});
m.DateList = AuditionDate.MusicalDates(m.MusicalID).Select(r => new SelectListItem()
{
Text = ((DateTime)r.date).ToString("MM/dd/yyyy"),
Value = r.dateID.ToString()
});
if (m.DateID == 0)
m.DateID = m.DateList.Select(r => Int32.Parse(r.Value)).FirstOrDefault();
m.TimeList = AuditionTime.TimeSlots(m.DateID).Select(t => new SelectListItem()
{
Text = t.timeDescription,
Value = t.timeID.ToString()
});
return View("EditStudent", m);
}
}
catch (Exception ex)
{
m.RoleList = MusicalRole.AllRoles(m.MusicalID).Select(r => new SelectListItem()
{
Text = r.name,
Value = r.roleID.ToString()
});
m.DateList = AuditionDate.MusicalDates(m.MusicalID).Select(r => new SelectListItem()
{
Text = ((DateTime)r.date).ToString("MM/dd/yyyy"),
Value = r.dateID.ToString()
});
if (m.DateID == 0)
m.DateID = m.DateList.Select(r => Int32.Parse(r.Value)).FirstOrDefault();
m.TimeList = AuditionTime.TimeSlots(m.DateID).Select(t => new SelectListItem()
{
Text = t.timeDescription,
Value = t.timeID.ToString()
});
ModelState.AddModelError("", ex.Message);
return View("EditStudent", m);
}
return RedirectToRoute("AdminStudents", new { musicalID = myStudent.musicalID });
}
示例5: Save_WithAnExistingStudent_ExpectIndividualDalUpdateIsCalledOnce
public void Save_WithAnExistingStudent_ExpectIndividualDalUpdateIsCalledOnce()
{
// Arrange
var today = new DateTime(2003, 5, 17);
const int ExpectedStudentId = 897931;
var studentEntity = new StudentEntity { Id = ExpectedStudentId, };
var stubStudentRepo = MockRepository.GenerateStub<IRepository<StudentEntity>>();
stubStudentRepo
.Stub(e => e.Retrieve(ExpectedStudentId))
.Return(studentEntity);
var mockIndividualRepo = MockRepository.GenerateStrictMock<IRepository<IndividualEntity>>();
mockIndividualRepo
.Expect(e => e.Update(Arg<IndividualEntity>.Is.Anything))
.Repeat
.Once();
var classUnderTest =
new Student(mockIndividualRepo, stubStudentRepo)
{
Id = ExpectedStudentId,
Today = today,
DateOfBirth = today.AddYears(-19),
};
// Act
classUnderTest.Save();
// Assert
Assert.AreEqual(ExpectedStudentId, classUnderTest.Id);
mockIndividualRepo.VerifyAllExpectations();
}
示例6: Save_WithInvalidDateOfBirth_ExpectInvalidOperationException_v2
public void Save_WithInvalidDateOfBirth_ExpectInvalidOperationException_v2(
int age)
{
// Arrange
var today = new DateTime(2003, 5, 17);
var classUnderTest =
new Student(null, null)
{
Today = today,
DateOfBirth = today.AddYears(-1 * age),
};
// Act
TestDelegate act = () => classUnderTest.Save();
// Assert
Assert.Throws<InvalidOperationException>(act,
"Exception was not thrown for age {0}", age);
}
示例7: SubmitMyInfo
public ActionResult SubmitMyInfo(StudentMyInfoModel m)
{
try
{
if (ModelState.IsValid)
{
Student s = new Student(m.Code, Musical.CurrentMusical().musicalID);
s.code = m.Code;
s.firstName = m.FirstName;
s.lastName = m.LastName;
s.email = m.Email;
s.gender = m.Gender;
s.grade = m.Grade;
s.musicalID = Musical.CurrentMusical().musicalID;
List<int> DesiredRoleList = new List<int>();
if (m.DesiredRoles != null)
DesiredRoleList = m.DesiredRoles.ToList();
s.Save(DesiredRoleList);
return RedirectToRoute("StudentTime", new { code = s.code });
}
else
{
return View("MyInfo", m);
}
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
return View("MyInfo", m);
}
}
示例8: Save_WithAnExistingStudentImproperlyCreated_ExpectInvalidOperationException
public void Save_WithAnExistingStudentImproperlyCreated_ExpectInvalidOperationException()
{
// Arrange
var today = new DateTime(2003, 5, 17);
const int ExpectedStudentId = 897931;
var stubIndividualRepo = new Mock<IRepository<IndividualEntity>>();
stubIndividualRepo
.Setup(e => e.Update(It.IsAny<IndividualEntity>()));
var stubStudentRepo = new Mock<IRepository<StudentEntity>>();
stubStudentRepo
.Setup(e => e.Retrieve(ExpectedStudentId))
.Returns(default(StudentEntity));
stubStudentRepo
.Setup(e => e.Create(It.IsAny<StudentEntity>()))
.Returns(23);
var classUnderTest =
new Student(stubIndividualRepo.Object, stubStudentRepo.Object)
{
Id = ExpectedStudentId,
Today = today,
DateOfBirth = today.AddYears(-19),
};
// Act
TestDelegate act = () => classUnderTest.Save();
// Assert
Assert.Throws<InvalidOperationException>(act);
}
示例9: Save_WithAnExistingStudent_ExpectIndividualDalUpdateIsCalledOnce
public void Save_WithAnExistingStudent_ExpectIndividualDalUpdateIsCalledOnce()
{
// Arrange
var today = new DateTime(2003, 5, 17);
const int ExpectedStudentId = 897931;
var studentEntity = new StudentEntity { Id = ExpectedStudentId, };
var stubStudentRepo = new Mock<IRepository<StudentEntity>>();
stubStudentRepo
.Setup(e => e.Retrieve(ExpectedStudentId))
.Returns(studentEntity);
var mockIndividualRepo = new Mock<IRepository<IndividualEntity>>();
mockIndividualRepo
.Setup(e => e.Update(It.IsAny<IndividualEntity>()));
var classUnderTest =
new Student(mockIndividualRepo.Object, stubStudentRepo.Object)
{
Id = ExpectedStudentId,
Today = today,
DateOfBirth = today.AddYears(-19),
};
// Act
classUnderTest.Save();
// Assert
Assert.AreEqual(ExpectedStudentId, classUnderTest.Id);
mockIndividualRepo
.Verify(e => e.Update(It.IsAny<IndividualEntity>()), Times.Once());
}