示例#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)
                              );
        }
示例#2
0
        private void AddSubjectQueries(SubjectFacade subjectFacade)
        {
            Field <ListGraphType <SubjectType> >(
                "allSubjects",
                resolve: context => subjectFacade.GetAll()
                );

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

                return(id != null ? (subjectFacade.GetById((int)id)) : null);
            }
                                );
        }
        public ResponseData <Subject> GetSubjectById(string id)
        {
            ResponseData <Subject> response = new ResponseData <Subject>();

            int currId = 0;

            int.TryParse(id, out currId);

            if (currId != default(int))
            {
                try
                {
                    SubjectFacade subjectFacade = new SubjectFacade();
                    response.Data = subjectFacade.GetById(currId);
                }
                catch (Exception ex)
                {
                    ExceptionHandlerFactory.Factory.GetResponseExceptionHandler(response).Handle(ex);
                }
            }

            return(response);
        }
示例#4
0
        private void AddGroupSubjectQueries(GroupSubjectFacade groupSubjectFacade, SubjectFacade subjectFacade,
                                            UserFacade userFacade)
        {
            Field <ListGraphType <GroupSubjectType> >(
                "allGroupSubjects",
                resolve: context => groupSubjectFacade.GetAll()
                );

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

                IEnumerable <GroupSubject> groupSubjects = groupSubjectFacade.GetByGroupId(groupId);

                foreach (var groupSubject in groupSubjects)
                {
                    groupSubject.Subject = subjectFacade.GetById(groupSubject.SubjectId);
                    groupSubject.Teacher = userFacade.GetById(groupSubject.TeacherId);
                }

                return(groupSubjects);
            }
                                                      );

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

                IEnumerable <GroupSubject> groupSubjects = groupSubjectFacade.GetScheduleByTeacherId(teacherId);

                foreach (var groupSubject in groupSubjects)
                {
                    groupSubject.Subject = subjectFacade.GetById(groupSubject.SubjectId);
                    groupSubject.Teacher = userFacade.GetById(groupSubject.TeacherId);
                }

                return(groupSubjects);
            }
                                                      );

            Field <ListGraphType <GroupSubjectType> >("teachersDisabled",
                                                      arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "dayOfWeek"
            },
                                                                                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "orderNumber"
            },
                                                                                    new QueryArgument <ListGraphType <IntGraphType> > {
                Name = "teachers"
            }),
                                                      resolve: context => {
                var teachers    = context.GetArgument <List <int> >("teachers");
                var dayOfWeek   = context.GetArgument <int>("dayOfWeek");
                var orderNumber = context.GetArgument <int>("orderNumber");

                List <GroupSubject> groupSubjects = new List <GroupSubject>();

                foreach (var teacher in teachers)
                {
                    GroupSubject groupSubject =
                        groupSubjectFacade.GetByDayAndOrderAndTeacher(dayOfWeek, orderNumber, teacher);
                    if (groupSubject != null)
                    {
                        groupSubjects.Add(groupSubject);
                    }
                }

                return(groupSubjects);
            }
                                                      );

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

                return(groupSubjectFacade.GetByDayAndGroup(groupId, dayOfWeek));
            }
                                                      );

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

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