Exemple #1
0
        /// <inheritdoc />
        public override void OnResultExecuted(ResultExecutedContext context)
        {
            IServiceProvider provider = context.HttpContext.RequestServices;
            ScopedDictionary dict     = provider.GetService <ScopedDictionary>();

            if (dict.AuditOperation?.FunctionName == null)
            {
                return;
            }
            dict.AuditOperation.EndedTime = DateTime.Now;
            IUnitOfWork unitOfWork = provider.GetService <IUnitOfWork>();

            unitOfWork?.Dispose();

            //移除当前功能,使保存审计信息的时候不再获取记录变更,审计信息不需要再审计
            dict.Function = null;
            IAuditStore store = provider.GetService <IAuditStore>();

            provider.BeginUnitOfWorkTransaction(_ =>
            {
                store?.Save(dict.AuditOperation);
            });
        }
 /// <summary>
 /// 将种子数据初始化到数据库
 /// </summary>
 /// <param name="entities"></param>
 protected override void SyncToDatabase(Role[] entities)
 {
     if (entities?.Length > 0)
     {
         _rootProvider.BeginUnitOfWorkTransaction(provider =>
         {
             RoleManager <Role> roleManager = provider.GetService <RoleManager <Role> >();
             foreach (Role role in entities)
             {
                 if (roleManager.Roles.Any(ExistingExpression(role)))
                 {
                     continue;
                 }
                 IdentityResult result = roleManager.CreateAsync(role).Result;
                 if (!result.Succeeded)
                 {
                     throw new OsharpException($"进行角色种子数据“{role.Name}”同步时出错:{result.ErrorMessage()}");
                 }
             }
         },
                                                  true);
     }
 }
Exemple #3
0
 /// <summary>
 /// 将种子数据初始化到数据库
 /// </summary>
 /// <param name="entities"></param>
 protected override void SyncToDatabase(User[] entities)
 {
     if (entities.Any())
     {
         _rootProvider.BeginUnitOfWorkTransaction(provider =>
         {
             UserManager <User> userManager = provider.GetService <UserManager <User> >();
             foreach (User user in entities)
             {
                 if (userManager.Users.Any(ExistingExpression(user)))
                 {
                     continue;
                 }
                 IdentityResult result = userManager.CreateAsync(user).Result;
                 if (!result.Succeeded)
                 {
                     throw new HybridException($"进行用户种子数据“{user.UserName}”同步时出错:{result.ErrorMessage()}");
                 }
             }
         },
                                                  true);
     }
 }