public async Task <ActionResult> ExcludeStudentAsync(StudentGroupRequest request) { if (await _groupingService.ExcludeStudentAsync(request.StudentId, request.GroupId)) { return(Ok()); } return(NotFound()); }
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")); } }
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)}") });
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)); }
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())); } }