示例#1
0
        public static void AddStudent(NewStudentDto studentDto)
        {
            _lastIndex++;
            Student student = new Student(_lastIndex, studentDto.Name, studentDto.Faculty, studentDto.Year);

            Students[student.Id] = student;
        }
示例#2
0
        public async Task <Student> Create(NewStudentDto inboundData)
        {
            // Add the student
            Student student = new Student()
            {
                FirstName   = inboundData.Name.Split(" ").First <string>(),
                LastName    = inboundData.Name.Split(" ").Last <string>(),
                DateOfBirth = inboundData.Dob
            };

            _context.Entry(student).State = Microsoft.EntityFrameworkCore.EntityState.Added;
            await _context.SaveChangesAsync();


            Course course = await _context.Courses.FirstOrDefaultAsync(c => c.CourseCode == inboundData.CourseCode);

            // Add student to course
            Enrollment enrollment = new Enrollment()
            {
                CourseId  = course.Id,
                StudentId = student.Id
            };

            _context.Entry(enrollment).State = EntityState.Added;
            await _context.SaveChangesAsync();


            return(student);
        }
示例#3
0
        public IActionResult Register([FromBody] NewStudentDto dto)
        {
            var command = new RegisterCommand(dto.Name, dto.Email, dto.Course1, dto.Course1Grade, dto.Course2, dto.Course2Grade);
            var result  = _messages.Dispatch(command);

            return(FromResult(result));
        }
示例#4
0
        public RegisterStudentViewModel()
        {
            Student = new NewStudentDto();

            OkCommand     = new Command(Save);
            CancelCommand = new Command(() => DialogResult = false);
        }
        public IActionResult Register([FromBody] NewStudentDto dto)
        {
            var    command = new RegisterCommand(dto);
            Result result  = _mesages.Dispatch(command);

            return(FromResult(result));
        }
示例#6
0
        public async Task <ActionResult <Student> > PostStudent(NewStudentDto student)
        {
            Student newStudent = await _student.Create(student);

            // Returns a 201 Header
            // The body will be the result of calling GetStudent with the id
            return(CreatedAtAction("GetStudent", new { id = newStudent.Id }, newStudent));
        }
示例#7
0
        public async Task <IActionResult> Register([FromBody] NewStudentDto dto)
        {
            var result = await _dispatcher.Dispatch(new RegisterCommand(
                                                        dto.Name, dto.Email,
                                                        dto.Course1, dto.Course1Grade,
                                                        dto.Course2, dto.Course2Grade));

            return(FromResult(result));
        }
示例#8
0
 public RegisterCommand(NewStudentDto dto)
 {
     Name         = dto.Name;
     Email        = dto.Email;
     Course1      = dto.Course1;
     Course1Grade = dto.Course1Grade;
     Course2      = dto.Course2;
     Course2Grade = dto.Course2Grade;
 }
示例#9
0
        public async Task <IActionResult> Register([FromBody] NewStudentDto dto)
        {
            var command = new RegisterCommand(
                dto.Name, dto.Email,
                dto.Course1, dto.Course1Grade,
                dto.Course2, dto.Course2Grade);

            Result result = await _mediator.Send(command);

            return(FromResult(result));
        }
示例#10
0
        public IActionResult Register([FromBody] NewStudentDto dto)
        {
            var handler = new RegisterCommandHandler(_studentService, _courseService);

            return(Ok(handler.Handle(new RegisterCommand(
                                         dto.Name,
                                         dto.Email,
                                         dto.Course1,
                                         dto.Course1Grade,
                                         dto.Course2,
                                         dto.Course2Grade))));
        }
示例#11
0
        public async Task <ActionResult <Student> > UpdateStudent(NewStudentDto studentDto)
        {
            var student = new Student
            {
                Name      = studentDto.Name,
                Roll      = studentDto.Roll,
                Phone     = studentDto.Phone,
                Email     = studentDto.Email,
                ClassesId = studentDto.ClassesId,
                SchoolId  = studentDto.SchoolId
            };
            var students = await _uom.studentRepository.UpdateAsync(student);

            return(Ok(students));
        }
示例#12
0
        public async Task <ActionResult <Student> > CreateStudent(NewStudentDto student)
        {
            var students = new Student
            {
                Name      = student.Name,
                Roll      = student.Roll,
                Phone     = student.Phone,
                Email     = student.Email,
                ClassesId = student.ClassesId,
                SchoolId  = student.SchoolId
            };

            var createdData = await _uom.studentRepository.CreateAsync(students);

            return(Ok(createdData));
        }
示例#13
0
        public async Task <IActionResult> Register([FromForm] NewStudentDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var result = await _messages.Dispatch(
                new RegisterCommand(dto.Name, dto.Email, dto.Course1, dto.Course1Grade.ToString(), dto.Course2, dto.Course2Grade?.ToString()));

            if (result.IsFailure)
            {
                return(Error(result.Error));
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#14
0
        public IActionResult Register([FromBody] NewStudentDto dto)
        {
            var student = new Student(dto.Name, dto.Email);

            if (dto.Course1 != null && dto.Course1Grade != null)
            {
                Course course = _courseRepository.GetByName(dto.Course1);
                student.Enroll(course, Enum.Parse <Grade>(dto.Course1Grade));
            }

            if (dto.Course2 != null && dto.Course2Grade != null)
            {
                Course course = _courseRepository.GetByName(dto.Course2);
                student.Enroll(course, Enum.Parse <Grade>(dto.Course2Grade));
            }

            _studentRepository.Save(student);
            _unitOfWork.Commit();

            return(Ok());
        }
示例#15
0
        public async Task <Student> Create(NewStudentDto inboundData)
        {
            // Add the student
            Student student = new Student()
            {
                FirstName   = inboundData.Name.Split(" ").First <string>(),
                LastName    = inboundData.Name.Split(" ").Last <string>(),
                DateOfBirth = inboundData.Dob
            };

            _context.Entry(student).State = Microsoft.EntityFrameworkCore.EntityState.Added;
            await _context.SaveChangesAsync();

            // Use the Courses Service to get a course from the course service
            Course course = await _courses.GetOneByCourseCode(inboundData.CourseCode);

            // Use the Courses Service to add an enrollment for the student and course
            await _courses.AddStudent(course.Id, student.Id);

            return(student);
        }
示例#16
0
 public void AddStudent([FromBody] NewStudentDto studentDto)
 {
     StudentRepository.AddStudent(studentDto);
 }