Пример #1
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);
            }
                                                      );
        }