Esempio n. 1
0
        public GroupSubjectType(UserMarkFacade userMarkFacade, SubjectFacade subjectFacade, UserFacade userFacade,
                                GroupFacade groupFacade)
        {
            Field(x => x.Id);
            Field <IntGraphType>(
                "orderNumber",
                resolve: context => context.Source.OrderNumber);
            Field <IntGraphType>(
                "dayOfWeek",
                resolve: context => context.Source.DayOfWeek);
            Field <ListGraphType <UserMarkType> >(
                "userMarks",
                resolve: context => userMarkFacade.GetByGroupSubjectId(context.Source.Id));

            Field <SubjectType>("subject",
                                resolve: context => subjectFacade.GetById(context.Source.SubjectId)
                                );

            Field <UserType>("teacher",
                             resolve: context => userFacade.GetById(context.Source.TeacherId)
                             );

            Field <GroupType>("group",
                              resolve: context => groupFacade.GetById(context.Source.GroupId)
                              );
        }
Esempio n. 2
0
        private void AddNotificationMutations(NotificationFacade notificationFacade, GroupFacade groupFacade, NotificationStudentFacade notificationStudentFacade)
        {
            Field <NotificationType>("addNotification",
                                     arguments: new QueryArguments(new QueryArgument <NonNullGraphType <NotificationInputType> > {
                Name = "notification"
            }),
                                     resolve: context => {
                var notification   = context.GetArgument <Notification>("notification");
                notification.Group = groupFacade.GetById(notification.GroupId);
                return(notificationFacade.Add(notification));;
            }
                                     );

            Field <NotificationType>("deleteNotification",
                                     arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "notificationId"
            }),
                                     resolve: context => {
                var notificationId        = context.GetArgument <int>("notificationId");
                Notification notification = notificationFacade.GetById(notificationId);
                notificationStudentFacade.DeleteByNotification(notification);
                return(notificationFacade.Delete(notification));
            }
                                     );

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

                IEnumerable <Notification> notifications = notificationFacade.GetByGroupId(groupId);

                List <Notification> notificationList = new List <Notification>();

                foreach (var notification in notifications)
                {
                    if (!notificationStudentFacade.getByUserIdAndNotificationId(studentId, notification.Id))
                    {
                        notificationList.Add(notification);
                        notificationStudentFacade.Add(new NotificationStudent {
                            NotificationId = notification.Id, StudentId = studentId
                        });
                    }
                }

                return(notificationList);
            }
                                                      );
        }
Esempio n. 3
0
 public UserGroupType(GroupFacade groupFacade, UserFacade userFacade)
 {
     Field(x => x.Id);
     Field <GroupType>("group",
                       resolve: context => groupFacade.GetById(context.Source.GroupId)
                       );
     Field <UserType>("user",
                      resolve: context => userFacade.GetById(context.Source.UserId)
                      );
 }
Esempio n. 4
0
        private void AddGroupQueries(GroupFacade groupFacade)
        {
            Field <ListGraphType <GroupType> >(
                "allGroups",
                resolve: context => groupFacade.GetAll()
                );

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

                return(id != null ? (groupFacade.GetById((int)id)) : null);
            }
                              );
        }
Esempio n. 5
0
        public NotificationType(NotificationStudentFacade notificationStudentFacade, GroupFacade groupFacade)
        {
            Field(x => x.Id);
            Field <StringGraphType>("message",
                                    resolve: context => context.Source.Message);
            Field <GroupType>("group",
                              resolve: context => groupFacade.GetById(context.Source.GroupId)
                              );

            Field <ListGraphType <NotificationStudentType> >(
                "notificationStudents",
                resolve: context => notificationStudentFacade.GetByNotificationId(context.Source.Id));

            Field <NotificationStudentType>("notificationStudent",
                                            arguments: new QueryArguments(new QueryArgument <IntGraphType> {
                Name = "id"
            }),
                                            resolve: context => notificationStudentFacade.GetById(context.GetArgument <int>("id")));
        }
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));
            }
                             );
        }