public static IRoleToken AddPostApi <TKey, TEntity, TDbContext>(this IPlatformModuleBuilder builder, Action <PostApiConfigurations <TKey, TEntity> > options = null)
            where TEntity : class
            where TDbContext : DbContext
        {
            var config = new PostApiConfigurations <TKey, TEntity>();

            options?.Invoke(config);
            return(builder.AddEntityApi <TKey, TEntity, TDbContext>(GetApiKey <TEntity>(), EntityControllerMethods.Post, c =>
                                                                    c.Then(config.Request)
                                                                    .GetRequestModel <TEntity>()
                                                                    .Then(config.ModelGeted)
                                                                    .StartValidation <TEntity>()
                                                                    .Then(config.Validate)
                                                                    .EndValidation(x => x.CreateData <TEntity, TDbContext>().Then(config.Created).OkOrNotFound().Then(config.Response))));
        }
Exemple #2
0
        public void Build(IPlatformModuleBuilder moduleBuilder)
        {
            moduleBuilder.AddModel <Model.ModelConfig>();

            var customer = moduleBuilder.AddEntityApi <long, Model.Entities.Customer>(options =>
            {
                options.ConfigDeleteApi(x => x.OnDeleted(d => d.Pipe(Pipe1)));
                options.ConfigDeleteApi(x => x.OnDeleted(d => d.Pipe(Pipe2)));
                options.ConfigDeleteApi(x => x.OnDeleted(d => d.Pipe(Pipe3)));
                options.ConfigDeleteApi(x => x.OnDeleted(d => d.Pipe(Pipe4)));
                options.ConfigDeleteApi(x => x.OnDeleted(d => d.Pipe(Pipe5)));
                options.ConfigDeleteApi(x => x.OnDeleted(d => d.Pipe(Pipe6)));

                options.ConfigGetApi(x => x.OnGeted(y => y.QueryChildFor(z => z.Orders)));
                options.ConfigPostApi(x => x.OnCreated(y => y.SaveChildsFor(z => z.Orders)));
                options.ConfigPutApi(x => x.OnUpdated(y => y.SaveChildsFor(z => z.Orders)));
            });
            var space = "PlatformModule.Test";

            moduleBuilder.AddModuleFuncion($"{space}.{nameof(Model.Entities.Customer)}", options =>
            {
                options.AddStandardApiRoles(customer, o => o.View.AddOdataPermission <Model.Entities.Customer>(build => build.AllowExpand(x => x.CreatedByUser.Name)));
            });
        }
 public static IRoleToken AddGetFlowApi <TKey, TEntity, TDbContext>(this IPlatformModuleBuilder builder, string name, DIFlowBuilderHandler <HttpRequest, IActionResult> flowBuilder) where TEntity : class where TDbContext : DbContext =>
 builder.AddEntityApi <TKey, TEntity, TDbContext>(name, EntityControllerMethods.Get, flowBuilder);
 public static IRoleToken AddEntityApi <TKey, TEntity>(this IPlatformModuleBuilder builder, string name, string methodName, DIFlowBuilderHandler <HttpRequest, IActionResult> flowBuilder) where TEntity : class => builder.AddEntityApi <TKey, TEntity, PlatformDbContext>(name, methodName, flowBuilder);
 public static EntityApiRoles AddEntityApi <TKey, TEntity, TView>(this IPlatformModuleBuilder builder, System.Linq.Expressions.Expression <Func <TEntity, TView> > projection, Action <EntityApiBuildContext <TKey, TEntity> > config = null)
     where TEntity : class
     where TView : class
 {
     return(builder.AddEntityApi <TKey, TEntity, TView, PlatformDbContext>(projection, config));
 }
 public static EntityApiRoles AddEntityApi <TKey, TEntity>(this IPlatformModuleBuilder builder, Action <EntityApiBuildContext <TKey, TEntity> > config = null)
     where TEntity : class
 {
     return(builder.AddEntityApi <TKey, TEntity, PlatformDbContext>(config));
 }
