Ejemplo n.º 1
0
        public EmployeeMutation(IEmployeeRepository employeeRepository, IDbContextScopeFactory dbContextScope)
        {
            _authUtility = new AuthenticationUtility();

            FieldAsync <EmployeeType>("addEmployee",
                                      arguments: new QueryArguments {
                new QueryArgument <NonNullGraphType <AddEmployeeType> > {
                    Name = "employeeData"
                }
            },
                                      resolve: async context =>
            {
                if (!_authUtility.ValidateContext(context))
                {
                    throw new ExecutionError("ErrorCode: UNAUTHORIZED_USER, Message: 401 Unautherized error.");
                }

                AddEmployeeDataModel employeeData = context.GetArgument <AddEmployeeDataModel>("employeeData");

                using (dbContextScope.Create(DbContextScopeOption.ForceCreateNew))
                {
                    return(await employeeRepository.AddEmployee(employeeData));
                }
            });
        }
Ejemplo n.º 2
0
        public EmployeeQuery(IEmployeeRepository employeeRepository, IDbContextScopeFactory dbContextScope)
        {
            _authUtility = new AuthenticationUtility();

            FieldAsync <ListGraphType <EmployeeType> >(Name = "employees", resolve: async context =>
            {
                if (!_authUtility.ValidateContext(context))
                {
                    throw new ExecutionError("ErrorCode: UNAUTHORIZED_USER, Message: 401 Unautherized error.");
                }

                using (dbContextScope.CreateReadOnly())
                {
                    return(await employeeRepository.GetEmployees());
                }
            });

            FieldAsync <EmployeeType>(Name = "employee",
                                      arguments: new QueryArguments {
                new QueryArgument <NonNullGraphType <EmployeeFilterType> > {
                    Name = "employeeFilter"
                }
            },
                                      resolve: async context =>
            {
                if (!_authUtility.ValidateContext(context))
                {
                    throw new ExecutionError("ErrorCode: UNAUTHORIZED_USER, Message: 401 Unautherized error.");
                }

                EmployeeModelFilter employeeFilter = context.GetArgument <EmployeeModelFilter>("employeeFilter");
                using (dbContextScope.CreateReadOnly())
                {
                    return(await employeeRepository.GetEmployee(employeeFilter.EmployeeId));
                }
            });
        }