Example #1
0
        /// <summary>
        /// Creates or updates a publish content template entity.
        /// </summary>
        /// <param name="template">The publish content template entity to save.</param>
        /// <param name="message">The commit message.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The change method.</returns>
        public async Task <ChangeMethods> SaveAsync(ContentTemplateEntity template, string message, CancellationToken cancellationToken = default)
        {
            if (template is null)
            {
                return(ChangeMethods.Invalid);
            }
            var rev     = template.CreateRevision(message);
            var context = GetContext();
            var result  = await DbResourceEntityExtensions.SaveAsync(context.ContentTemplates, context.SaveChangesAsync, template, cancellationToken);

            await DbResourceEntityExtensions.SaveAsync(context.ContentTemplateRevisions, context.SaveChangesAsync, rev, cancellationToken);

            return(result);
        }
Example #2
0
        /// <summary>
        /// Saves.
        /// </summary>
        /// <param name="value">The entity to add or update.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The change method.</returns>
        public virtual async Task <ChangingResultInfo> SaveAsync(TEntity value, CancellationToken cancellationToken = default)
        {
            var context = await GetDbContextAsync();

            if (value == null)
            {
                return(new ChangingResultInfo(ChangeMethods.Unchanged));
            }
            var isNew = value.IsNew;

            if (isNew)
            {
                OnAdd(value);
            }
            else
            {
                OnUpdate(value);
            }
            var set    = GetDbSet(context);
            var change = await DbResourceEntityExtensions.SaveAsync(set, context.SaveChangesAsync, value, cancellationToken);

            return(new ChangingResultInfo(change));
        }
Example #3
0
        /// <summary>
        /// Creates or updates the settings.
        /// </summary>
        /// <param name="key">The settings key with optional namespace.</param>
        /// <param name="siteId">The owner site identifier if bound to a site; otherwise, null.</param>
        /// <param name="value">The value.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The change method.</returns>
        public async Task <ChangeMethods> SaveSettingsAsync(string key, string siteId, JsonObjectNode value, CancellationToken cancellationToken = default)
        {
            var context = GetContext();
            var entity  = await context.Settings.FirstOrDefaultAsync(ele => ele.Name == key && ele.OwnerSiteId == siteId, cancellationToken);

            if (entity == null)
            {
                entity = new Configurations.SettingsEntity
                {
                    Name        = key,
                    OwnerSiteId = siteId,
                    State       = ResourceEntityStates.Normal,
                    Config      = value
                };
            }
            else
            {
                entity.Config = value;
            }

            entity.State = ResourceEntityStates.Normal;
            return(await DbResourceEntityExtensions.SaveAsync(context.Settings, context.SaveChangesAsync, entity, cancellationToken));
        }
        /// <summary>
        /// Saves an entity.
        /// </summary>
        /// <param name="entity">The resource entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The changing result information.</returns>
        public Task <ChangeMethods> SaveAsync(SentMailEntity entity, CancellationToken cancellationToken = default)
        {
            var context = GetContext(false);

            return(DbResourceEntityExtensions.SaveAsync(context.SentMails, context.SaveChangesAsync, entity, cancellationToken));
        }
Example #5
0
        /// <summary>
        /// Creates or updates a publish content comment entity.
        /// </summary>
        /// <param name="comment">The publish content comment entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The change method.</returns>
        public Task <ChangeMethods> SaveAsync(ContentCommentEntity comment, CancellationToken cancellationToken = default)
        {
            var context = GetContext();

            return(DbResourceEntityExtensions.SaveAsync(context.ContentComments, context.SaveChangesAsync, comment, cancellationToken));
        }
Example #6
0
        /// <summary>
        /// Creates or updates an authorization code entity.
        /// </summary>
        /// <param name="code">The authorization code entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The change method result.</returns>
        public Task <ChangeMethods> SaveAsync(AuthorizationCodeEntity code, CancellationToken cancellationToken = default)
        {
            var context = GetContext();

            return(DbResourceEntityExtensions.SaveAsync(context.Codes, context.SaveChangesAsync, code, cancellationToken));
        }
Example #7
0
        /// <summary>
        /// Creates or updates a relationship entity.
        /// </summary>
        /// <param name="relationship">The user group relationship entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The change method result.</returns>
        public Task <ChangeMethods> SaveAsync(UserGroupRelationshipEntity relationship, CancellationToken cancellationToken = default)
        {
            var context = GetContext();

            return(DbResourceEntityExtensions.SaveAsync(context.Relationships, context.SaveChangesAsync, relationship, cancellationToken));
        }
Example #8
0
        /// <summary>
        /// Creates or updates a permission item entity.
        /// </summary>
        /// <param name="permissionItem">The permission item entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>An async task result.</returns>
        public Task <ChangeMethods> SaveAsync(ClientPermissionItemEntity permissionItem, CancellationToken cancellationToken = default)
        {
            var context = GetContext();

            return(DbResourceEntityExtensions.SaveAsync(context.ClientPermissions, context.SaveChangesAsync, permissionItem, cancellationToken));
        }
Example #9
0
        /// <summary>
        /// Creates or updates a token entity.
        /// </summary>
        /// <param name="token">The token entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>An async task result.</returns>
        public Task <ChangeMethods> SaveAsync(TokenEntity token, CancellationToken cancellationToken = default)
        {
            var context = GetContext();

            return(DbResourceEntityExtensions.SaveAsync(context.Tokens, context.SaveChangesAsync, token, cancellationToken));
        }