diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs index c94df7923448ce7fc4e1af8b3d24d8d8adfe01af..19b56f853a2c8cb1db658771f40e43ca5a466815 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs @@ -30,9 +30,8 @@ namespace Tsi1.Api.Controllers { var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value; - var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value); - var result = await _courseService.GetCoursePreviews(userType, tenantId); + var result = await _courseService.GetCoursePreviews(userId, userType); if (result.HasError) { return BadRequest(result.Message); diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs index 2d89f2d51a75d6fe72be9e61e968c0d63796e5db..082798fedb9a2cc7a9802f2266558a00e8111c8d 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs @@ -10,7 +10,7 @@ namespace Tsi1.BusinessLayer.Interfaces { public interface ICourseService { - Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(string userType, int tenantId); + Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(int userId, string userType); Task<ServiceResult<Course>> Create(CourseCreateDto newCourse); diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs index 8ca7b4017631c59d7b2ce394d666fd94257a782f..4f8db3fc7b9bc1dfac00432c60f33e838baa8dc5 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs @@ -48,17 +48,26 @@ namespace Tsi1.BusinessLayer.Services return result; } - public async Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(string userType, int tenantId) + public async Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(int userId, string userType) { var result = new ServiceResult<List<CoursePreviewDto>>(); var courses = new List<Course>(); + var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == userId); + + if (user == null) + { + result.HasError = true; + result.Message = string.Format(ErrorMessages.UserDoesNotExist, userId); + return result; + } + if (userType == UserTypes.Student) { courses = await _context.StudentCourses .Include(x => x.Course) - .Where(x => x.Course.TenantId == tenantId) + .Where(x => x.StudentId == user.StudentId) .Select(x => x.Course) .ToListAsync(); } @@ -66,7 +75,7 @@ namespace Tsi1.BusinessLayer.Services { courses = await _context.ProfessorCourses .Include(x => x.Course) - .Where(x => x.Course.TenantId == tenantId) + .Where(x => x.ProfessorId == user.ProfessorId) .Select(x => x.Course) .ToListAsync(); }