private void AddUserRoleQueries(UserRoleFacade userRoleFacade) { Field <ListGraphType <UserRoleType> >( "allUserRoles", resolve: context => userRoleFacade.GetAll() ); Field <UserRoleType>("userRole", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "id" }), resolve: context => { var id = context.GetArgument <int?>("id"); return(id != null ? (userRoleFacade.GetById((int)id)) : null); } ); }
private void AddUserMutations(UserFacade userFacade, UserRoleFacade userRoleFacade, UserGroupFacade userGroupFacade, GroupFacade groupFacade) { User ParseUser(User user) { user.UserRole = userRoleFacade.GetAll().SingleOrDefault(x => x.RoleName == "Student"); return(user); } Field <UserType>("addUser", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "groupId" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "userId" }, new QueryArgument <NonNullGraphType <UserInputType> > { Name = "user" }), resolve: context => { var user = ParseUser(context.GetArgument <User>("user")); var groupId = context.GetArgument <int>("groupId"); if (user.FirstName == null || user.LastName == null || user.Login == null || user.Password == null) { throw new ArgumentException(); } if (userFacade.GetByLogin(user.Login) != null) { return(null); } user.UserRoleId = userRoleFacade.GetByName("Студент").Id; user = userFacade.Add(user); UserGroup userGroup = new UserGroup { User = user, Group = groupFacade.GetById(groupId) }; userGroupFacade.Add(userGroup); return(user); } ); Field <UserType>("deleteUser", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "userId" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "deleteId" }), resolve: context => { var deleteUser = userFacade.GetById(context.GetArgument <int>("deleteId")); userGroupFacade.Delete(userGroupFacade.GetUserGroupByUserId(deleteUser.Id)); return(userFacade.Delete(deleteUser)); } ); Field <UserType>("editUser", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "userId" }, new QueryArgument <NonNullGraphType <UserInputType> > { Name = "user" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "editId" }), resolve: context => { var editId = context.GetArgument <int>("editId"); var user = ParseUser(context.GetArgument <User>("user")); return(userFacade.Edit(editId, user)); } ); }
public async Task <IActionResult> Index() { var items = await _userRoleFacade.GetAll(); return(View(items)); }