コード例 #1
0
        public async Task <ActionResult> ExcludeStudentAsync(StudentGroupRequest request)
        {
            if (await _groupingService.ExcludeStudentAsync(request.StudentId, request.GroupId))
            {
                return(Ok());
            }

            return(NotFound());
        }
コード例 #2
0
        public async Task <ActionResult> IncludeStudentAsync(StudentGroupRequest request)
        {
            var includeResult = await _groupingService.IncludeStudentAsync(request.StudentId, request.GroupId);

            if (includeResult)
            {
                return(Ok());
            }
            else
            {
                return(Ok("Already included"));
            }
        }
コード例 #3
0
        public async Task <bool> IncludeStudentAsync(StudentGroupRequest request)
        {
            var result = await HttpClient.PostAsJsonAsync("api/StudentGroup/IncludeStudent", request);

            return(result.StatusCode switch
            {
                HttpStatusCode.OK => true,

                HttpStatusCode.NotFound => false,

                _ => throw new IndexOutOfRangeException(
                    $"{nameof(result.StatusCode)} in {GetType().Name}.{nameof(IncludeStudentAsync)}")
            });
コード例 #4
0
        public async Task <dynamic> Add(StudentGroupRequest studentGroupRequest)
        {
            if (studentGroupRequest == null)
            {
                AddError("20000");
                return(null);
            }

            var course = await _courseRepository.FindById(studentGroupRequest.CourseId);

            var studentGroup = StudentGroup.Create(studentGroupRequest.Name, course);

            _studentGroupRepository.Add(studentGroup);

            var studentResponse = _mapper.Map <StudentGroup, StudentGroupResponse>(studentGroup);

            return(await Task.FromResult(studentResponse));
        }
コード例 #5
0
        public async Task <ActionResult> Post([FromBody] StudentGroupRequest studentRequest)
        {
            try
            {
                var response = await _studentGroupService.Add(studentRequest);

                var notifications = _studentGroupService as Notifiable;

                if (response == null && notifications.Error.Any())
                {
                    return(BadRequest(notifications.Error));
                }

                return(Created(string.Empty, response));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.ToString()));
            }
        }