public EmployeeType(ICongeRepository congeRepository, ISortieRepository sortieRepository, ITeamEmployeeRepository teamEmployeeRepository, IDataLoaderContextAccessor dataLoader)
        {
            Field(x => x.Id, type: typeof(IdGraphType)).Description("Id property from the owner object.");
            Field(x => x.FirstName).Description(" First Name property from the owner object.");
            Field(x => x.LastName).Description("Last Name property from the owner object");
            Field(x => x.Login);
            Field(x => x.Password);
            Field(x => x.RemainingCongeSolde);
            Field(x => x.InitialCongeSolde).Description("Initial Conge Solde property from the owner object.");

            Field <ListGraphType <CongeType> >(
                "conges",
                resolve: context =>
            {
                var loader = dataLoader.Context.GetOrAddCollectionBatchLoader <int, Conge>("GetCongesByEmployeeIds", congeRepository.GetCongesByEmployeeIds);
                return(loader.LoadAsync(context.Source.Id));
            }

                );

            Field <ListGraphType <SortieType> >(
                "sorties",
                resolve: context =>
            {
                var loader = dataLoader.Context.GetOrAddCollectionBatchLoader <int, Sortie>("GetSortiesByEmployeeIds", sortieRepository.GetSortiesByEmployeeIds);
                return(loader.LoadAsync(context.Source.Id));
            }
                );

            Field <ListGraphType <TeamEmployeeType> >(
                "teamEmployee",
                resolve: context =>
            {
                var loader = dataLoader.Context.GetOrAddCollectionBatchLoader <int, TeamEmployee>("GetTeamEmployeeByEmployeeIds", teamEmployeeRepository.GetTeamEmployeeByEmployeeIds);
                return(loader.LoadAsync(context.Source.Id));
            }
                );
        }
示例#2
0
        public EmployeeQuery(IEmployeeRepository repository, ICongeRepository congeRepository, ISortieRepository sortieRepository)
        {
            Field <ListGraphType <EmployeeType> >(
                "employees",
                resolve: context => repository.GetAll()
                );

            Field <EmployeeType>(
                "Employee",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "empId"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <int>("empId");
                return(repository.GetEmployeeById(id));
            }
                );

            Field <EmployeeType>(
                "login",



                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "login"
            },
                                              new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                string login    = context.GetArgument <string>("login");
                string password = context.GetArgument <string>("password");
                return(repository.GetEmployeeByLogin(login, password));
            }
                );
        }
示例#3
0
        public EmployeeMutation(IEmployeeRepository repository, ICongeRepository congeRepository, ISortieRepository sortieRepository)
        {
            Field <EmployeeType>(
                "createEmployee",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <EmployeeInputType> > {
                Name = "emp"
            }),
                resolve: context =>
            {
                var empl = context.GetArgument <Employee>("emp");
                return(repository.CreateEmployee(empl));
            }
                );


            Field <CongeType>(
                "createConge",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <CongeInputType> > {
                Name = "conge"
            }),
                resolve: context =>
            {
                var temp = context.GetArgument <Conge>("conge");
                return(congeRepository.CreateConge(temp));
            }
                );

            Field <CongeType>(
                "updateConge",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <CongeInputType> > {
                Name = "conge"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "congeId"
            }),
                resolve: context =>
            {
                var conge   = context.GetArgument <Conge>("conge");
                var congeId = context.GetArgument <int>("congeId");

                var dbConge    = congeRepository.GetCongeById(congeId);
                var employeeId = dbConge.EmployeeId;


                if (dbConge == null)
                {
                    context.Errors.Add(new ExecutionError("Couldn't find conge in db."));
                    return(null);
                }
                var dbEmployee = repository.GetEmployeeById(employeeId);
                if (dbEmployee == null)
                {
                    context.Errors.Add(new ExecutionError("Couldn't find conge in db."));
                    return(null);
                }


                var date1     = dbConge.start_Date;
                var date2     = dbConge.end_Date;
                var sub       = date2.Subtract(date1);
                int remaining = dbEmployee.RemainingCongeSolde - sub.Days;
                repository.UpdateEmployeeRemaining(dbEmployee, remaining);

                return(congeRepository.UpdateConge(dbConge, conge));
            }
                );


            Field <EmployeeType>(
                "updateEmployee",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <EmployeeInputType> > {
                Name = "employee"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "employeeId"
            }),
                resolve: context =>
            {
                var employee   = context.GetArgument <Employee>("employee");
                var employeeId = context.GetArgument <int>("employeeId");

                var dbEmployee = repository.GetEmployeeById(employeeId);
                if (dbEmployee == null)
                {
                    context.Errors.Add(new ExecutionError("Couldn't find conge in db."));
                    return(null);
                }

                return(repository.UpdateEmployee(dbEmployee, employee));
            }
                );



            Field <SortieType>(
                "createSortie",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <SortieInputType> > {
                Name = "sortie"
            }),
                resolve: context =>
            {
                var temp = context.GetArgument <Sortie>("sortie");
                return(sortieRepository.CreateSortie(temp));
            }
                );

            Field <SortieType>(
                "updateSortie",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <SortieInputType> > {
                Name = "sortie"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "sortieId"
            }),
                resolve: context =>
            {
                var sortie   = context.GetArgument <Sortie>("sortie");
                var sortieId = context.GetArgument <int>("sortieId");

                var dbSortie = sortieRepository.GetSortieById(sortieId);
                if (dbSortie == null)
                {
                    context.Errors.Add(new ExecutionError("Couldn't find sortie in db."));
                    return(null);
                }

                return(sortieRepository.UpdateSortie(dbSortie, sortie));
            }
                );
        }