public async Task <bool> AssignReviewer(Guid internshipId, ICollection <Guid> teacherIds) { var internship = await Get(internshipId); if (internship == null || teacherIds.Count == 0) { return(false); } foreach (var reviewerInternship in internship.Reviewers) { _context.Remove(reviewerInternship); } await Save(); internship.Reviewers = new List <ReviewerInternships>(); foreach (var teacher in teacherIds) { var reviewerInternship = new ReviewerInternships { ReviewedInternshipId = internshipId, ReviewerId = teacher }; internship.Reviewers.Add(reviewerInternship); } internship.InternshipState = InternshipState.InReviewByTeacher; internship.DateOfState = DateTime.UtcNow; _context.Update(internship); await Save(); return(true); }
public void Setup() { _context = ContextHelper.GetDatabaseContext(); sut = new InternshipService(_context); dto = new InternshipCreationDto { RequiredFieldsOfStudy = new List <string>(), AssignedStudents = new List <string>(), Environment = new List <string>(), TechnicalDescription = "TechnicalDescription", ExtraRequirements = "ExtraRequirements", ResearchTheme = "ResearchTheme", Activities = new List <string>(), RequiredStudentsAmount = 2, AdditionalRemarks = "AdditionalRemarks", PeriodOfInternship = new List <string>(), Description = "Description" }; for (int i = 0; i < 10; i++) { dto.RequiredFieldsOfStudy.Add("ReqFOS" + i); dto.AssignedStudents.Add("AssignedStudent" + i); dto.Environment.Add("Environment" + i); dto.Activities.Add("Activity" + i); dto.PeriodOfInternship.Add("Period" + i); } internship = new Internship { CreatorId = Guid.NewGuid(), RequiredFieldsOfStudy = dto.RequiredFieldsOfStudy, AssignedStudents = dto.AssignedStudents, Environment = dto.Environment, TechnicalDescription = "TechnicalDescription", ExtraRequirements = "ExtraRequirements", ResearchTheme = "ResearchTheme", Activities = dto.Activities, RequiredStudentsAmount = 2, AdditionalRemarks = "AdditionalRemarks", Id = Guid.NewGuid(), InternshipState = 0, Periods = dto.PeriodOfInternship, Description = "Description", DateOfState = DateTime.UtcNow }; userTeacher = new User { Id = Guid.NewGuid(), City = "City", Email = "*****@*****.**", FirstName = "John", HouseNumber = 18, LastName = "Doe", PasswordHash = Guid.NewGuid().ToString(), PhoneNumber = "+3259874896", ZipCode = 7890, UserName = "******", StreetName = "Easy Street" }; userTeacher2 = new User { Id = Guid.NewGuid(), City = "City", Email = "*****@*****.**", FirstName = "John", HouseNumber = 18, LastName = "Doe", PasswordHash = Guid.NewGuid().ToString(), PhoneNumber = "+3259874896", ZipCode = 7890, UserName = "******", StreetName = "Easy Street" }; company = new Company { Id = internship.CreatorId }; ReviewerInternships reviewerInternships = new ReviewerInternships { ReviewedInternship = internship, Reviewer = userTeacher }; reviewerList = new List <ReviewerInternships> { reviewerInternships }; internship.Reviewers = reviewerList; IFCDto = new InternshipFeedbackCoordinatorDto { Feedback = "coordinator", InternshipId = internship.Id, ReviewedState = InternshipState.ApprovedByAll }; IFTDto = new InternshipFeedbackTeacherDto { Feedback = "teacher", InternshipId = internship.Id, TeacherId = userTeacher.Id }; updateDto = new InternshipUpdate { ID = internship.Id, ResearchTheme = "ResearchTheme", Description = "DescriptionUpdate", Activities = new List <string>() { "test" }, AdditionalRemarks = "test", AssignedStudents = new List <string>() { "Jan" }, Environment = new List <string>() { "test" }, ExtraRequirements = "test", PeriodOfInternship = new List <string>() { "test" }, RequiredFieldsOfStudy = new List <string>() { "AON" }, RequiredStudentsAmount = 1, TechnicalDescription = "test", Title = "test" }; _context.Add(reviewerInternships); _context.Add(userTeacher); _context.Add(internship); _context.SaveChanges(); }
public void Setup() { _context = ContextHelper.GetDatabaseContext(); moqInternshipService = new Mock <IInternshipService>(); moqUserService = new Mock <IUserService>(); userTeacher = new User { Id = Guid.NewGuid(), City = "City", Email = "*****@*****.**", FirstName = "John", HouseNumber = 18, LastName = "Doe", PasswordHash = Guid.NewGuid().ToString(), PhoneNumber = "+3259874896", ZipCode = 7890, UserName = "******", StreetName = "Easy Street" }; internship = new Internship { RequiredFieldsOfStudy = new List <string>(), AssignedStudents = new List <string>(), Environment = new List <string>(), TechnicalDescription = "TechnicalDescription", ExtraRequirements = "ExtraRequirements", ResearchTheme = "ResearchTheme", Activities = new List <string>(), RequiredStudentsAmount = 2, AdditionalRemarks = "AdditionalRemarks", Id = Guid.NewGuid(), InternshipState = 0, Periods = new List <string>(), Description = "Description", DateOfState = DateTime.UtcNow, }; roleTeacher = new Role { Id = Guid.NewGuid(), Name = "Teacher", NormalizedName = "TEACHER" }; ReviewerInternships reviewerInternships = new ReviewerInternships { ReviewedInternship = internship, Reviewer = userTeacher }; reviewerList = new List <ReviewerInternships> { reviewerInternships }; internship.Reviewers = reviewerList; var store = new Mock <IUserStore <User> >(); moqUserManager = new Mock <UserManager <User> >(store.Object, null, null, null, null, null, null, null, null); moqUserManager.Object.UserValidators.Add(new UserValidator <User>()); moqUserManager.Object.PasswordValidators.Add(new PasswordValidator <User>()); sut = new InternshipController(moqInternshipService.Object, moqUserService.Object, moqUserManager.Object); assignDto = new InternshipAssign { InternshipID = Guid.NewGuid(), Teachers = new List <Guid> { Guid.NewGuid() } }; _context.Add(userTeacher); _context.Roles.Add(roleTeacher); _context.UserRoles.Add(new IdentityUserRole <Guid> { RoleId = roleTeacher.Id, UserId = userTeacher.Id }); _context.SaveChanges(); }