public async Task CreateAsync(CreateReflectionBindingModel reflectionBindingModel, string teacherName) { EdumanUser Student = this.context.Users.FirstOrDefault(u => u.FirstName == reflectionBindingModel.StudentFirstName && u.LastName == reflectionBindingModel.StudentLastName && u.IsConfirmed); EdumanUser Teacher = this.context.Users.FirstOrDefault(u => u.UserName == teacherName); if (Student == null || !(await userManager.IsInRoleAsync(Student, "Student"))) { throw new Exception("The User is either non-existent or is not a student"); } Reflection reflectionModel = new Reflection { DateCreated = DateTime.Now, Description = reflectionBindingModel.Description, StudentId = Student.Id, TeacherId = Teacher.Id, IsCompliment = reflectionBindingModel.IsCompliment }; this.context.Reflections.Add(reflectionModel); this.context.SaveChanges(); }
public async Task CreateAsync(CreateEventBindingModel eventBindingModel, string teacherName) { EdumanUser Student = this.context.Users.FirstOrDefault(u => u.FirstName == eventBindingModel.StudentFirstName && u.LastName == eventBindingModel.StudentLastName && u.IsConfirmed); EdumanUser Teacher = this.context.Users.FirstOrDefault(u => u.UserName == teacherName); if (Student == null || !(await userManager.IsInRoleAsync(Student, "Student"))) { throw new Exception("The User is either non-existent or is not a student"); } Event eventModel = new Event { Description = eventBindingModel.Description, EventDate = eventBindingModel.EventDate, StudentId = Student.Id, TeacherId = Teacher.Id, Type = eventBindingModel.Type }; this.context.Events.Add(eventModel); this.context.SaveChanges(); }
public async Task Create_WithNonExistentUser_ShouldNotIncludeIntoDatabase() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateAbsenceBindingModel model = new CreateAbsenceBindingModel() { StudentFirstName = "Student", DateAbsent = DateTime.Now, StudentLastName = "TestName", Subject = "Maths" }; // Assert var ex = Assert.ThrowsAsync <Exception>(() => absenceService.CreateAsync(model, "teacherName")); Assert.AreEqual(ex.Message, "The User is either non-existent or is not a student"); }
public async Task CreateAsync(CreateFeeBindingModel feeBindingModel, string teacherName) { EdumanUser Student = this.context.Users.FirstOrDefault(u => u.FirstName == feeBindingModel.StudentFirstName && u.LastName == feeBindingModel.StudentLastName && u.IsConfirmed); EdumanUser Teacher = this.context.Users.FirstOrDefault(u => u.UserName == teacherName); if (Student == null || !(await userManager.IsInRoleAsync(Student, "Student"))) { throw new Exception("The User is either non-existent or is not a student"); } Fee feeModel = new Fee { Description = feeBindingModel.Description, DueDate = feeBindingModel.DueDate, StudentId = Student.Id, TeacherId = Teacher.Id, Cost = feeBindingModel.Cost }; this.context.Fees.Add(feeModel); this.context.SaveChanges(); }
public async Task CreateAsync(CreateGradeBindingModel gradeBindingModel, string teacherName) { EdumanUser Student = this.context.Users.FirstOrDefault(u => u.FirstName == gradeBindingModel.StudentFirstName && u.LastName == gradeBindingModel.StudentLastName && u.IsConfirmed); EdumanUser Teacher = this.context.Users.FirstOrDefault(u => u.UserName == teacherName); if (Student == null || !(await userManager.IsInRoleAsync(Student, "Student"))) { throw new Exception("The User is either non-existent or is not a student"); } if (gradeBindingModel.Subject.Contains(" ")) { gradeBindingModel.Subject = gradeBindingModel.Subject.Split()[0] + gradeBindingModel.Subject.Split()[1]; } Grade gradeModel = new Grade { DateCreated = DateTime.Now, Description = gradeBindingModel.Description, StudentId = Student.Id, Subject = gradeBindingModel.Subject, TeacherId = Teacher.Id, Value = gradeBindingModel.Value }; this.context.Grades.Add(gradeModel); this.context.SaveChanges(); }
public async Task <IActionResult> Register(RegisterBindingModel registerBindingModel) { var user = new EdumanUser { FirstName = registerBindingModel.FirstName, LastName = registerBindingModel.LastName, Email = registerBindingModel.Email, UserName = registerBindingModel.Username, School = registerBindingModel.School, Number = registerBindingModel.Number, IsConfirmed = false }; var result = this.signInManager.UserManager.CreateAsync(user, registerBindingModel.Password).Result; if (result.Succeeded) { await signInManager.UserManager.AddToRoleAsync(user, registerBindingModel.Role); await signInManager.SignInAsync(user, isPersistent : false); await signInManager.SignOutAsync(); return(this.View("~/Views/Account/RegisterRequestNotification.cshtml")); } return(this.View()); }
public async Task Details_DifferentUser_ShouldReturnNoData() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId", School = "TestSchool" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId", FirstName = "TeacherFirstName", LastName = "TeacherLastName" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Student").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateEventBindingModel model = new CreateEventBindingModel() { StudentFirstName = "Student", StudentLastName = "TestName", Description = "TestEventDescription", EventDate = DateTime.Now, Type = "TestType" }; await eventService.CreateAsync(model, "teacherName"); var id = (eventService.GetAllAsync("TestStudentId").GetAwaiter().GetResult().FirstOrDefault()).Id; var eventDetails = await eventService.GetEventDetails(id); // Assert Assert.AreEqual("Student", eventDetails.StudentFirstName); Assert.AreEqual("TestName", eventDetails.StudentLastName); Assert.AreEqual("TestEventDescription", eventDetails.Description); Assert.AreEqual("TestSchool", eventDetails.School); Assert.AreEqual("TeacherFirstName", eventDetails.TeacherFirstName); Assert.AreEqual("TeacherLastName", eventDetails.TeacherLastName); Assert.AreEqual("TestType", eventDetails.Type); }
public async Task All_DifferentUser_ShouldReturnNoData() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId" }; EdumanUser anotherStudent = new EdumanUser { UserName = "******", FirstName = "Student1", LastName = "TestName1", IsConfirmed = true, Id = "TestStudentId1" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(anotherStudent).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Student").GetAwaiter(); userManager.AddToRoleAsync(anotherStudent, "Student").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateEventBindingModel model = new CreateEventBindingModel() { StudentFirstName = "Student1", StudentLastName = "TestName1", Description = "TestEventDescription", EventDate = DateTime.Now, Type = "TestType" }; await eventService.CreateAsync(model, "teacherName"); var count = (eventService.GetAllAsync("TestStudentId").GetAwaiter().GetResult()).Count; // Assert Assert.AreEqual(0, count); }
public async Task All_WithValidData_ShouldReturnCorrectData() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Student").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateFeeBindingModel model = new CreateFeeBindingModel() { StudentFirstName = "Student", StudentLastName = "TestName", Description = "TestFeeDescription", Cost = 27, DueDate = DateTime.Now }; await feeService.CreateAsync(model, "teacherName"); var count = (feeService.GetAllAsync("TestStudentId").GetAwaiter().GetResult()).Count; var feeResult = feeService.GetAllAsync("TestStudentId").GetAwaiter().GetResult().FirstOrDefault(); // Assert Assert.AreEqual(1, count); Assert.AreEqual("studentName", feeResult.StudentUsername); Assert.AreEqual("teacherName", feeResult.TeacherUsername); Assert.AreEqual(27, feeResult.Cost); }
public async Task All_WithValidData_ShouldReturnCorrectData() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Student").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateGradeBindingModel model = new CreateGradeBindingModel() { StudentFirstName = "Student", StudentLastName = "TestName", Description = "TestGradeDescription", Subject = "Maths", Value = 6 }; await gradeService.CreateAsync(model, "teacherName"); var count = (gradeService.GetAllAsync("TestStudentId").GetAwaiter().GetResult()).Count; var gradeResult = gradeService.GetAllAsync("TestStudentId").GetAwaiter().GetResult().FirstOrDefault(); // Assert Assert.AreEqual(1, count); Assert.AreEqual("Maths", gradeResult.Subject); Assert.AreEqual(6, gradeResult.Value); }
public void ConfirmUser(string id) { EdumanUser user = this.context.Users.FirstOrDefault(u => u.Id == id && !u.IsConfirmed); if (user == null) { throw new Exception("The User is non-existent"); } user.IsConfirmed = true; this.context.Users.Update(user); this.context.SaveChanges(); }
public async Task GetAllUnconfirmed_WithValidData_ShouldReturnCorrectData() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser user = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = false, Id = "TestStudentId", School = "TestSchool" }; EdumanUser principal = new EdumanUser { UserName = "******", FirstName = "Principal", LastName = "TestName", IsConfirmed = true, Id = "TestPrincipalId", School = "TestSchool" }; this.userManager.CreateAsync(user).GetAwaiter(); this.userManager.CreateAsync(principal).GetAwaiter(); userManager.AddToRoleAsync(user, "Student").GetAwaiter(); userManager.AddToRoleAsync(principal, "Principal").GetAwaiter(); this.Context.SaveChanges(); var users = this.accountService.GetAllUnconfirmedUsersAsync("principalName").Result; var result = users.FirstOrDefault(); // Assert Assert.AreEqual(1, users.Count); Assert.AreEqual("studentName", result.Username); Assert.AreEqual(user.Id, result.Id); Assert.AreEqual("Student", result.FirstName); Assert.AreEqual("TestName", result.LastName); Assert.AreEqual("Student", result.Role); Assert.AreEqual(false, user.IsConfirmed); }
public async Task Create_WithValidData_ShouldIncludeIntoDatabase() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Student").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateAbsenceBindingModel model = new CreateAbsenceBindingModel() { StudentFirstName = "Student", DateAbsent = DateTime.Now, StudentLastName = "TestName", Subject = "Maths" }; await absenceService.CreateAsync(model, "teacherName"); var count = (absenceService.GetAllAsync("TestStudentId").GetAwaiter().GetResult()).Count; // Assert Assert.AreEqual(1, count); }
public async Task Create_WithValidData_ShouldIncludeIntoDatabase() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Student").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateReflectionBindingModel model = new CreateReflectionBindingModel() { StudentFirstName = "Student", StudentLastName = "TestName", Description = "TestReflectionDescription", IsCompliment = true }; await reflectionService.CreateAsync(model, "teacherName"); var count = (reflectionService.GetAllComplimentsAsync("TestStudentId").GetAwaiter().GetResult()).Count + (reflectionService.GetAllCriticismsAsync("TestStudentId").GetAwaiter().GetResult()).Count; // Assert Assert.AreEqual(1, count); }
public async Task Create_WithNonStudentUser_ShouldNotIncludeIntoDatabase() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Principal").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateReflectionBindingModel model = new CreateReflectionBindingModel() { StudentFirstName = "Student", StudentLastName = "TestName", Description = "TestReflectionDescription", IsCompliment = true }; // Assert var ex = Assert.ThrowsAsync <Exception>(() => reflectionService.CreateAsync(model, "teacherName")); Assert.AreEqual(ex.Message, "The User is either non-existent or is not a student"); }
public async Task <ReflectionDetailsViewModel> GetReflectionDetails(string id) { var reflectionModel = this.context.Reflections.FirstOrDefault(e => e.Id == id); EdumanUser student = await userManager.FindByIdAsync(reflectionModel.StudentId); EdumanUser teacher = await userManager.FindByIdAsync(reflectionModel.TeacherId); return(new ReflectionDetailsViewModel { Description = reflectionModel.Description, StudentFirstName = student.FirstName, StudentLastName = student.LastName, TeacherFirstName = teacher.FirstName, TeacherLastName = teacher.LastName, DateCreated = reflectionModel.DateCreated, IsCompliment = reflectionModel.IsCompliment, }); }
public async Task <EventDetailsViewModel> GetEventDetails(string id) { var eventModel = this.context.Events.FirstOrDefault(e => e.Id == id); EdumanUser student = await userManager.FindByIdAsync(eventModel.StudentId); EdumanUser teacher = await userManager.FindByIdAsync(eventModel.TeacherId); return(new EventDetailsViewModel { Description = eventModel.Description, EventDate = eventModel.EventDate, StudentFirstName = student.FirstName, StudentLastName = student.LastName, School = student.School, TeacherFirstName = teacher.FirstName, TeacherLastName = teacher.LastName, Type = eventModel.Type }); }
public async Task <FeeDetailsViewModel> GetFeeDetails(string id) { var feeModel = this.context.Fees.FirstOrDefault(e => e.Id == id); EdumanUser student = await userManager.FindByIdAsync(feeModel.StudentId); EdumanUser teacher = await userManager.FindByIdAsync(feeModel.TeacherId); return(new FeeDetailsViewModel { Description = feeModel.Description, DueDate = feeModel.DueDate, StudentFirstName = student.FirstName, StudentLastName = student.LastName, School = student.School, TeacherFirstName = teacher.FirstName, TeacherLastName = teacher.LastName, Cost = feeModel.Cost }); }
public async Task ConfirmUser_ConfirmedUser_ShouldNotConfirmUser() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser user = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId", School = "TestSchool" }; EdumanUser principal = new EdumanUser { UserName = "******", FirstName = "Principal", LastName = "TestName", IsConfirmed = true, Id = "TestPrincipalId", School = "TestSchool" }; this.userManager.CreateAsync(user).GetAwaiter(); this.userManager.CreateAsync(principal).GetAwaiter(); userManager.AddToRoleAsync(user, "Student").GetAwaiter(); userManager.AddToRoleAsync(principal, "Principal").GetAwaiter(); this.Context.SaveChanges(); // Assert var ex = Assert.Throws <Exception>(() => accountService.ConfirmUser("TestStudentId")); Assert.AreEqual(ex.Message, "The User is non-existent"); }
public async Task <GradeDetailsViewModel> GetGradeDetails(string id) { var gradeModel = this.context.Grades.FirstOrDefault(e => e.Id == id); EdumanUser student = await userManager.FindByIdAsync(gradeModel.StudentId); EdumanUser teacher = await userManager.FindByIdAsync(gradeModel.TeacherId); return(new GradeDetailsViewModel { Description = gradeModel.Description, StudentFirstName = student.FirstName, StudentLastName = student.LastName, TeacherFirstName = teacher.FirstName, TeacherLastName = teacher.LastName, DateCreated = gradeModel.DateCreated, Subject = gradeModel.Subject, Value = gradeModel.Value }); }
public async Task <List <AllReflectionsViewModel> > GetAllCriticismsAsync(string UserId) { EdumanUser user = await this.context.Users.FirstOrDefaultAsync(u => u.Id == UserId); List <AllReflectionsViewModel> reflections = new List <AllReflectionsViewModel>(); if (await userManager.IsInRoleAsync(user, "Teacher")) { var resultList = this.context.Reflections.Where(r => r.TeacherId == UserId && !r.IsCompliment).ToList(); foreach (var currentReflection in resultList) { AllReflectionsViewModel temp = new AllReflectionsViewModel { Id = currentReflection.Id, DateCreated = currentReflection.DateCreated, Description = currentReflection.Description, StudentUsername = this.context.Users.FirstOrDefault(u => u.Id == currentReflection.StudentId).UserName, TeacherUsername = user.UserName }; reflections.Add(temp); } } else if (await userManager.IsInRoleAsync(user, "Student")) { var resultList = this.context.Reflections.Where(r => r.StudentId == UserId && !r.IsCompliment).ToList(); foreach (var currentReflection in resultList) { AllReflectionsViewModel temp = new AllReflectionsViewModel { Id = currentReflection.Id, DateCreated = currentReflection.DateCreated, Description = currentReflection.Description, StudentUsername = this.context.Users.FirstOrDefault(u => u.Id == currentReflection.StudentId).UserName, TeacherUsername = user.UserName }; reflections.Add(temp); } } return(reflections); }
public async Task ConfirmUser_WithValidData_ShouldConfirmUser() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser user = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = false, Id = "TestStudentId", School = "TestSchool" }; EdumanUser principal = new EdumanUser { UserName = "******", FirstName = "Principal", LastName = "TestName", IsConfirmed = true, Id = "TestPrincipalId", School = "TestSchool" }; this.userManager.CreateAsync(user).GetAwaiter(); this.userManager.CreateAsync(principal).GetAwaiter(); userManager.AddToRoleAsync(user, "Student").GetAwaiter(); userManager.AddToRoleAsync(principal, "Principal").GetAwaiter(); this.Context.SaveChanges(); this.accountService.ConfirmUser("TestStudentId"); // Assert Assert.True(user.IsConfirmed); }
public IActionResult Login(LoginBindingModel loginBindingModel) { EdumanUser user = signInManager.UserManager.Users.FirstOrDefault(u => u.UserName == loginBindingModel.Username); SignInResult result = null; if (user == null) { return(this.View()); } if (!user.IsConfirmed) { return(this.View()); } result = this.signInManager.PasswordSignInAsync(user, loginBindingModel.Password, isPersistent: false, lockoutOnFailure: false).Result; if (result.Succeeded && user.IsConfirmed) { return(RedirectToAction("Index", "Home")); } return(this.View()); }
public async Task <List <AllGradesViewModel> > GetAllAsync(string UserId) { EdumanUser user = await this.context.Users.FirstOrDefaultAsync(u => u.Id == UserId); List <AllGradesViewModel> grades = new List <AllGradesViewModel>(); if (await userManager.IsInRoleAsync(user, "Teacher")) { var resultList = this.context.Grades.Where(a => a.TeacherId == UserId).ToList(); foreach (var currentGrade in resultList) { AllGradesViewModel temp = new AllGradesViewModel { Value = currentGrade.Value, Id = currentGrade.Id, Subject = currentGrade.Subject }; grades.Add(temp); } } else if (await userManager.IsInRoleAsync(user, "Student")) { var resultList = this.context.Grades.Where(e => e.StudentId == UserId).ToList(); foreach (var currentGrade in resultList) { AllGradesViewModel temp = new AllGradesViewModel { Value = currentGrade.Value, Id = currentGrade.Id, Subject = currentGrade.Subject }; grades.Add(temp); } } return(grades); }
public async Task CreateAsync(CreateAbsenceBindingModel absenceModel, string teacherName) { EdumanUser Student = this.context.Users.FirstOrDefault(u => u.FirstName == absenceModel.StudentFirstName && u.LastName == absenceModel.StudentLastName && u.IsConfirmed); EdumanUser Teacher = this.context.Users.FirstOrDefault(u => u.UserName == teacherName); if (Student == null || !(await userManager.IsInRoleAsync(Student, "Student"))) { throw new Exception("The User is either non-existent or is not a student"); } Absence absence = new Absence { DateAbsent = absenceModel.DateAbsent, StudentId = Student.Id, Subject = absenceModel.Subject, TeacherId = Teacher.Id }; this.context.Absences.Add(absence); this.context.SaveChanges(); }
public async Task <List <AllEventsViewModel> > GetAllAsync(string UserId) { EdumanUser user = await this.context.Users.FirstOrDefaultAsync(u => u.Id == UserId); List <AllEventsViewModel> events = new List <AllEventsViewModel>(); if (await userManager.IsInRoleAsync(user, "Teacher")) { var resultList = this.context.Events.Where(a => a.TeacherId == UserId).ToList(); foreach (var currentEvent in resultList) { AllEventsViewModel temp = new AllEventsViewModel { StudentUsername = this.context.Users .FirstOrDefault(u => u.Id == currentEvent.StudentId).UserName, TeacherUsername = this.context.Users .FirstOrDefault(u => u.Id == currentEvent.TeacherId).UserName, EventDate = currentEvent.EventDate, Type = currentEvent.Type, Id = currentEvent.Id }; events.Add(temp); } } else if (await userManager.IsInRoleAsync(user, "Principal")) { var resultList = this.context.Events.Where( e => this.context.Users .FirstOrDefault(u => u.Id == e.StudentId).School == user.School).ToList(); foreach (var currentEvent in resultList) { AllEventsViewModel temp = new AllEventsViewModel { StudentUsername = this.context.Users .FirstOrDefault(u => u.Id == currentEvent.StudentId).UserName, TeacherUsername = this.context.Users .FirstOrDefault(u => u.Id == currentEvent.TeacherId).UserName, Id = currentEvent.Id, EventDate = currentEvent.EventDate, Type = currentEvent.Type }; events.Add(temp); } } else if (await userManager.IsInRoleAsync(user, "Student")) { var resultList = this.context.Events.Where(e => e.StudentId == UserId).ToList(); foreach (var currentEvent in resultList) { AllEventsViewModel temp = new AllEventsViewModel { StudentUsername = this.context.Users .FirstOrDefault(u => u.Id == currentEvent.StudentId).UserName, TeacherUsername = this.context.Users .FirstOrDefault(u => u.Id == currentEvent.TeacherId).UserName, Id = currentEvent.Id, EventDate = currentEvent.EventDate, Type = currentEvent.Type }; events.Add(temp); } } return(events); }
public async Task AllCriticism_WithValidData_ShouldReturnCorrectData() { await roleManager.CreateAsync(new IdentityRole("Student")); await roleManager.CreateAsync(new IdentityRole("Teacher")); await roleManager.CreateAsync(new IdentityRole("Principal")); EdumanUser student = new EdumanUser { UserName = "******", FirstName = "Student", LastName = "TestName", IsConfirmed = true, Id = "TestStudentId" }; EdumanUser teacher = new EdumanUser { UserName = "******", IsConfirmed = true, Id = "TestTeacherId" }; this.userManager.CreateAsync(student).GetAwaiter(); this.userManager.CreateAsync(teacher).GetAwaiter(); userManager.AddToRoleAsync(student, "Student").GetAwaiter(); userManager.AddToRoleAsync(teacher, "Teacher").GetAwaiter(); this.Context.SaveChanges(); CreateReflectionBindingModel compliment = new CreateReflectionBindingModel() { StudentFirstName = "Student", StudentLastName = "TestName", Description = "TestReflectionDescription", IsCompliment = true }; CreateReflectionBindingModel criticism = new CreateReflectionBindingModel() { StudentFirstName = "Student", StudentLastName = "TestName", Description = "TestReflectionDescription", IsCompliment = false }; await reflectionService.CreateAsync(compliment, "teacherName"); await reflectionService.CreateAsync(criticism, "teacherName"); var count = (reflectionService.GetAllCriticismsAsync("TestTeacherId").GetAwaiter().GetResult()).Count; var reflectionResult = reflectionService.GetAllCriticismsAsync("TestTeacherId").GetAwaiter().GetResult().FirstOrDefault(); // Assert Assert.AreEqual(1, count); Assert.AreEqual("TestReflectionDescription", reflectionResult.Description); Assert.AreEqual("studentName", reflectionResult.StudentUsername); Assert.AreEqual("teacherName", reflectionResult.TeacherUsername); }
public async Task <List <AllAbsencesViewModel> > GetAllAsync(string UserId) { EdumanUser user = await this.context.Users.FirstOrDefaultAsync(u => u.Id == UserId); List <AllAbsencesViewModel> absences = new List <AllAbsencesViewModel>(); if (await userManager.IsInRoleAsync(user, "Teacher")) { var resultList = this.context.Absences.Where(a => a.TeacherId == UserId).ToList(); foreach (var absence in resultList) { AllAbsencesViewModel temp = new AllAbsencesViewModel { DateAbsent = absence.DateAbsent, StudentName = this.context.Users .FirstOrDefault(u => u.Id == absence.StudentId).UserName, Subject = absence.Subject, TeacherName = this.context.Users .FirstOrDefault(u => u.Id == absence.TeacherId).UserName }; absences.Add(temp); } } else if (await userManager.IsInRoleAsync(user, "Principal")) { var resultList = this.context.Absences.Where( a => this.context.Users .FirstOrDefault(u => u.Id == a.StudentId).School == user.School).ToList(); foreach (var absence in resultList) { AllAbsencesViewModel temp = new AllAbsencesViewModel { DateAbsent = absence.DateAbsent, StudentName = this.context.Users .FirstOrDefault(u => u.Id == absence.StudentId).UserName, Subject = absence.Subject, TeacherName = this.context.Users .FirstOrDefault(u => u.Id == absence.TeacherId).UserName }; absences.Add(temp); } } else if (await userManager.IsInRoleAsync(user, "Student")) { var resultList = this.context.Absences.Where(a => a.StudentId == UserId).ToList(); foreach (var absence in resultList) { AllAbsencesViewModel temp = new AllAbsencesViewModel { DateAbsent = absence.DateAbsent, StudentName = this.context.Users .FirstOrDefault(u => u.Id == absence.StudentId).UserName, Subject = absence.Subject, TeacherName = this.context.Users .FirstOrDefault(u => u.Id == absence.TeacherId).UserName }; absences.Add(temp); } } return(absences); }
public async Task InvokeAsync(HttpContext httpContext, IServiceProvider serviceProvider) { var userManager = serviceProvider.GetService <UserManager <EdumanUser> >(); var teacher = await userManager.FindByEmailAsync("teacher@teacherpass"); var principal = await userManager.FindByEmailAsync("principal@principalpass"); var student = await userManager.FindByEmailAsync("student@studentpass"); if (teacher == null) { var user = new EdumanUser() { UserName = "******", FirstName = "Petar", LastName = "Petrov", Email = "teacher@teacherpass", School = "RNDSchool", Number = 0, IsConfirmed = true }; await userManager.CreateAsync(user, "teacherpass"); await userManager.AddToRoleAsync(user, "Teacher"); } if (principal == null) { var user = new EdumanUser() { UserName = "******", FirstName = "Petko", LastName = "Petkov", School = "RNDSchool", Email = "principal@principalpass", IsConfirmed = true, Number = 0 }; await userManager.CreateAsync(user, "principalpass"); await userManager.AddToRoleAsync(user, "Principal"); } if (student == null) { var user = new EdumanUser() { UserName = "******", FirstName = "Georgi", LastName = "Georgiev", School = "RNDSchool", Email = "student@studentpass", Number = 0, IsConfirmed = true }; await userManager.CreateAsync(user, "studentpass"); await userManager.AddToRoleAsync(user, "Student"); } await this.next(httpContext); }