Ejemplo n.º 1
0
        public async Task <ActionResult <FullStudentResource> > AddStudentToGroup(
            int studentId, int groupId)
        {
            if (studentId <= 0 || groupId <= 0)
            {
                return(BadRequest());
            }

            var studentDto = await _studentService.GetStudentByIdAsync(studentId);

            if (studentDto == null)
            {
                return(NotFound());
            }

            var groupDto = await _groupService.GetGroupByIdAsync(groupId);

            if (groupDto == null)
            {
                return(NotFound());
            }

            await _studentService.AddStudentToGroupAsync(studentId, groupDto);

            var fullStudentDto = await _studentService.GetFullStudentInfoAsync(studentId);

            var resource = _mapper.Map <FullStudentResource>(fullStudentDto);

            return(Ok(resource));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <GroupResource> > GetGroupById(int id)
        {
            if (id <= 0)
            {
                return(BadRequest());
            }

            var groupDto = await _groupService.GetGroupByIdAsync(id);

            if (groupDto == null)
            {
                return(NotFound());
            }

            var groupResource = _mapper.Map <GroupResource>(groupDto);

            return(Ok(groupResource));
        }