Esempio n. 1
0
        private void AddAuthorizeQueries(UserFacade userFacade, UserRoleFacade userRoleFacade)
        {
            Field <UserType>("login",
                             arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "login"
            },
                                                           new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                             resolve: context => {
                var login    = context.GetArgument <String>("login");
                var password = context.GetArgument <String>("password");
                return(userFacade.Login(login, password));
            }
                             );

            Field <UserType>("studentLogin",
                             arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "login"
            },
                                                           new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                             resolve: context => {
                var login    = context.GetArgument <String>("login");
                var password = context.GetArgument <String>("password");
                return(userFacade.Login(login, password, false));
            }
                             );
        }
Esempio n. 2
0
        private void AddUserQueries(UserFacade userFacade, UserRoleFacade userRoleFacade)
        {
            Field <ListGraphType <UserType> >(
                "allUsers",
                resolve: context => userFacade.GetAll()
                );

            Field <UserType>("user",
                             arguments: new QueryArguments(new QueryArgument <IntGraphType> {
                Name = "id"
            }),
                             resolve: context => {
                var id = context.GetArgument <int?>("id");

                return(id != null ? (userFacade.GetById((int)id)) : null);
            }
                             );

            Field <ListGraphType <UserType> >("teachers",
                                              resolve: context => userFacade.GetByUserRoleId(userRoleFacade.GetByName("Преподаватель").Id));


            Field <ListGraphType <UserType> >("studentsByGroupId",
                                              arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "groupId"
            }),
                                              resolve: context => {
                var groupId = context.GetArgument <int>("groupId");

                return(userFacade.GetStudentsByGroupId(groupId));
            }
                                              );
        }
Esempio n. 3
0
        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);
            }
                                 );
        }
Esempio n. 4
0
        public Mutations(MarkFacade markFacade, UserFacade userFacade, GroupFacade groupFacade,
                         GroupSubjectFacade groupSubjectFacade, NotificationFacade notificationFacade,
                         NotificationStudentFacade notificationStudentFacade, SubjectFacade subjectFacade,
                         UserGroupFacade userGroupFacade, UserMarkFacade userMarkFacade, UserRoleFacade userRoleFacade)
        {
            AddMarkMutations(markFacade);

            AddUserMutations(userFacade, userRoleFacade, userGroupFacade, groupFacade);

            AddGroupMutations(groupFacade);

            AddGroupSubjectMutations(groupSubjectFacade, userFacade);

            AddNotificationMutations(notificationFacade, groupFacade, notificationStudentFacade);

            AddNotificationStudentMutations(notificationStudentFacade);

            AddSubjectMutations(subjectFacade);

            AddUserGroupMutations(userGroupFacade);

            AddUserMarkMutations(userMarkFacade);

            AddUserRoleMutations(userRoleFacade);
        }
Esempio n. 5
0
 private void AddUserRoleMutations(UserRoleFacade userRoleFacade)
 {
 }
Esempio n. 6
0
        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));
            }
                             );
        }
Esempio n. 7
0
 public UserType(UserGroupFacade userGroupFacade, UserMarkFacade userMarkFacade, UserRoleFacade userRoleFacade,
                 GroupFacade groupFacade, GroupSubjectFacade groupSubjectFacade)
 {
     Field(x => x.Id);
     Field <StringGraphType>("login",
                             resolve: context => context.Source.Login);
     Field <StringGraphType>("password",
                             resolve: context => context.Source.Password);
     Field <StringGraphType>("firstName",
                             resolve: context => context.Source.FirstName);
     Field <StringGraphType>("lastName",
                             resolve: context => context.Source.LastName);
     Field <StringGraphType>("secondName",
                             resolve: context => context.Source.SecondName);
     Field <ListGraphType <GroupType> >("group",
                                        resolve: context => {
         return(userGroupFacade.GetByUserId(context.Source.Id, groupFacade));
     }
                                        );
     Field <ListGraphType <UserMarkType> >("userMarks",
                                           resolve: context => userMarkFacade.GetByUserId(context.Source.Id)
                                           );
     Field <UserMarkType>("userMark",
                          arguments: new QueryArguments(new QueryArgument <IntGraphType> {
         Name = "id"
     }),
                          resolve: context => userMarkFacade.GetById(context.GetArgument <int>("id")));
     Field <UserRoleType>(
         "userRole",
         resolve: context => userRoleFacade.GetById(context.Source.UserRoleId)
         );
 }
Esempio n. 8
0
        public Queries(MarkFacade markFacade, UserFacade userFacade, GroupFacade groupFacade,
                       GroupSubjectFacade groupSubjectFacade, NotificationFacade notificationFacade,
                       NotificationStudentFacade notificationStudentFacade, SubjectFacade subjectFacade,
                       UserGroupFacade userGroupFacade, UserMarkFacade userMarkFacade, UserRoleFacade userRoleFacade)
        {
            AddMarkQueries(markFacade);

            AddUserQueries(userFacade, userRoleFacade);

            AddGroupQueries(groupFacade);

            AddGroupSubjectQueries(groupSubjectFacade, subjectFacade, userFacade);

            AddNotificationQueries(notificationFacade);

            AddNotificationStudentQueries(notificationStudentFacade);

            AddSubjectQueries(subjectFacade);

            AddUserGroupQueries(userGroupFacade);

            AddUserMarkQueries(userMarkFacade);

            AddUserRoleQueries(userRoleFacade);

            AddAuthorizeQueries(userFacade, userRoleFacade);
        }
Esempio n. 9
0
 public UserRoleController(UserFacade userFacade, UserRoleFacade userRoleFacade, RoleFacade roleFacade)
 {
     _userFacade     = userFacade;
     _userRoleFacade = userRoleFacade;
     _roleFacade     = roleFacade;
 }