public IHttpActionResult UpdateStudent(int id, Student student) { studentsService = new StudentsService(); // check if student exists in db.students bool studentExistsInDb = studentsService.CheckIfStudentExistsById(id); if (!studentExistsInDb) { return(NotFound()); } // if exists update his name in db.students and db.unistudents Student updatedStudent = studentsService.UpdateStudent(id, student); if (updatedStudent == null) { return(BadRequest()); } studentToExposeService = new StudentToExposeService(); StudentToExpose studentToExpose = studentToExposeService.TrimStudent(student); return(Ok(studentToExpose)); }
public async Task <IActionResult> UpdateStudent([FromServices] StudentsService studentsService, ResultModel <StudentDisciplineVO> request) { string token = User.FindFirst("Token").Value; request.Object.Student.CourseId = Guid.Parse(User.FindFirst("CourseId").Value); ResultModel <StudentDisciplineVO> response = await studentsService.UpdateStudentTaskAsync(request.Object.Student, token); if (response.StatusCode != HttpStatusCode.Created) { return(View("/Views/Coordinator/Students/Update.cshtml", new ResultModel <StudentDisciplineVO> { Object = request.Object, Message = response.Message, StatusCode = response.StatusCode })); } ResultModel <List <StudentDisciplineVO> > studentResponse = await studentsService.GetStudentsTaskAsync(token); if (studentResponse.StatusCode == HttpStatusCode.OK) { studentResponse.Message = response.Message; studentResponse.StatusCode = response.StatusCode; } return(View("/Views/Coordinator/Students/Index.cshtml", studentResponse)); }
public async Task Post([FromBody] StudentModel student) { if (string.IsNullOrEmpty(student.University) || string.IsNullOrEmpty(student.CNP)) { throw new Exception("The student does not have university or CNP set!"); } var studentEntity = new StudentEntity(student.University, student.CNP) { Email = student.Email, Faculty = student.Faculty, FirstName = student.FirstName, LastName = student.LastName, PhoneNumber = student.PhoneNumber, Year = student.Year }; // queueClient = new QueueClient(ServiceBusConnectionString, QueueName); // string json = JsonConvert.SerializeObject(student); // var message = new Message(Encoding.UTF8.GetBytes(json)); // Console.WriteLine($"Sending message: {json}"); // // Send the message to the queue. // await queueClient.SendAsync(message); using (var service = new StudentsService()) { await service.Initialize(); await service.AddStudent(studentEntity); } }
public async Task <IActionResult> Index([FromServices] StudentsService studentsService) { string token = User.FindFirst("Token").Value; ResultModel <List <StudentDisciplineVO> > students = await studentsService.GetStudentsTaskAsync(token); return(View("/Views/Coordinator/Students/Index.cshtml", students)); }
public async Task <ActionResult <IEnumerable <StudentEntity> > > Get() { using (var service = new StudentsService()) { await service.Initialize(); return(await service.GetStudents()); } }
public async Task <string> Polls([FromBody] dynamic value) { PollService _pollService = new PollService(); FiltersService _filtersService = new FiltersService(); StudentsService _studentsService = StudentsService.Instance; var resultFilter = _filtersService.GetFilter(value.ToString()); var normalizedStudentsResult = _studentsService.GetNormalizeData(); var studens = _pollService.GetPoll(resultFilter, normalizedStudentsResult); return(JsonConvert.SerializeObject(studens)); }
// DELETE /api/students/ public IHttpActionResult DeleteStudent(int id) { studentsService = new StudentsService(); studentsService.DeleteStudent(id); // delete all student subjects List <StudentToExpose> allStudents = studentsService.GetAllEnrolledStudents(); return(Ok(allStudents)); }
public async Task <IActionResult> Update([FromServices] StudentsService studentsService, [Required] Guid studentId) { if (ModelState.IsValid) { string token = User.FindFirst("Token").Value; ResultModel <StudentDisciplineVO> response = await studentsService.GetStudentTaskAsync(token, studentId); return(View("/Views/Coordinator/Students/Update.cshtml", response)); } return(BadRequest()); }
public StudentsServiceTests() { _mockILoggerStudentsService = new Mock <ILogger <StudentsService> >(); _mockIEducationRepository = new Mock <IEducationRepository>(); _mockIStudentRepository = new Mock <IStudentRepository>(); _mockIEducationRepository.Setup(er => er.GetStudentRepository()).Returns(_mockIStudentRepository.Object); _mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <StudentBL, Student>())); _studentsService = new StudentsService(_mockIEducationRepository.Object, _mockILoggerStudentsService.Object, _mapper); _studentBL = new StudentBL() { EMail = "[email protected]", FullName = "Ivan", Phone = "12345678" }; }
// GET /api/students/ public IHttpActionResult GetEnrolledStudents() { studentsService = new StudentsService(); List <StudentToExpose> allStudents = studentsService.GetAllEnrolledStudents(); if (allStudents.Count() == 0) { return(NotFound()); } return(Ok(allStudents)); }
public void AddMail_Exception() { StudentsService service = new StudentsService(); StudentModel expected = new StudentModel() { Id = 4, St_Last_Name = "ddad", St_First_Name = "sasd", Phone = "8 999 222-11-11", Email = "23233.ru", GroupNumberId = 2 }; Assert.Throws <InvalidMailExeption>(() => service.AddStudent(expected)); }
public void AddName_Exception() { StudentsService service = new StudentsService(); StudentModel expected = new StudentModel() { Id = 4, St_Last_Name = "131231", St_First_Name = "s41s", Phone = "8 999 222-11-11", Email = "*****@*****.**", GroupNumberId = 2 }; Assert.Throws <InvalidNameException>(() => service.AddStudent(expected)); }
public void AddPhone_Exception() { StudentsService service = new StudentsService(); StudentModel expected = new StudentModel() { Id = 4, St_Last_Name = "ddds", St_First_Name = "ssad", Phone = "42s4d323", Email = "*****@*****.**", GroupNumberId = 2 }; Assert.Throws <InvalidPhoneException>(() => service.AddStudent(expected)); }
public StudentsServiceTests() { var localMemoryCache = new Mock <ICache>(); localMemoryCache.Setup(x => x.Get <Dictionary <int, Student> >(StudentsKey)).Returns(() => new Dictionary <int, Student> { { 1, new Student("Leia", 1, 'F', "Kinder", new DateTime(2013, 12, 31, 14, 59, 34)) }, { 2, new Student("Luke", 2, 'M', "University", new DateTime(2013, 11, 25, 12, 59, 34)) }, { 3, new Student("Maria", 3, 'F', "High", new DateTime(2014, 10, 20, 11, 59, 34)) }, { 4, new Student("Charles", 4, 'M', "Elementary", new DateTime(2015, 01, 15, 10, 59, 34)) }, { 5, new Student("Marcela", 5, 'F', "High", new DateTime(2016, 03, 05, 19, 59, 34)) }, { 6, new Student("Peter", 6, 'M', "University", new DateTime(2015, 10, 20, 12, 59, 34)) } }); _subject = new StudentsService(localMemoryCache.Object); }
public async Task ShouldPersistStudentWhenStudentIsPassedIn() { // given var storageBrokerMock = new Mock <IStorageBroker>(); Student student = new Filler <Student>().Create(); storageBrokerMock.Setup(broker => broker.AddStudentAsync(student)); // when var studentsService = new StudentsService(storageBrokerMock.Object, this.loggingBrokerMock.Object); await studentsService.RegisterStudentAsync(student); // then storageBrokerMock.Verify(broker => broker.AddStudentAsync(student), Times.Once); }
public async Task GetStudentIdsWithMatchingEmailShouldReturnStudents() { var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("test"); var context = new ApplicationDbContext(dbOptions.Options); var roleService = new WebSchool.Services.RolesService(context); var studentsService = new StudentsService(context, roleService); var school = new School(); await context.Schools.AddAsync(school); await context.SaveChangesAsync(); var students = studentsService.GetStudentIdsWithMatchingEmail("email", "12 D", school.Id); Assert.That(students.Count == 0); }
public async Task <IActionResult> Delete([FromServices] StudentsService studentsService, [Required] Guid studentId) { if (ModelState.IsValid) { string token = User.FindFirst("Token").Value; ResultModel <bool> response = await studentsService.RemoveStudentTaskAsync(studentId, token); ResultModel <List <StudentDisciplineVO> > studentResponse = await studentsService.GetStudentsTaskAsync(token); studentResponse.Message = response.Message; studentResponse.StatusCode = response.StatusCode; return(View("/Views/Coordinator/Students/Index.cshtml", studentResponse)); } return(NotFound()); }
public void Delete() { Mock <DbContexts.MVCWebAppDbContext> dbContext = new Mock <DbContexts.MVCWebAppDbContext>(); IStudentsService studentService = new StudentsService(dbContext.Object); var students = new List <Student>() { new Student() { StudentID = 1, RefNo = "12456343", FirstName = "John", LastName = "Smith", DateOfBirth = DateTime.Now.AddYears(-10), DateCreated = DateTime.Now }, new Student() { StudentID = 2, RefNo = "87984564", FirstName = "Pete", LastName = "Luck", DateOfBirth = DateTime.Now.AddYears(-20), DateCreated = DateTime.Now.AddDays(1) } }; var mockSet = new Mock <DbSet <Student> >(); mockSet.As <IQueryable <Student> >().Setup(m => m.Provider).Returns(students.AsQueryable().Provider); mockSet.As <IQueryable <Student> >().Setup(m => m.Expression).Returns(students.AsQueryable().Expression); mockSet.As <IQueryable <Student> >().Setup(m => m.ElementType).Returns(students.AsQueryable().ElementType); mockSet.As <IQueryable <Student> >().Setup(m => m.GetEnumerator()).Returns(students.AsQueryable().GetEnumerator()); dbContext.Setup(m => m.Students.Remove(It.IsAny <Student>())).Callback <Student>((entity) => students.Remove(entity)); dbContext.Setup(c => c.Students).Returns(mockSet.Object); int idToDelete = 1; dbContext.Setup(s => s.Students.Find(idToDelete)).Returns(students.Single(s => s.StudentID == idToDelete)); // call delete method now studentService.Delete(idToDelete); // 1 object deleted, it should return 1 Assert.Equal(1, students.Count()); // <----- Error here dbContext.Verify(s => s.Students.Find(idToDelete), Times.Once); dbContext.Verify(s => s.Students.Remove(It.IsAny <Student>()), Times.Once); dbContext.Verify(s => s.SaveChanges(), Times.Once); }
// GET /api/students/id public IHttpActionResult GetStudent(int id) { if (id == 0) { return(NotFound()); } studentsService = new StudentsService(); Student student = studentsService.GetStudent(id); if (student == null) { return(NotFound()); } studentToExposeService = new StudentToExposeService(); StudentToExpose studentToExpose = studentToExposeService.TrimStudent(student); return(Ok(studentToExpose)); }
public async void ShouldThrowStudentRegistrationExceptionWhenStorageFails() { // given Student student = new Filler <Student>().Create(); DbUpdateException dbUpdateException = CreateDbUpdateException(); this.storageBrokerMock.Setup(broker => broker.AddStudentAsync(student)) .ThrowsAsync(dbUpdateException); // when var studentsService = new StudentsService( this.storageBrokerMock.Object, this.loggingBrokerMock.Object); Task registerStudentTask = studentsService.RegisterStudentAsync(student); // then await Assert.ThrowsAsync <StudentRegistrationFailedException>( () => registerStudentTask); this.loggingBrokerMock.Verify(broker => broker.Error(dbUpdateException.Message), Times.Once); }
public async Task ShouldThrowStudentRegistrationExceptionWhenStorageFails() { // given var storageBrokerMock = new Mock <IStorageBroker>(); Student student = new Filler <Student>().Create(); var dbUpdateException = new DbUpdateException( message: "Exception", innerException: new Exception()); storageBrokerMock.Setup(broker => broker.AddStudentAsync(student)) .ThrowsAsync(dbUpdateException); // when var studentsService = new StudentsService(storageBrokerMock.Object, this.loggingBrokerMock.Object); Task registerStudentTask = studentsService.RegisterStudentAsync(student); // then Assert.ThrowsAsync <StudentRegistrationFailedException>( () => registerStudentTask); this.loggingBrokerMock.Verify(broker => broker.Error(dbUpdateException.Message), Times.Once); }
public async Task Post([FromBody] StudentModel student) { if (string.IsNullOrEmpty(student.University) || string.IsNullOrEmpty(student.CNP)) { throw new Exception("The student does not have university or CNP set!"); } var studentEntity = new StudentEntity(student.University, student.CNP) { Email = student.Email, Faculty = student.Faculty, FirstName = student.FirstName, LastName = student.LastName, PhoneNumber = student.PhoneNumber, Year = student.Year }; using (var service = new StudentsService()) { await service.Initialize(); await service.AddStudent(studentEntity); } }
public StudentsGrpcServiceImpl() { StudentsService = new StudentsService(); }
public StudentsController(StudentsService studentsService , CountryService countryService) { this._studentsService = studentsService; this._countryService = countryService; }
public StudentsController(SmsDbContext db, IMapper mapper, StudentsService studentsService) { this.db = db; this.mapper = mapper; this.studentsService = studentsService; }
public StudentsController(StudentsService studentsService) { _studentsService = studentsService; }
public StudentsApiController(StudentsService service) { this._service = service; }
public StudentsController(StudentsService servStudents) { _servStudents = servStudents; }
public StudentsController() { service = new StudentsService(); }
public StudentsController(StudentsService ss, ClassroomsService cs) { _ss = ss; _cs = cs; }