예제 #1
0
        public async Task AddStudentInGroup(Guid groupId, Guid studentId)
        {
            if (!await _uow.Groups.GetQuery().AnyAsync(group => group.Id == groupId))
            {
                throw new Exception("Не удалось найти данную группу!");
            }

            if (!await _uow.Students.GetQuery().AnyAsync(student => student.Id == studentId))
            {
                throw new Exception("Не удалось найти данного студента!");
            }

            var studentInGroup = await _uow.StudentGroupRelations.GetQuery()
                                 .AnyAsync(relation => relation.GroupId == groupId &&
                                           relation.StudentId == studentId);

            if (studentInGroup)
            {
                throw new Exception("Данный студент уже находится в этой группе!");
            }

            var relation = new StudentGroupRelation
            {
                GroupId   = groupId,
                StudentId = studentId
            };

            await _uow.StudentGroupRelations.CreateAsync(relation);
        }
예제 #2
0
        public async Task RemoveStudentFromGroup(Guid groupId, Guid studentId)
        {
            if (!await _uow.Groups.GetQuery().AnyAsync(group => group.Id == groupId))
            {
                throw new Exception("Не удалось найти данную группу!");
            }

            if (!await _uow.Students.GetQuery().AnyAsync(student => student.Id == studentId))
            {
                throw new Exception("Не удалось найти данного студента!");
            }

            var studentInGroup = await _uow.StudentGroupRelations.GetQuery()
                                 .AnyAsync(relation => relation.GroupId == groupId &&
                                           relation.StudentId == studentId);

            if (!studentInGroup)
            {
                throw new Exception("В этой группе нет такого студента!");
            }

            var relation = new StudentGroupRelation
            {
                GroupId   = groupId,
                StudentId = studentId
            };

            await _uow.StudentGroupRelations.RemoveAsync(relation);
        }