Exemple #1
0
        public async Task <T> CreateVersion(T newVersion, T currentVersion = null, string partitionKey = null, bool incrementFromCurrentVersion = false)
        {
            ICreateVersions <T> newVersionBuilder = _newVersionBuilderFactory.CreateNewVersionBuild(CosmosRepository);

            return(await newVersionBuilder.CreateVersion(newVersion,
                                                         currentVersion,
                                                         partitionKey,
                                                         incrementFromCurrentVersion));


            // Guard.ArgumentNotNull(newVersion, nameof(newVersion));
            //
            // newVersion.Date = DateTimeOffset.Now.ToLocalTime();
            //
            // if (currentVersion == null)
            // {
            //     newVersion.Version = 1;
            //
            //     newVersion.PublishStatus = PublishStatus.Draft;
            // }
            // else
            // {
            //     newVersion.Version = await GetNextVersionNumber(newVersion, currentVersion.Version, partitionKey, incrementFromCurrentVersion);
            //
            //     if (newVersion.PublishStatus == PublishStatus.Approved && (currentVersion.PublishStatus == PublishStatus.Draft || currentVersion.PublishStatus == PublishStatus.Updated))
            //     {
            //         return newVersion;
            //     }
            //     else
            //     {
            //         switch (currentVersion.PublishStatus)
            //         {
            //             case PublishStatus.Draft:
            //                 newVersion.PublishStatus = PublishStatus.Draft;
            //                 break;
            //
            //             case PublishStatus.Approved:
            //                 if (newVersion.PublishStatus != PublishStatus.Draft)
            //                 {
            //                     newVersion.PublishStatus = PublishStatus.Updated;
            //                 }
            //
            //                 break;
            //
            //             default:
            //                 newVersion.PublishStatus = PublishStatus.Updated;
            //                 break;
            //         }
            //     }
            // }
            //
            // return newVersion;
        }
Exemple #2
0
        public async Task <T> CreateVersion(T newVersion,
                                            T currentVersion    = null,
                                            string partitionKey = null,
                                            bool incrementFromCurrentVersion = false)
        {
            ICreateVersions <T> newVersionBuilder = _newVersionBuilderFactory.CreateNewVersionBuild(CosmosRepository);

            return(await newVersionBuilder.CreateVersion(newVersion,
                                                         currentVersion,
                                                         partitionKey,
                                                         incrementFromCurrentVersion));
        }
Exemple #3
0
        public async Task <int> GetNextVersionNumber(T version = null, int currentVersion = 0, string partitionKeyId = null, bool incrementFromCurrentVersion = false)
        {
            ICreateVersions <T> newVersionBuilder = _newVersionBuilderFactory.CreateNewVersionBuild(CosmosRepository);

            return(await newVersionBuilder.GetNextVersionNumber(version,
                                                                currentVersion,
                                                                partitionKeyId,
                                                                incrementFromCurrentVersion));

            //
            // Guard.ArgumentNotNull(version, nameof(version));
            //
            // if (incrementFromCurrentVersion)
            // {
            //     return currentVersion + 1;
            // }
            //
            // CosmosDbQuery cosmosDbQuery;
            // if (string.IsNullOrWhiteSpace(partitionKeyId))
            // {
            //     string entityId = version.EntityId;
            //
            //     cosmosDbQuery = new CosmosDbQuery
            //     {
            //         QueryText = @"SELECT VALUE Max(c.content.version)
            //                 FROM    c
            //                 WHERE   c.content.entityId = @EntityID
            //                         AND c.documentType = @DocumentType
            //                         AND c.deleted = false",
            //         Parameters = new[]
            //         {
            //             new CosmosDbQueryParameter("@EntityID", entityId),
            //             new CosmosDbQueryParameter("@DocumentType", typeof(T).Name)
            //         }
            //     };
            // }
            // else
            // {
            //     cosmosDbQuery = new CosmosDbQuery
            //     {
            //         QueryText = @"SELECT VALUE Max(c.content.version)
            //                 FROM    c
            //                 WHERE   c.documentType = @DocumentType
            //                         AND c.deleted = false",
            //         Parameters = new[]
            //         {
            //             new CosmosDbQueryParameter("@DocumentType", typeof(T).Name)
            //         }
            //     };
            // }
            //
            // IEnumerable<dynamic> results;
            //
            // if (string.IsNullOrWhiteSpace(partitionKeyId))
            // {
            //     results = await CosmosRepository.DynamicQuery(cosmosDbQuery);
            // }
            // else
            // {
            //     results = await CosmosRepository.DynamicQueryPartitionedEntity<dynamic>(cosmosDbQuery, partitionKeyId);
            // }
            //
            // if (results.IsNullOrEmpty()) return 1;
            //
            // int nextVersionNumber = (int)results.First() + 1;
            //
            // return nextVersionNumber;
        }