Ejemplo n.º 1
0
        public async Task UpdateStudentAsync(Guid studentId, Guid classId, UpsertStudentDto studentDto)
        {
            var result = await _executor.ExecuteAsync(new UpdateStudentCommand(classId, studentId, studentDto));

            if (!await _context.CommitAsync())
            {
                throw new Exception("Updating an student failed on save.");
            }
            if (result.Success)
            {
                await _hubContext.Clients.All.InvokeAsync("refresh");
            }
        }
Ejemplo n.º 2
0
        public async Task <Guid> AddStudentAsync(Guid classId, UpsertStudentDto studentDto)
        {
            var student = await _executor.ExecuteAsync(new AddStudentCommand(classId, studentDto));

            if (!await _context.CommitAsync())
            {
                throw new Exception("Creating an student failed on save.");
            }
            if (student.StudentId != null)
            {
                await _hubContext.Clients.All.InvokeAsync("refresh");
            }
            return(student.StudentId);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateStudent(Guid classId, [FromBody] UpsertStudentDto studentDto)
        {
            if (studentDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(StatusCode(StatusCodes.Status422UnprocessableEntity));
            }

            var id = await _studentsService.AddStudentAsync(classId, studentDto);

            return(Ok(id));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateStudent(Guid classId, Guid studentId, [FromBody] UpsertStudentDto studentDto)
        {
            if (studentDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(StatusCode(StatusCodes.Status422UnprocessableEntity));
            }

            await _studentsService.UpdateStudentAsync(studentId, classId, studentDto);

            return(NoContent());
        }
Ejemplo n.º 5
0
 public AddStudentCommand(Guid classId, UpsertStudentDto dto)
 {
     _classId = classId;
     _dto     = dto;
 }
Ejemplo n.º 6
0
 public UpdateStudentCommand(Guid classId, Guid studentId, UpsertStudentDto dto)
 {
     _classId   = classId;
     _studentId = studentId;
     _dto       = dto;
 }