Exemple #1
0
        public PermissionMutations(IPermissionService permissionService, ILogger <PermissionMutations> logger)
        {
            FieldAsync <ActionResponseViewModel>(
                "add",
                "Add a new permissions for user",
                new QueryArguments(new QueryArgument <ListGraphType <PermissionInputViewModel> > {
                Name = "permissions"
            }),
                async context =>
            {
                try
                {
                    var permissions = context.GetArgument <List <Permission> >("permissions");
                    var username    = context.UserContext.As <GraphQLUserContext>().UserId.ToString();
                    return(await permissionService.AddAsync(permissions, username));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Permissions.ToString());

            FieldAsync <ActionResponseViewModel>(
                "remove",
                "Remove permissions for user",
                new QueryArguments(new QueryArgument <ListGraphType <PermissionInputViewModel> > {
                Name = "permissions"
            }),
                async context =>
            {
                try
                {
                    var permissions = context.GetArgument <List <Permission> >("permissions");
                    var username    = context.UserContext.As <GraphQLUserContext>().UserId.ToString();
                    return(await permissionService.RemoveAsync(permissions, username));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Permissions.ToString());
        }
        public TeamMutations(ICrudService <Team> teamService, ILogger <TeamMutations> logger)
        {
            FieldAsync <ActionResponseViewModel>(
                "create",
                "Add a new team",
                new QueryArguments(new QueryArgument <TeamCreateViewModel> {
                Name = "team"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Team>("team");
                    return(await teamService.AddAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Team.ToString());

            FieldAsync <ActionResponseViewModel>(
                "update",
                "Update team",
                new QueryArguments(new QueryArgument <TeamUpdateViewModel> {
                Name = "team"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Dictionary <string, object> >("team");
                    return(await teamService.UpdateAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Team.ToString());
        }
        public CaptainMutations(ICrudService <Captain> captainService, ILogger <CaptainMutations> logger)
        {
            FieldAsync <ActionResponseViewModel>(
                "create",
                "Add a new captain to the fleet",
                new QueryArguments(new QueryArgument <CaptainCreateViewModel> {
                Name = "captain"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Captain>("captain");
                    return(await captainService.AddAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Captain.ToString());

            FieldAsync <ActionResponseViewModel>(
                "update",
                "Update captain",
                new QueryArguments(new QueryArgument <CaptainUpdateViewModel> {
                Name = "captain"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Dictionary <string, object> >("captain");
                    return(await captainService.UpdateAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Captain.ToString());
        }
 public ExplorationMutations(ICrudService <Exploration> explorationService, ILogger <ExplorationMutations> logger)
 {
     FieldAsync <ActionResponseViewModel>(
         "create",
         "Add a new exploration to the fleet",
         new QueryArguments(new QueryArgument <ExplorationCreateViewModel> {
         Name = "exploration"
     }),
         async context =>
     {
         try
         {
             var model = context.GetArgument <Exploration>("exploration");
             return(await explorationService.AddAsync(model));
         }
         catch (Exception ex)
         {
             logger.LogCritical(ex.Message, ex);
             return(ActionResponse.ServerError());
         }
     }).AuthorizeWith(UserPermission.Exploration.ToString());
 }
        public UserMutations(IUserService userService, ILogger <UserMutations> logger)
        {
            FieldAsync <ActionResponseViewModel>(
                "register",
                "Register new user in the platform",
                new QueryArguments(new QueryArgument <UserRegisterViewModel> {
                Name = "register"
            }),
                async context =>
            {
                try{
                    var model = context.GetArgument <UserRegister>("register");
                    return(await userService.RegisterAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            });
            FieldAsync <ActionResponseViewModel>(
                "changePassword",
                "User change password",
                new QueryArguments(new QueryArgument <UserChangePasswordViewModel> {
                Name = "password"
            }),
                async context =>
            {
                try
                {
                    var model       = context.GetArgument <UserChangePassword>("password");
                    var userContext = context.UserContext.As <GraphQLUserContext>();

                    model.Username = userContext.UserId.ToString();
                    return(await userService.ChangePasswordAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            });
            FieldAsync <ActionResponseViewModel>(
                "update",
                "Update user profile information",
                new QueryArguments(new QueryArgument <UserUpdateViewModel> {
                Name = "profile"
            }),
                async context =>
            {
                try
                {
                    var model       = context.GetArgument <UserUpdate>("profile");
                    var userContext = context.UserContext.As <GraphQLUserContext>();

                    model.Username = userContext.UserId.ToString();
                    return(await userService.UpdateAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            });
        }