Untitled
unknown
plain_text
3 years ago
1.6 kB
3
Indexable
Never
using AutoMapper; using FirstDemo.Training.BusinessObjects; using FirstDemo.Training.UnitOfWorks; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using StudentEntity = FirstDemo.Training.Entities.Student; using CourseStudentEntity = FirstDemo.Training.Entities.CourseStudent; namespace FirstDemo.Training.Services { public class CourseEnrollmentService : ICourseEnrollmentService { private readonly ICourseEnrollmentUnitOfWork _courseEnrollmentUnitOfWork; private readonly IMapper _mapper; public CourseEnrollmentService(IMapper mapper, ICourseEnrollmentUnitOfWork courseEnrollmentUnitOfWork) { _mapper = mapper; _courseEnrollmentUnitOfWork = courseEnrollmentUnitOfWork; } public void EnrollStudent(Course course, Student student) { var courseEntity = _courseEnrollmentUnitOfWork.Courses.GetById(course.Id); var studentEntity = _courseEnrollmentUnitOfWork.Students.GetById(student.Id); _mapper.Map(student, studentEntity); //var studentEntity = _mapper.Map<StudentEntity>(student); CourseStudentEntity courseStudent = new CourseStudentEntity(); courseStudent.Student = studentEntity; courseEntity.Students = new List<CourseStudentEntity>(); courseEntity.Students.Add(courseStudent); _courseEnrollmentUnitOfWork.Save(); } } }