public async Task <IActionResult> Get(string groupName) { var group = await _groupsService.GetGroupAsync(groupName); if (group == null) { return(NotFound()); } return(new ObjectResult(group)); }
public async Task <IActionResult> GetGroupAsync(int groupId) { var group = await _groupsService.GetGroupAsync(groupId); if (group == null) { return(NotFound()); } return(Ok(group)); }
public async Task AddSubjectToSemester(SemesterSubjectDto semesterSubject, int groupId, int yearNumber, int semesterNumber) { var group = await _groupsService.GetGroupAsync(groupId).ConfigureAwait(false); if (group == null) { throw new ResourceNotFoundException($"Група {groupId} не знайдена"); } if (await HasGroupSubjectInScheduleAsync(groupId, semesterSubject.Subject.Id).ConfigureAwait(false)) { throw new ResourceOperationException($"Група {group.Code} вже має предмет {semesterSubject.Subject.Name} у своєму розкладі"); } var semester = await _groupSemestersService.GetGroupSemesterAsync(groupId, yearNumber, semesterNumber) .ConfigureAwait(false); if (semester == null) { throw new ResourceNotFoundException($"Семестр {yearNumber}/{semesterNumber} для групи {group.Code} не знайдений"); } var newSemesterSubject = _mapper.Map <SemesterSubject>(semesterSubject); newSemesterSubject.SemesterRefId = semester.Id; using (var transaction = await _semesterScheduleUnitOfWork.BeginTransactionAsync().ConfigureAwait(false)) { _semesterScheduleUnitOfWork.Repository.Add(newSemesterSubject); await _semesterScheduleUnitOfWork.SaveChangesAsync().ConfigureAwait(false); await _gradebooksService.CreateGradebookAsync(new GradebookDto { SemesterId = semester.Id, SubjectId = semesterSubject.Subject.Id }).ConfigureAwait(false); transaction.Commit(); } }
public async Task <IActionResult> GetGroup(long groupId) { var group = await _groupsService.GetGroupAsync(groupId); return(Ok(group)); }