Пример #1
0
        private async Task EnsureContactDoesNotExist(
            CreateContactCommand command,
            CancellationToken cancellationToken)
        {
            var query = new GetUserContactsQuery();
            var list  = await _queryProcessor.ExecuteAsync(query, cancellationToken);

            if (list.Any(c => c.Phone == command.Phone))
            {
                throw new ValidationException(ErrorCodes.ContactExists);
            }
        }
        public override async Task <IReadOnlyCollection <ContactReadModel> > ExecuteAsync(
            GetUserContactsQuery query,
            CancellationToken cancellationToken = default)
        {
            const string sql = @"SELECT c.*,cr.grade_value, cr.name_value as classroom_name,
								cr.grade_value as grade, ct.id as contact_type,
								ct.name as contact_type_name FROM contacts  c
							   LEFT JOIN students s on c.student_id=s.id
							   LEFT JOIN classrooms cr on cr.id=s.classroom_id
							   INNER JOIN contact_types ct ON c.contact_type_id=ct.id
							   WHERE c.created_by=@userId
							   ORDER BY c.first_name_value , c.last_name_value"                            ;

            await using var connection = new NpgsqlConnection(_connectionString);
            return((await connection.QueryAsync <ContactReadModel>(
                        sql,
                        new { userId = query.UserId })).ToList());
        }