Beispiel #1
0
        public static string ToSqlQuery(this DynamicQuery dq)
        {
            if (dq == null)
            {
                throw new ArgumentNullException(nameof(dq));
            }

            var sqlqs = dq.ToSqlQuerySpec();

            return(ToSqlQuery(sqlqs));
        }
Beispiel #2
0
        public async Task <T> FindByEmailAsync(string email)
        {
            ThrowIfDisposed();

            if (email == null)
            {
                throw new ArgumentNullException(nameof(email));
            }

            var q = new DynamicQuery <T>
                    (
                $"select top 1 * from c where c.email = @email {EntityTypeConstraint}",
                new
            {
                email
            }
                    );

            return(await _repo.GetFirstOrDefaultAsync(q.ToSqlQuerySpec()));
        }
Beispiel #3
0
        public async Task <T> FindByNameAsync(string userName)
        {
            ThrowIfDisposed();

            if (userName == null)
            {
                throw new ArgumentNullException(nameof(userName));
            }

            var q = new DynamicQuery <T>
                    (
                $"select top 1 * from c where c.userName = @userName {EntityTypeConstraint}",
                new
            {
                userName
            }
                    );

            return(await _repo.GetFirstOrDefaultAsync(q.ToSqlQuerySpec()));
        }
Beispiel #4
0
        internal async Task <Entities.Document> FindDocumentByIdAsync(string instance, Uri projectId, Uri documentId, long?version)
        {
            // get actual version
            if (version == null)
            {
                var q = new DynamicQuery
                        (
                    "select * from c where c.entity = @entity and c.instance = @instance and c.projectId = @projectId and c.identifier = @identifier",
                    new
                {
                    entity = Entities.Document.Entity,
                    instance,
                    projectId  = projectId.ToString(),
                    identifier = documentId.ToString()
                }
                        );

                var document = await _repoDocument.GetFirstOrDefaultAsync(q).ConfigureAwait(false);

                return(document);
            }

            // get document from snapshot
            var q2 = new DynamicQuery
                     (
                "select * from c where c.entity = @entity and c.instance = @instance and c.projectId = @projectId and c.documentId = @identifier and c.version = @version",
                new
            {
                entity = Entities.DocumentVersion.Entity,
                instance,
                projectId  = projectId.ToString(),
                identifier = documentId.ToString(),
                version
            }
                     );

            var x = q2.ToSqlQuerySpec().ToSqlQuery();

            var documentVersion = await _repoDocumentVersion.GetFirstOrDefaultAsync(q2).ConfigureAwait(false);

            if (documentVersion == null)
            {
                return(null);
            }

            var newDocument = new Entities.Document
                              (
                documentVersion.Instance,
                documentVersion.ProjectId,
                documentVersion.DocumentId,
                documentVersion.DocumentTypeId,
                documentVersion.Hash,
                documentVersion.Document.Slug,
                documentVersion.Document.OriginalMeta,
                documentVersion.Document.Meta,
                documentVersion.Document.Content,
                documentVersion.Document.Date == null ? (DateTime?)null : documentVersion.Document.Date.DateTime,
                documentVersion.Document.Draft,
                documentVersion.Version
                              );

            return(newDocument);
        }