Exemplo n.º 1
0
 public Task UpdatePageDirectoryClosureAsync()
 {
     return(_entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.PageDirectoryClosure_Update"
                                 ));
 }
 public async Task LogAuthenticationSuccessAsync(int userId, string ipAddress, DateTime dateNow)
 {
     await _entityFrameworkSqlExecutor.ExecuteCommandAsync(_dbContext,
                                                           "Cofoundry.UserAuthenticationLog_Add",
                                                           new SqlParameter("UserId", userId),
                                                           new SqlParameter("IPAddress", ipAddress),
                                                           new SqlParameter("DateNow", dateNow)
                                                           );
 }
Exemplo n.º 3
0
 /// <summary>
 /// Copies all the page blocks from one custom entity version into the draft
 /// version of another custom entity. The version must be of the same custom
 /// entity definition.  The custom entity should already have a draft version.
 /// </summary>
 /// <param name="copyToCustomEntityId">
 /// Id of the custom entity with a draft to copy the blocks to. The custom entity
 /// should already have a draft version; the procedure will throw an error if a draft
 /// version is not found.
 /// </param>
 /// <param name="copyFromCustomEntityIdVersionId">
 /// Id of the custom entity version to copy from. The version must be of the same custom
 /// entity definition (i.e. same custom entity definition code) otherwise an exception
 /// will be thrown.
 /// </param>
 public Task CopyBlocksToDraftAsync(
     int copyToCustomEntityId,
     int copyFromCustomEntityIdVersionId
     )
 {
     return(_entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.CustomEntity_CopyBlocksToDraft",
                                 new SqlParameter("CustomEntityId", copyToCustomEntityId),
                                 new SqlParameter("CopyFromCustomEntityVersionId", copyFromCustomEntityIdVersionId)
                                 ));
 }
Exemplo n.º 4
0
        public async Task ExecuteAsync(DeleteUnstructuredDataDependenciesCommand command, IExecutionContext executionContext)
        {
            string entityName;

            var entityDefinition = _entityDefinitionRepository.GetByCode(command.RootEntityDefinitionCode);

            EntityNotFoundException.ThrowIfNull(entityDefinition, command.RootEntityDefinitionCode);
            entityName = entityDefinition.Name;

            var query        = new GetEntityDependencySummaryByRelatedEntityQuery(command.RootEntityDefinitionCode, command.RootEntityId);
            var dependencies = await _queryExecutor.ExecuteAsync(query, executionContext);

            var requiredDependency = dependencies.FirstOrDefault(d => !d.CanDelete);

            if (requiredDependency != null)
            {
                throw new ValidationException(
                          string.Format("Cannot delete this {0} because {1} '{2}' has a dependency on it.",
                                        entityName,
                                        requiredDependency.Entity.EntityDefinitionName.ToLower(),
                                        requiredDependency.Entity.RootEntityTitle));
            }

            await _entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.UnstructuredDataDependency_Delete",
                                 new SqlParameter("EntityDefinitionCode", command.RootEntityDefinitionCode),
                                 new SqlParameter("EntityId", command.RootEntityId)
                                 );
        }
