public static School ToSchoolEntity(SchoolModel schoolModel, IUnitOfWork unitOfWork) { School school = new School() { Name = schoolModel.Name, Location = schoolModel.Location }; foreach (StudentModel student in schoolModel.Students) { school.Students.Add(Extensions.CreateOrLoadStudent(student, unitOfWork)); } return school; }
public HttpResponseMessage Add(SchoolModel schoolModel) { var httpResponse = this.PerformOperation(() => { var schoolEntity = SchoolsMapper.ToSchoolEntity(schoolModel, unitOfWork); this.unitOfWork.SchoolsRepository.Add(schoolEntity); this.unitOfWork.Save(); schoolModel.ID = schoolEntity.ID; return schoolModel; }); return httpResponse; }
public static SchoolModel ToSchoolModel(School schoolEntity) { SchoolModel school = new SchoolModel() { ID = schoolEntity.ID, Name = schoolEntity.Name, Location = schoolEntity.Location }; foreach (Student student in schoolEntity.Students) { school.Students.Add(StudentsMapper.ToStudentModel(student)); } return school; }