Untitled
unknown
plain_text
4 years ago
1.6 kB
9
Indexable
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();
}
}
}
Editor is loading...