public ProjectsMutationSpecification(ProjectCommonController projectManager)
        {
            Name = "ProjectsMutation";
            var safe = new Safe(_log);

            this.RequireAuthorization();
            Field <ProjectSpecification>(
                "insert",
                Description = "add a project",
                new QueryArguments(
                    new QueryArgument <ProjectCreateUpdateSpecification> {
                Name = Value
            }
                    ),
                safe.Wrap(context =>
            {
                var project = context.GetArgument <ProjectCreateUpdateModel>(Name = Value);
                return(projectManager.Insert(project));
            })).RequirePermission(Activity.UpdateProject);

            Field <ProjectSpecification>(
                "update",
                Description = "update a project",
                new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            },
                    new QueryArgument <ProjectCreateUpdateSpecification> {
                Name = Value
            }
                    ),
                safe.Wrap(context =>
            {
                var id      = context.GetArgument <string>(Name = "id");
                var project = context.GetArgument <ProjectCreateUpdateModel>(Name = Value);
                return(projectManager.Update(id, project));
            })).RequirePermission(Activity.UpdateProject);

            Field <BooleanGraphType>(
                "delete",
                Description = "permanently remove a project",
                new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            }
                    ),
                safe.Wrap(context =>
            {
                var id = context.GetArgument <string>(Name = "id");
                return(projectManager.Delete(id));
            })).RequirePermission(Activity.DeleteProject);
        }
Esempio n. 2
0
        public ProjectsSpecification(ProjectCommonController projects)
        {
            var safe    = new Safe(_log);
            var options = new GraphQlQueryOptions <ProjectCommonController, ProjectModel, Project>(projects);

            Name = "Projects";
            Field <ProjectSpecification>(
                "byId",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "id",
                Description = "id of the project"
            }
                    ),
                resolve: safe.Wrap(context => projects.GetById(context.GetArgument <string>("id")))
                ).RequirePermission(Activity.ReadProject);
            Field <ListGraphType <ProjectSpecification> >(
                "all",
                Description = "all projects",
                resolve: safe.Wrap(context => projects.Query(queryable => queryable))
                ).RequirePermission(Activity.ReadProject);
            Field <ListGraphType <ProjectSpecification> >(
                "recent",
                Description = "recent modified projects",
                new QueryArguments(
                    new QueryArgument <IntGraphType>
            {
                Name        = "first",
                Description = "id of the project"
            }
                    ),
                safe.Wrap(context => projects
                          .Query(queryable =>
                                 queryable
                                 .OrderByDescending(x => x.UpdateDate)
                                 .Take(context.HasArgument("first") ? context.GetArgument <int>("first") : 100)
                                 ))
                ).RequirePermission(Activity.ReadProject);
            Field <QueryResultSpecification>(
                "query",
                Description = "query the projects projects",
                options.GetArguments(),
                safe.Wrap(context => options.Query(context))
                ).RequirePermission(Activity.ReadProject);
        }
Esempio n. 3
0
 public ProjectController(ProjectCommonController projectCommonController)
 {
     _projectCommonController = projectCommonController;
 }