コード例 #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);
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the SocialNetworkDbContext class.
 /// The Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder)
 /// method will still be called to allow further configuration of the options.
 /// </summary>
 /// <param name="configureConnection">The method to configure context options with connection string.</param>
 /// <param name="connection">The connection string.</param>
 /// <param name="optionsAction">The additional options action.</param>
 public SocialNetworkDbContext(Func <DbContextOptionsBuilder <SocialNetworkDbContext>, string, Action <DbContextOptionsBuilder <SocialNetworkDbContext> >, DbContextOptionsBuilder <SocialNetworkDbContext> > configureConnection, string connection, Action <DbContextOptionsBuilder <SocialNetworkDbContext> > optionsAction)
     : base(DbResourceEntityExtensions.CreateDbContextOptions(configureConnection, connection, optionsAction))
 {
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the SocialNetworkDbContext class.
 /// The Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder)
 /// method will still be called to allow further configuration of the options.
 /// </summary>
 /// <param name="configureConnection">The method to configure context options with connection string.</param>
 /// <param name="connection">The connection string.</param>
 public SocialNetworkDbContext(Func <DbContextOptionsBuilder, string, DbContextOptionsBuilder> configureConnection, string connection)
     : base(DbResourceEntityExtensions.CreateDbContextOptions <SocialNetworkDbContext>(configureConnection, connection))
 {
 }
コード例 #6
0
        /// <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));
        }
コード例 #7
0
 /// <summary>
 /// Searches.
 /// </summary>
 /// <param name="q">The query arguments.</param>
 /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
 /// <returns>A collection of entity.</returns>
 public virtual async Task <CollectionResult <TEntity> > SearchAsync(QueryData q, CancellationToken cancellationToken = default)
 {
     return(await DbResourceEntityExtensions.SearchAsync(await GetDbSetAsync(), q, MapQuery, cancellationToken));
 }
コード例 #8
0
 public static DbContextOptions CreateDbContextOptions <T>() where T : DbContext
 {
     return(DbResourceEntityExtensions.CreateDbContextOptions <T>(UseSqlServer, dbConn));
 }
コード例 #9
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));
        }
コード例 #10
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));
        }
コード例 #11
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));
        }
コード例 #12
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));
        }
コード例 #13
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));
        }
コード例 #14
0
ファイル: AccountDbContext.cs プロジェクト: nuscien/nuscien
 /// <summary>
 /// Initializes a new instance of the AccountDbContext class.
 /// The Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder)
 /// method will still be called to allow further configuration of the options.
 /// </summary>
 /// <param name="configureConnection">The method to configure context options with connection string.</param>
 /// <param name="connection">The database connection.</param>
 /// <param name="optionsAction">The additional options action.</param>
 public AccountDbContext(Func <DbContextOptionsBuilder <AccountDbContext>, DbConnection, Action <DbContextOptionsBuilder <AccountDbContext> >, DbContextOptionsBuilder <AccountDbContext> > configureConnection, DbConnection connection, Action <DbContextOptionsBuilder <AccountDbContext> > optionsAction)
     : base(DbResourceEntityExtensions.CreateDbContextOptions(configureConnection, connection, optionsAction))
 {
 }
コード例 #15
0
ファイル: AccountDbContext.cs プロジェクト: nuscien/nuscien
 /// <summary>
 /// Initializes a new instance of the AccountDbContext class.
 /// The Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder)
 /// method will still be called to allow further configuration of the options.
 /// </summary>
 /// <param name="configureConnection">The method to configure context options with connection string.</param>
 /// <param name="connection">The database connection.</param>
 public AccountDbContext(Func <DbContextOptionsBuilder, DbConnection, DbContextOptionsBuilder> configureConnection, DbConnection connection)
     : base(DbResourceEntityExtensions.CreateDbContextOptions <AccountDbContext>(configureConnection, connection))
 {
 }