diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IActivityService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IActivityService.cs index 43e11ae55cebab960701cd73efb5e620cd7c74a7..a8dfd19d3ab6d2ff3377d43fc7827d91e73eb1fd 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IActivityService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IActivityService.cs @@ -15,10 +15,6 @@ namespace Tsi1.BusinessLayer.Interfaces Task<ServiceResult<int>> Modify(int activityId, ActivityModifyDto activityDto, int userId); Task<ServiceResult<int>> Delete(int activityId, int userId); - Task<ServiceResult<int>> ActivityValidation(int activityId, int userId); - Task<ServiceResult<GradeDto>> AddOrModifyGrade(GradeDto gradeDto, int userId); - Task<ServiceResult<int>> DeleteGrade(int myUserId, int activityId, int userId); - Task<ServiceResult<List<GradeDto>>> GetMyGrades(int activityId, int userId); - Task<ServiceResult<List<GradeDto>>> GetAllGrades(int activityId, int userId); + Task<ServiceResult<int>> ActivityValidation(int activityId, int userId); } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationService.cs new file mode 100644 index 0000000000000000000000000000000000000000..c26aac04bed9b696d2ecddf95b4eed36c29bcdcd --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationService.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Tsi1.BusinessLayer.Dtos; +using Tsi1.BusinessLayer.Helpers; + +namespace Tsi1.BusinessLayer.Interfaces +{ + public interface IEvaluationService + { + Task<ServiceResult<bool>> Registration(int evaluationId, int userId); + + Task<ServiceResult<bool>> CancelRegistration(int evaluationId, int userId); + + Task<ServiceResult<bool>> SubmitLaboratory(FileDto fileDto, int evaluationId, int userId); + + Task<ServiceResult<bool>> DeleteLaboratory(int submissionId, int userId); + + Task<ServiceResult<List<MyEvaluationInscriptionDto>>> GetMyEvaluationInscriptions(int userId, int courseId); + + Task<ServiceResult<List<EvaluationInscriptionDto>>> GetAllEvaluationInscriptions(int userId, int evaluationId); + + Task<ServiceResult<bool>> QualifyEvaluationInscription(EvaluationInscriptionModifyDto evaluationInscriptionDto, int userId); + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationTypeService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationTypeService.cs new file mode 100644 index 0000000000000000000000000000000000000000..55ac35724ef5331ea100cdbd5d2e832dfdfa2c75 --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationTypeService.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Tsi1.BusinessLayer.Dtos; +using Tsi1.BusinessLayer.Helpers; + +namespace Tsi1.BusinessLayer.Interfaces +{ + public interface IEvaluationTypeService + { + public Task<ServiceResult<EvaluationTypeDto>> GetById(int id); + + public Task<ServiceResult<List<EvaluationTypeDto>>> GetAll(string userType); + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/ActivityService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/ActivityService.cs index fca3edd8d1cf94a4530a2fcb09f5b0d0dbd80832..ff629d1eaee7cfffdfc00419d14273957ef18405 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/ActivityService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/ActivityService.cs @@ -179,38 +179,15 @@ namespace Tsi1.BusinessLayer.Services return result; } - var activity = _mapper.Map<Activity>(newActivity); - _context.Activities.Add(activity); - - await _context.SaveChangesAsync(); - - result.Data = activity.Id; - return result; - } - - public async Task<ServiceResult<int>> Modify(int activityId, ActivityModifyDto activityDto, int userId) - { - var result = new ServiceResult<int>(); - - var activity = await _context.Activities.FirstOrDefaultAsync(x => x.Id == activityId); - - if (activity == null) - { - result.HasError = true; - result.AddMessage(string.Format(ErrorMessages.ActivityDoesNotExist, activityId)); - return result; - } - - var userTypeValidation = await this.UserTypeValidation(activity.CourseId, userId); - - if (userTypeValidation.HasError) + if (newActivity.IsVideoConference && newActivity.Evaluation != null) { result.HasError = true; - result.AddMessage(userTypeValidation.Message); + result.AddMessage(ErrorMessages.VideoConferenceIsNotEvaluation); return result; } - _mapper.Map(activityDto, activity); + var activity = _mapper.Map<Activity>(newActivity); + _context.Activities.Add(activity); await _context.SaveChangesAsync(); @@ -218,7 +195,7 @@ namespace Tsi1.BusinessLayer.Services return result; } - public async Task<ServiceResult<int>> Delete(int activityId, int userId) + public async Task<ServiceResult<int>> Modify(int activityId, ActivityModifyDto activityDto, int userId) { var result = new ServiceResult<int>(); @@ -240,105 +217,25 @@ namespace Tsi1.BusinessLayer.Services return result; } - _context.Activities.Remove(activity); - - await _context.SaveChangesAsync(); - - result.Data = activity.Id; - return result; - } - - public async Task<ServiceResult<GradeDto>> AddOrModifyGrade(GradeDto gradeDto, int userId) - { - var result = new ServiceResult<GradeDto>(); - - var activity = await _context.Activities.FirstOrDefaultAsync(x => x.Id == gradeDto.ActivityId); - - if (activity == null) + if (activityDto.IsVideoConference && activityDto.Evaluation != null) { result.HasError = true; - result.AddMessage(string.Format(ErrorMessages.ActivityDoesNotExist, gradeDto.ActivityId)); + result.AddMessage(ErrorMessages.VideoConferenceIsNotEvaluation); return result; } - var userTypeValidation = await this.UserTypeValidation(activity.CourseId, userId); - - if (userTypeValidation.HasError) - { - result.HasError = true; - result.AddMessage(userTypeValidation.Message); - return result; - } - - var userStudent = await _context.Users - .Include(x => x.Student) - .FirstOrDefaultAsync(x => x.Id == gradeDto.UserId); - - if (userStudent == null || userStudent.Student == null) - { - result.HasError = true; - result.AddMessage(string.Format(ErrorMessages.StudentDoesNotExist, gradeDto.UserId)); - return result; - } - - var userStudentValidation = await this.UserTypeValidation(activity.CourseId, userStudent.Id); - - if (userStudentValidation.HasError) - { - result.HasError = true; - result.AddMessage(userStudentValidation.Message); - return result; - } - - var grade = await _context.Grades - .FirstOrDefaultAsync(x => x.ActivityId == gradeDto.ActivityId && x.StudentId == userStudent.StudentId); - - if (grade == null) - { - grade = new Grade - { - ActivityId = gradeDto.ActivityId, - StudentId = (int)userStudent.StudentId - }; - - _context.Grades.Add(grade); - } - - grade.Value = gradeDto.Value; + _mapper.Map(activityDto, activity); - await _context.SaveChangesAsync(); - result.Data = gradeDto; + result.Data = activity.Id; return result; } - public async Task<ServiceResult<int>> DeleteGrade(int myUserId, int activityId, int userId) + public async Task<ServiceResult<int>> Delete(int activityId, int userId) { var result = new ServiceResult<int>(); - var userStudent = await _context.Users - .AsNoTracking() - .Include(x => x.Student) - .FirstOrDefaultAsync(x => x.Id == userId); - - if (userStudent == null || userStudent.Student == null) - { - result.HasError = true; - result.AddMessage(string.Format(ErrorMessages.StudentDoesNotExist, userStudent.Id)); - return result; - } - - var grade = await _context.Grades - .FirstOrDefaultAsync(x => x.ActivityId == activityId && x.StudentId == userStudent.StudentId); - - if (grade == null) - { - result.HasError = true; - result.AddMessage(string.Format(ErrorMessages.GradeDoesNotExist, activityId, userId)); - return result; - } - var activity = await _context.Activities.FirstOrDefaultAsync(x => x.Id == activityId); if (activity == null) @@ -357,99 +254,13 @@ namespace Tsi1.BusinessLayer.Services return result; } - _context.Grades.Remove(grade); - await _context.SaveChangesAsync(); - - return result; - } - - public async Task<ServiceResult<List<GradeDto>>> GetMyGrades(int activityId, int userId) - { - var result = new ServiceResult<List<GradeDto>>(); - - var activity = await _context.Activities.AsNoTracking().FirstOrDefaultAsync(x => x.Id == activityId); - - if (activity == null) - { - result.HasError = true; - result.AddMessage(string.Format(ErrorMessages.ActivityDoesNotExist, activityId)); - return result; - } - - var userTypeValidation = await this.UserTypeValidation(activity.CourseId, userId); - - if (userTypeValidation.HasError) - { - result.HasError = true; - result.AddMessage(userTypeValidation.Message); - return result; - } - - var user = userTypeValidation.Data; + _context.Activities.Remove(activity); - var grades = await _context.Grades - .AsNoTracking() - .Where(x => x.ActivityId == activityId && x.StudentId == user.StudentId) - .ToListAsync(); + await _context.SaveChangesAsync(); - result.Data = _mapper.Map<List<GradeDto>>(grades); + result.Data = activity.Id; return result; } - public async Task<ServiceResult<List<GradeDto>>> GetAllGrades(int activityId, int userId) - { - var result = new ServiceResult<List<GradeDto>>(); - - var activity = await _context.Activities.AsNoTracking().FirstOrDefaultAsync(x => x.Id == activityId); - - if (activity == null) - { - result.HasError = true; - result.AddMessage(string.Format(ErrorMessages.ActivityDoesNotExist, activityId)); - return result; - } - - var userTypeValidation = await this.UserTypeValidation(activity.CourseId, userId); - - if (userTypeValidation.HasError) - { - result.HasError = true; - result.AddMessage(userTypeValidation.Message); - return result; - } - - var user = userTypeValidation.Data; - - var grades = await _context.Grades - .AsNoTracking() - .Where(x => x.ActivityId == activityId) - .ToListAsync(); - - var studentIds = grades.Select(x => x.StudentId).ToList(); - - var users = await _context.Users - .AsNoTracking() - .Where(x => studentIds.Contains((int)x.StudentId)) - .ToListAsync(); - - var gradeDtos = new List<GradeDto>(); - - foreach (var grade in grades) - { - var userStudent = users.FirstOrDefault(x => x.StudentId == grade.StudentId); - - var gradeDto = new GradeDto - { - ActivityId = grade.ActivityId, - UserId = userStudent.Id, - Value = grade.Value - }; - - gradeDtos.Add(gradeDto); - } - - result.Data = gradeDtos; - return result; - } } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationService.cs new file mode 100644 index 0000000000000000000000000000000000000000..9d20685d06a2bd51aef9f7dcc1826753ab0a56c0 --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationService.cs @@ -0,0 +1,420 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tsi1.BusinessLayer.Dtos; +using Tsi1.BusinessLayer.Helpers; +using Tsi1.BusinessLayer.Interfaces; +using Tsi1.DataLayer; +using Tsi1.DataLayer.Entities; + +namespace Tsi1.BusinessLayer.Services +{ + public class EvaluationService : IEvaluationService + { + private readonly Tsi1Context _context; + private readonly IMapper _mapper; + private readonly IFileService _fileService; + + public EvaluationService(Tsi1Context context, IMapper mapper, IFileService fileService) + { + _context = context; + _mapper = mapper; + _fileService = fileService; + } + + public async Task<ServiceResult<bool>> CancelRegistration(int evaluationId, int userId) + { + var result = new ServiceResult<bool>(); + + var validation = await this.StudentValidation(evaluationId, userId); + + if (validation.HasError) + { + result.HasError = true; + result.AddMessage(validation.Message); + return result; + } + + var studentId = validation.Data; + + var evaluationInscription = await _context.EvaluationInscriptions + .FirstOrDefaultAsync(x => x.EvaluationId == evaluationId && x.StudentId == studentId); + + if (evaluationInscription == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationInscriptionDoesNotExists, studentId, evaluationId)); + return result; + } + + if (evaluationInscription.HasAttended) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationInscriptionHasAttended, studentId, evaluationId)); + return result; + } + + _context.EvaluationInscriptions.Remove(evaluationInscription); + + await _context.SaveChangesAsync(); + + return result; + } + + public async Task<ServiceResult<bool>> DeleteLaboratory(int submissionId, int userId) + { + var result = new ServiceResult<bool>(); + + var user = await _context.Users + .AsNoTracking() + .Include(x => x.Student) + .FirstOrDefaultAsync(x => x.Id == userId); + + if (user == null || user.Student == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.UserDoesNotExist, userId)); + return result; + } + + var studentId = user.StudentId; + + var submission = await _context.Submissions.FirstOrDefaultAsync(x => x.Id == submissionId); + + if (submission == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.SubmissionDoesNotExists, submissionId)); + return result; + } + + if (submission.StudentId != studentId) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.InavalidUserSubmission, submissionId, studentId)); + return result; + } + + _context.Submissions.Remove(submission); + + await _context.SaveChangesAsync(); + + return result; + } + + public async Task<ServiceResult<List<EvaluationInscriptionDto>>> GetAllEvaluationInscriptions(int userId, int evaluationId) + { + var result = new ServiceResult<List<EvaluationInscriptionDto>>(); + + var validation = await this.ProfessorValidation(evaluationId, userId); + + if (validation.HasError) + { + result.HasError = true; + result.AddMessage(validation.Message); + return result; + } + + var evaluationInscriptions = await _context.EvaluationInscriptions + .Where(x => x.EvaluationId == evaluationId) + .ToListAsync(); + + result.Data = _mapper.Map<List<EvaluationInscriptionDto>>(evaluationInscriptions); + return result; + } + + public async Task<ServiceResult<List<MyEvaluationInscriptionDto>>> GetMyEvaluationInscriptions(int userId, int courseId) + { + var result = new ServiceResult<List<MyEvaluationInscriptionDto>>(); + + var course = await _context.Courses + .AsNoTracking() + .FirstOrDefaultAsync(x => x.Id == courseId); + + if (course == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.CourseDoesNotExist, courseId)); + return result; + } + + var user = await _context.Users + .AsNoTracking() + .Include(x => x.Student) + .FirstOrDefaultAsync(x => x.Id == userId); + + if (user == null || user.Student == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.UserDoesNotExist, userId)); + return result; + } + + var studentCourse = await _context.StudentCourses + .AsNoTracking() + .FirstOrDefaultAsync(x => x.StudentId == user.StudentId && x.CourseId == courseId); + + if (studentCourse == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.StudentCourseDoesNotExists, user.StudentId, courseId)); + return result; + } + + var evaluationInscriptions = await _context.EvaluationInscriptions + .AsNoTracking() + .Include(x => x.Evaluation) + .ThenInclude(x => x.Activity) + .Include(x => x.Evaluation) + .ThenInclude(x => x.EvaluationType) + .Where(x => x.StudentId == user.StudentId) + .ToListAsync(); + + var myEvaluationInscriptionDtos = new List<MyEvaluationInscriptionDto>(); + + foreach (var evaluationInscription in evaluationInscriptions) + { + var myEvaluationInscriptionDto = new MyEvaluationInscriptionDto + { + ActivityName = evaluationInscription.Evaluation.Activity.Name, + EvaluationTypeId = evaluationInscription.EvaluationId, + EvaluationType = evaluationInscription.Evaluation.EvaluationType.Name, + Grade = evaluationInscription.Grade, + HasAttended = evaluationInscription.HasAttended, + }; + + myEvaluationInscriptionDtos.Add(myEvaluationInscriptionDto); + } + + result.Data = myEvaluationInscriptionDtos; + return result; + } + + public async Task<ServiceResult<bool>> QualifyEvaluationInscription(EvaluationInscriptionModifyDto evaluationInscriptionDto, int userId) + { + var result = new ServiceResult<bool>(); + + var evaluationId = evaluationInscriptionDto.EvaluationId; + var studentId = evaluationInscriptionDto.StudentId; + + var validation = await this.ProfessorValidation(evaluationId, userId); + + if (validation.HasError) + { + result.HasError = true; + result.AddMessage(validation.Message); + return result; + } + + var evaluationInscription = await _context.EvaluationInscriptions + .FirstOrDefaultAsync(x => x.EvaluationId == evaluationId && x.StudentId == studentId); + + if (evaluationInscription == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationInscriptionDoesNotExists, studentId, evaluationId)); + return result; + } + + evaluationInscription.Grade = evaluationInscriptionDto.Grade; + evaluationInscription.HasAttended = true; + + await _context.SaveChangesAsync(); + + return result; + } + + public async Task<ServiceResult<bool>> Registration(int evaluationId, int userId) + { + var result = new ServiceResult<bool>(); + + var validation = await this.StudentValidation(evaluationId, userId); + + if (validation.HasError) + { + result.HasError = true; + result.AddMessage(validation.Message); + return result; + } + + var studentId = validation.Data; + + var evaluationInscription = await _context.EvaluationInscriptions + .AsNoTracking() + .FirstOrDefaultAsync(x => x.EvaluationId == evaluationId && x.StudentId == studentId); + + if (evaluationInscription != null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationInscriptionAlreadyExists, studentId, evaluationId)); + return result; + } + + var newEvaluationInscription = new EvaluationInscription + { + EvaluationId = evaluationId, + StudentId = studentId, + Grade = 0, + HasAttended = false, + }; + + _context.EvaluationInscriptions.Add(newEvaluationInscription); + + await _context.SaveChangesAsync(); + + return result; + } + + public async Task<ServiceResult<bool>> SubmitLaboratory(FileDto fileDto, int evaluationId, int userId) + { + var result = new ServiceResult<bool>(); + + var validation = await this.StudentValidation(evaluationId, userId); + + if (validation.HasError) + { + result.HasError = true; + result.AddMessage(validation.Message); + return result; + } + + var studentId = validation.Data; + + var evaluation = await _context.Evaluations + .Include(x => x.Submissions) + .FirstOrDefaultAsync(x => x.Id == evaluationId); + + var studentIds = evaluation.Submissions.Select(x => x.StudentId); + + if (studentIds.Contains(studentId)) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.SubmissionAlreadyExists, studentId, evaluationId)); + return result; + } + + if (!_fileService.ExistFile(fileDto.Path)) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.FileDoesNotExist, fileDto.Path)); + return result; + } + + var file = _mapper.Map<File>(fileDto); + + var newSubmission = new Submission + { + File = file, + StudentId = studentId, + Grade = 0, + IsCompleted = false, + }; + + evaluation.Submissions.Add(newSubmission); + + await _context.SaveChangesAsync(); + + return result; + } + + private async Task<ServiceResult<int>> StudentValidation(int evaluationId, int userId) + { + var result = new ServiceResult<int>(); + + var evaluation = await _context.Evaluations + .AsNoTracking() + .Include(x => x.Activity) + .FirstOrDefaultAsync(x => x.Id == evaluationId); + + if (evaluation == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationDoesNotExist, evaluationId)); + return result; + } + + if (evaluation.IsCompleted) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationIsCompleted, evaluationId)); + return result; + } + + var user = await _context.Users + .AsNoTracking() + .Include(x => x.Student) + .FirstOrDefaultAsync(x => x.Id == userId); + + if (user == null || user.Student == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.UserDoesNotExist, userId)); + return result; + } + + var activityCourseId = evaluation.Activity.CourseId; + + var studentCourse = await _context.StudentCourses + .AsNoTracking() + .FirstOrDefaultAsync(x => x.CourseId == activityCourseId && x.StudentId == user.StudentId); + + if (studentCourse == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.StudentCourseDoesNotExists, user.StudentId, activityCourseId)); + return result; + } + + result.Data = (int)user.StudentId; + return result; + } + + private async Task<ServiceResult<int>> ProfessorValidation(int evaluationId, int userId) + { + var result = new ServiceResult<int>(); + + var evaluation = await _context.Evaluations + .AsNoTracking() + .Include(x => x.Activity) + .FirstOrDefaultAsync(x => x.Id == evaluationId); + + if (evaluation == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationDoesNotExist, evaluationId)); + } + + var user = await _context.Users + .AsNoTracking() + .Include(x => x.Professor) + .FirstOrDefaultAsync(x => x.Id == userId); + + if (user == null || user.Professor == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.ProfessorDoesNotExist, userId)); + return result; + } + + var activityCourseId = evaluation.Activity.CourseId; + + var professorCourse = await _context.ProfessorCourses + .AsNoTracking() + .FirstOrDefaultAsync(x => x.CourseId == activityCourseId && x.ProfessorId == user.ProfessorId); + + if (professorCourse == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.ProfessorCourseDoesNotExists, user.ProfessorId, activityCourseId)); + return result; + } + + result.Data = (int)user.ProfessorId; + return result; + } + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationTypeService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationTypeService.cs new file mode 100644 index 0000000000000000000000000000000000000000..d2ce280ffb68f1bdf6295dc05188251b61540e7d --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationTypeService.cs @@ -0,0 +1,54 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Tsi1.BusinessLayer.Dtos; +using Tsi1.BusinessLayer.Helpers; +using Tsi1.BusinessLayer.Interfaces; +using Tsi1.DataLayer; + +namespace Tsi1.BusinessLayer.Services +{ + public class EvaluationTypeService : IEvaluationTypeService + { + private readonly Tsi1Context _context; + private readonly IMapper _mapper; + + public EvaluationTypeService(Tsi1Context context, IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task<ServiceResult<List<EvaluationTypeDto>>> GetAll(string userType) + { + var result = new ServiceResult<List<EvaluationTypeDto>>(); + + var evaluationTypes = await _context.EvaluationTypes.ToListAsync(); + + result.Data = _mapper.Map<List<EvaluationTypeDto>>(evaluationTypes); + + return result; + } + + public async Task<ServiceResult<EvaluationTypeDto>> GetById(int id) + { + var result = new ServiceResult<EvaluationTypeDto>(); + + var evaluationType = await _context.EvaluationTypes.FirstOrDefaultAsync(x => x.Id == id); + + if (evaluationType == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.EvaluationTypeDoesNotExist, id)); + return result; + } + + result.Data = _mapper.Map<EvaluationTypeDto>(evaluationType); + + return result; + } + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs index 74c8fb4ff7b641e327843a8acfdcb1cd6e3bd99b..bd235875dd97fc443d8513d6b5639bcca27fd15c 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs @@ -19,13 +19,11 @@ namespace Tsi1.BusinessLayer.Services public class FileService : IFileService { private readonly Tsi1Context _context; - private readonly IMapper _mapper; private readonly string _path; - public FileService(Tsi1Context context, IMapper mapper, IHostingEnvironment hostingEnvironment) + public FileService(Tsi1Context context, IHostingEnvironment hostingEnvironment) { _context = context; - _mapper = mapper; _path = Path.Combine(hostingEnvironment.ContentRootPath, "StaticFiles"); }