public IActionResult GetComponentById(int id)
        {
            var component = _componentRepository.GetComponentById(id);

            if (component == null)
            {
                return(NotFound());
            }
            //ensure the request for the component originated with its owner
            var currentUser = GetCurrentUserProfile();
            var project     = _projectRepository.GetSingleProjectById(component.ProjectId);

            if (currentUser.Id == project.UserProfileId)
            {
                return(Ok(component));
            }
            return(Unauthorized());
        }
        public ComponentDetails GetComponentById(int id)
        {
            ComponentDetails response = _repository.GetComponentById(id);

            if (response == null)
            {
                return(null);
            }

            return(response);
        }
        public Query(IProductRepository productRepository, IComponentRepository componentRepository)
        {
            Field <ListGraphType <ProductType> >("products", resolve: context => productRepository.GetAllProducts());
            Field <ProductType>("product",
                                arguments: new QueryArguments(
                                    new List <QueryArgument> {
                new QueryArgument <IdGraphType> {
                    Name = "id"
                },
                new QueryArgument <StringGraphType> {
                    Name = "name"
                }
            }),
                                resolve: context =>
            {
                var id = context.GetArgument <int?>("id");

                if (id.HasValue)
                {
                    return(productRepository.GetProductById(id.Value));
                }

                var name = context.GetArgument <string>("name");

                if (!string.IsNullOrEmpty(name))
                {
                    return(productRepository.GetProductByName(name));
                }

                return(productRepository.GetAllProducts());
            });

            Field <ComponentType>("component",
                                  arguments: new QueryArguments(
                                      new List <QueryArgument> {
                new QueryArgument <IdGraphType> {
                    Name = "id"
                },
            }),
                                  resolve: context =>
            {
                var id = context.GetArgument <int?>("id");

                if (!id.HasValue)
                {
                    throw new Exception();
                }

                return(componentRepository.GetComponentById(id.Value));
            });
        }
        public ProductType(IComponentRepository componentRepository)
        {
            Field(x => x.Id).Description("Product Id");
            Field(x => x.Name).Description("Product Name");
            Field(x => x.Price).Description("Product Price");
            Field(x => x.Description).Description("Product Description");
            Field <ListGraphType <ComponentType> >("components", resolve: context => componentRepository.GetComponentsByProductId(context.Source.Id));

            Field <ComponentType>("component",
                                  arguments: new QueryArguments(new List <QueryArgument> {
                new QueryArgument <IdGraphType> {
                    Name = "id"
                },
                new QueryArgument <StringGraphType> {
                    Name = "name"
                },
            }),
                                  resolve: context =>
            {
                var id = context.GetArgument <int?>("id");

                if (id.HasValue)
                {
                    return(componentRepository.GetComponentById(id.Value));
                }

                var name = context.GetArgument <string>("name");

                if (!string.IsNullOrEmpty(name))
                {
                    return(componentRepository.GetComponentByName(name, context.Source.Id));
                }

                return(componentRepository.GetComponentsByProductId(context.Source.Id));
            });
        }
Example #5
0
        public async Task <ActionResult <Component> > GetComponentById(Guid id)
        {
            var result = await _repository.GetComponentById(id);

            return(Ok(result));
        }