public void EditResource(ResourceEntity resource)
        {
            ResourcesRepository resRepo = new ResourcesRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    resRepo.Update(EntitiesMapper.ToDbModel(resource), uow);
                    uow.ApplyChanges();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error editing resource " + resource, ex);
                    throw ex;
                }
            }
        }
        public void EditTeacher(TeacherEntity teacher)
        {
            TeachersRepository teachRepo = new TeachersRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    teachRepo.Update(EntitiesMapper.ToDbModel(teacher), uow);
                    uow.ApplyChanges();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error editing teacher " + teacher, ex);
                    throw ex;
                }
            }
        }
        public void EditEnrollment(EnrollmentEntity enroll)
        {
            EnrollmentsRepository enrollRepo = new EnrollmentsRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    enrollRepo.Update(EntitiesMapper.ToDbModel(enroll), uow);
                    uow.ApplyChanges();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error editing enrollment " + enroll, ex);
                    throw ex;
                }
            }
        }
        public void EditCourse(CourseEntity course)
        {
            CoursesRepository courseRepo = new CoursesRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    courseRepo.Update(EntitiesMapper.ToDbModel(course), uow);
                    uow.ApplyChanges();
                }
                catch (Exception ex)
                {
                    uow.Rollback();
                    DbLog.LogError("Error editing course " + course, ex);
                    throw ex;
                }
            }
        }
        public void InsertResource(ResourceEntity res)
        {
            ResourcesRepository resRepo = new ResourcesRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    resRepo.Create(EntitiesMapper.ToDbModel(res), uow);
                    uow.ApplyChanges();
                }
                catch (Exception ex)
                {
                    uow.Rollback();
                    DbLog.LogError("Error inserting resource " + res, ex);
                    throw ex;
                }
            }
        }
        public List <ResourceEntity> GetResourcesByPartialUsername(string partUsername)
        {
            List <ResourceEntity> result  = new List <ResourceEntity>();
            ResourcesRepository   resRepo = new ResourcesRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    var resList = resRepo.GetResourcesByPartialUsername(partUsername, uow);
                    result = resList.Select(x => EntitiesMapper.ToEntity(x)).ToList();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error retrieving resources " + partUsername, ex);
                    throw ex;
                }
            }
            return(result);
        }
        public TeacherEntity GetTeacherById(int id)
        {
            TeacherEntity      result    = null;
            TeachersRepository teachRepo = new TeachersRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    var res = teachRepo.GetTeacherByID(id, uow);
                    result = res != null?EntitiesMapper.ToEntity(res) : null;
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error retrieving teacher " + id, ex);
                    throw ex;
                }
            }
            return(result);
        }
        public List <TeacherEntity> GetAllTeachers()
        {
            List <TeacherEntity> result    = new List <TeacherEntity>();
            TeachersRepository   teachRepo = new TeachersRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    var list = teachRepo.GetAllTeachers(uow);
                    result = list.Select(x => EntitiesMapper.ToEntity(x)).ToList();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error retrieving all teachers", ex);
                    throw ex;
                }
            }
            return(result);
        }
        public ResourceEntity GetResourceById(int id)
        {
            ResourceEntity      result  = null;
            ResourcesRepository resRepo = new ResourcesRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    var res = resRepo.GetResourceByID(id, uow);
                    result = res != null?EntitiesMapper.ToEntity(res) : null;
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error retrieving resource " + id, ex);
                    throw ex;
                }
            }
            return(result);
        }
        public EnrollmentEntity GetEnrollmentById(int id)
        {
            EnrollmentEntity      result     = null;
            EnrollmentsRepository enrollRepo = new EnrollmentsRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    var res = enrollRepo.GetEnrollmentByID(id, uow);
                    result = res != null?EntitiesMapper.ToEntity(res) : null;
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error retrieving enrollment " + id, ex);
                    throw ex;
                }
            }
            return(result);
        }
        public List <EnrollmentEntity> GetAllenrollments()
        {
            List <EnrollmentEntity> result     = new List <EnrollmentEntity>();
            EnrollmentsRepository   enrollRepo = new EnrollmentsRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    var list = enrollRepo.GetAllEnrollments(uow);
                    result = list.Select(x => EntitiesMapper.ToEntity(x)).ToList();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error retrieving all Enrollments", ex);
                    throw ex;
                }
            }
            return(result);
        }
        public List <ResourceEntity> GetAllResources()
        {
            List <ResourceEntity> result  = new List <ResourceEntity>();
            ResourcesRepository   resRepo = new ResourcesRepository();

            using (var uow = UnitOfWork.CreateUoW())
            {
                try
                {
                    var resList = resRepo.GetAllResources(uow);
                    result = resList.Select(x => EntitiesMapper.ToEntity(x)).ToList();
                }
                catch (Exception ex)
                {
                    DbLog.LogError("Error retrieving all resources", ex);
                    throw ex;
                }
            }
            return(result);
        }