Exemplo n.º 5
0
 /// <summary>
 /// Copies all the blocks from one page version into the draft version of a
 /// page. The version to copy from does not have to belong to the target page,
 /// but must use the same page template. The page to copy to should already
 /// have a draft version.
 /// </summary>
 /// <param name="copyToPageId">
 /// Id of the page with a draft to copy the blocks to. The page should already
 /// have a draft version; the procedure will throw an error if a draft version
 /// is not found.
 /// </param>
 /// <param name="copyFromPageVersionId">
 /// Id of the page version to copy from. The version does not have to belong to
 /// the same page, but must use the same page template otherwise an exception
 /// will be thrown.
 /// </param>
 /// <param name="createDate">Date to set as the create date for the new blocks.</param>
 /// <param name="creatorId">Id of the user to set as the creator fo the new blocks.</param>
 public Task CopyBlocksToDraftAsync(
     int copyToPageId,
     int copyFromPageVersionId,
     DateTime createDate,
     int creatorId
     )
 {
     return(_entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.Page_CopyBlocksToDraft",
                                 new SqlParameter("PageId", copyToPageId),
                                 new SqlParameter("CopyFromPageVersionId", copyFromPageVersionId),
                                 new SqlParameter("CreateDate", createDate),
                                 new SqlParameter("CreatorId", creatorId)
                                 ));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Updates the CustomEntityPublishStatusQuery lookup table for all
 /// PublishStatusQuery values.
 /// </summary>
 /// <param name="customEntityId">Id of the custom entity to update.</param>
 public Task UpdatePublishStatusQueryLookupAsync(int customEntityId)
 {
     return(_entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.CustomEntityPublishStatusQuery_Update",
                                 new SqlParameter("CustomEntityId", customEntityId)
                                 ));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Removes old completed entries from the AssetFileCleanupQueueItem
 /// table.
 /// </summary>
 /// <param name="completedItemRetentionTimeInSeconds">
 /// The amount of tiem in seconds to keep completed items in the queue.
 /// </param>
 /// <param name="deadLetterRetentionTimeInSeconds">
 /// The amount of time in seconds to keep items that have failed too many
 /// times andhave the "CanRetry" flag set to false.
 /// </param>
 /// <returns></returns>
 public Task CleanupAssetFileCleanupQueueItemAsync(double completedItemRetentionTimeInSeconds, double deadLetterRetentionTimeInSeconds)
 {
     return(_entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.AssetFileCleanupQueueItem_Cleanup",
                                 new SqlParameter("@CompletedItemRetentionTimeInSeconds", completedItemRetentionTimeInSeconds),
                                 new SqlParameter("@deadLetterRetentionTimeInSeconds", deadLetterRetentionTimeInSeconds)
                                 ));
 }
        public async Task ExecuteAsync(LogFailedLoginAttemptCommand command, IExecutionContext executionContext)
        {
            var connectionInfo = _clientConnectionService.GetConnectionInfo();

            await _sqlExecutor.ExecuteCommandAsync("Cofoundry.FailedAuthticationAttempt_Add",
                                                   new SqlParameter("UserAreaCode", command.UserAreaCode),
                                                   new SqlParameter("Username", TextFormatter.Limit(command.Username, 150)),
                                                   new SqlParameter("IPAddress", connectionInfo.IPAddress),
                                                   new SqlParameter("DateTimeNow", executionContext.ExecutionDate)
                                                   );
        }
 public Task ExecuteAsync(SetPlayerLikedCommand command, IExecutionContext executionContext)
 {
     return(_entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_teamsSiteDbContext,
                                 "app.PlayerLike_SetLiked",
                                 new SqlParameter("@PlayerId", command.PlayerId),
                                 new SqlParameter("@UserId", executionContext.UserContext.UserId),
                                 new SqlParameter("@IsLiked", command.IsLiked),
                                 new SqlParameter("@CreateDate", executionContext.ExecutionDate)
                                 ));
 }
Exemplo n.º 10
0
        public async Task ExecuteAsync(DeleteUnstructuredDataDependenciesCommand command, IExecutionContext executionContext)
        {
            await _dependableEntityDeleteCommandValidator.ValidateAsync(command.RootEntityDefinitionCode, command.RootEntityId, executionContext);

            await _entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.UnstructuredDataDependency_Delete",
                                 new SqlParameter("EntityDefinitionCode", command.RootEntityDefinitionCode),
                                 new SqlParameter("EntityId", command.RootEntityId)
                                 );
        }
Exemplo n.º 11
0
        public async Task InvalidateUserAccountRecoveryRequestsAsync(
            int userId,
            string[] authorizedTaskTypeCodes,
            DateTime dateNow
            )
        {
            string authorizedTaskTypeCodesParameterValue = null;

            if (!EnumerableHelper.IsNullOrEmpty(authorizedTaskTypeCodes))
            {
                authorizedTaskTypeCodesParameterValue = string.Join(",", authorizedTaskTypeCodes);
            }

            await _entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.AuthorizedTask_Invalidate",
                                 new SqlParameter("@userId", userId),
                                 new SqlParameter("@AuthorizedTaskTypeCodes", authorizedTaskTypeCodesParameterValue),
                                 new SqlParameter("@DateNow", dateNow)
                                 );
        }
        public Task ExecuteAsync(SetCatLikedCommand command, IExecutionContext executionContext)
        {
            // We could use the EF DbContext here, but it's faster to make this change using a
            // stored procedure. We use IEntityFrameworkSqlExecutor here to simplify this.
            // For more info see https://www.cofoundry.org/docs/framework/entity-framework-and-dbcontext-tools#executing-stored-procedures--raw-sql

            return(_entityFrameworkSqlExecutor
                   .ExecuteCommandAsync(_spaSiteDbContext,
                                        "app.CatLike_SetLiked",
                                        new SqlParameter("@CatId", command.CatId),
                                        new SqlParameter("@UserId", executionContext.UserContext.UserId),
                                        new SqlParameter("@IsLiked", command.IsLiked),
                                        new SqlParameter("@CreateDate", executionContext.ExecutionDate)
                                        ));
        }
        public async Task ExecuteAsync(LogAuthenticatedUserInCommand command, IExecutionContext executionContext)
        {
            var user = await Query(command.UserId).SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(user, command.UserId);

            var connectionInfo = _clientConnectionService.GetConnectionInfo();

            SetLoggedIn(user, executionContext);
            await _dbContext.SaveChangesAsync();

            await _sqlExecutor.ExecuteCommandAsync("Cofoundry.UserLoginLog_Add",
                                                   new SqlParameter("UserId", user.UserId),
                                                   new SqlParameter("IPAddress", connectionInfo.IPAddress),
                                                   new SqlParameter("DateTimeNow", executionContext.ExecutionDate)
                                                   );
        }