예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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));
        }
예제 #5
0
        public async Task <ActionResult <IEnumerable <StudentEntity> > > Get()
        {
            using (var service = new StudentsService())
            {
                await service.Initialize();

                return(await service.GetStudents());
            }
        }
예제 #6
0
        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));
        }
예제 #7
0
        // 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));
        }
예제 #8
0
        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());
        }
예제 #9
0
 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"
     };
 }
예제 #10
0
        // 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));
        }
예제 #14
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
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());
        }
예제 #18
0
        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);
        }
예제 #19
0
        // 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);
        }
예제 #22
0
        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;
 }
예제 #25
0
 public StudentsController(SmsDbContext db, IMapper mapper, StudentsService studentsService)
 {
     this.db              = db;
     this.mapper          = mapper;
     this.studentsService = studentsService;
 }
예제 #26
0
 public StudentsController(StudentsService studentsService)
 {
     _studentsService = studentsService;
 }
 public StudentsApiController(StudentsService service)
 {
     this._service = service;
 }
예제 #28
0
 public StudentsController(StudentsService servStudents)
 {
     _servStudents = servStudents;
 }
예제 #29
0
 public StudentsController()
 {
     service = new StudentsService();
 }
예제 #30
0
 public StudentsController(StudentsService ss, ClassroomsService cs)
 {
     _ss = ss;
     _cs = cs;
 }