Exemple #7
0
        public void Build(IPlatformModuleBuilder moduleBuilder)
        {
            //services
            moduleBuilder.Services.AddTransient <Processors.ClearUserCacheProcessor>();
            moduleBuilder.Services.AddTransient <Processors.UpdateGroupProcessor>();
            moduleBuilder.Services.AddTransient <Processors.UpdateRoleProcessor>();
            //apis
            moduleBuilder.ConfigDataProcessor <PlatformUser>(options => options.AddTask <PlatformUserEntityTask>());
            var user = moduleBuilder.AddEntityApi <long, PlatformUser>(options =>
            {
                options.ConfigGetApi(get => get.OnValidate(x => x.Pipe(Pipes.PlatformGroupUserPipes.ValidateUser)).OnGeted(geted => geted.Pipe(model => { model.Password = null; })));
                options.ConfigPostApi(post => post.OnValidate(validate => validate.Unique(unique =>
                {
                    unique.IsCreate = true;
                    unique.AddProperty(x => x.Account);
                })));

                options.ConfigPutApi(put =>
                {
                    put.OnValidate(validate => validate.Unique(unique => unique.AddProperty(x => x.Account)).Pipe(Pipes.PlatformGroupUserPipes.ValidateUser));
                    put.OnUpdated(updated => updated.Then <PlatformUser, Processors.ClearUserCacheProcessor>());
                });
                options.ConfigQueryApi(q =>
                {
                    q.OnQueryed(x => x.Pipe(Pipes.PlatformGroupUserPipes.FilterUser));
                    q.ConfigExportSetting(settings =>
                    {
                        settings.ConfigCellWriters(x =>
                        {
                            var w            = x.Where(p => p.Tag == "Status").First();
                            w.ValueTransform = (v) => ((Platform.User.UserStatus)v) == Platform.User.UserStatus.Active ? "啟用" : "停用";
                        });
                    });
                });
                options.ConfigDeleteApi(delete => delete.OnValidate(x => x.Pipe(Pipes.PlatformGroupUserPipes.ValidateUserDelete)).OnDeleted(deleted => deleted.Then <PlatformUser, Processors.ClearUserCacheProcessor>()));
            });

            var updateGroupRole = moduleBuilder.AddPutFlowApi <long, Hcs.Platform.ViewModels.BatchUpdateView <PlatformGroupRole> >("updateRoles",
                                                                                                                                   builder => builder.GetKeyAndModel <long, Hcs.Platform.ViewModels.BatchUpdateView <PlatformGroupRole> >().Then <IActionResult, Processors.UpdateRoleProcessor>());

            var updateUserGroup = moduleBuilder.AddPutFlowApi <long, Hcs.Platform.ViewModels.BatchUpdateView <PlatformUserGroup> >("updateGroups",
                                                                                                                                   builder => builder.GetKeyAndModel <long, Hcs.Platform.ViewModels.BatchUpdateView <PlatformUserGroup> >().Then <IActionResult, Processors.UpdateGroupProcessor>());

            var groupRoleQuery = moduleBuilder.AddQueryApi <PlatformGroupRole>(opt => opt.OnQueryed(q => q.Pipe(Pipes.PlatformGroupUserPipes.FilterRoles)));
            var userGroupQuery = moduleBuilder.AddQueryApi <PlatformUserGroup>(opt => opt.OnQueryed(q => q.Pipe(Pipes.PlatformGroupUserPipes.FilterUserGroup)));
            var group          = moduleBuilder.AddEntityApi <long, PlatformGroup>(options =>
            {
                options.ConfigGetApi(get => get.OnValidate(x => x.Pipe(Pipes.PlatformGroupUserPipes.ValidateGroup)));
                options.ConfigPutApi(put =>
                {
                    put.OnValidate(validate => validate.Pipe(Pipes.PlatformGroupUserPipes.ValidateGroup));
                });
                options.ConfigQueryApi(q =>
                {
                    q.OnQueryed(x => x.Pipe(Pipes.PlatformGroupUserPipes.FilterGroup));
                    q.ConfigExportSetting(settings =>
                    {
                        settings.ConfigCellWriters(x =>
                        {
                            var w            = x.Where(p => p.Tag == "IsEnabled").First();
                            w.ValueTransform = (v) => ((bool)v) ? "是" : "否";
                        });
                    });
                });
                options.ConfigDeleteApi(delete => delete.OnValidate(x => x.Pipe(Pipes.PlatformGroupUserPipes.ValidateGroup)));
            });
            var getUsr = moduleBuilder.AddGetFlowApi <long, PlatformUser>("getmyinfo", builder =>
                                                                          builder.GetService <Platform.User.IPlatformUser>()
                                                                          .Pipe(x => x.Service.Id)
                                                                          .GetData <long, PlatformUser>().Ok());
            var changePassword = moduleBuilder.AddPutFlowApi <long, Views.ChangePasswordView>("changepassword", builder =>
                                                                                              builder.GetKeyAndModel <long, Views.ChangePasswordView>()
                                                                                              .StartValidation()
                                                                                              .Pipe(Pipes.ChangePasswordPipes.ValidateUser)
                                                                                              .Pipe(Pipes.ChangePasswordPipes.ValidateOldPassword)
                                                                                              .EndValidation(sbuilder => sbuilder.Pipe(Pipes.ChangePasswordPipes.ChangePassword).Ok()));
            //function
            var moduleName = "Basic";

            moduleBuilder.Everyone.AddRole(changePassword);
            moduleBuilder.Everyone.AddRole(getUsr);
            moduleBuilder.AddModuleFuncion(moduleName, "PlatformUser", options => options.AddStandardApiRoles(user, roleOptions =>
            {
                roleOptions.View.AddRole(userGroupQuery);
                roleOptions.Modify.AddRole(updateUserGroup);
            }).AddPermission("Admin", b =>
            {
            }));
            moduleBuilder.AddModuleFuncion(moduleName, "PlatformGroup", options => options.AddStandardApiRoles(group, roleOptions =>
            {
                roleOptions.View.AddRole(groupRoleQuery);
                roleOptions.Modify.AddRole(updateGroupRole);
            }));
        }