Ejemplo n.º 1
0
        public CarBrandQuery(CarBrandRepository brandRepository)
        {
            Field <ListGraphType <CarBrandType> >("brands",
                                                  resolve: context =>
            {
                return(brandRepository.FindAllEager());
            });

            Field <CarBrandType>("brand",
                                 arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <IdGraphType>
                {
                    Name = "id"
                }
            }),
                                 resolve: context =>
            {
                var id = context.GetArgument <int>("id");
                if (id <= 0)
                {
                    context.Errors.Add(new ExecutionError("Brand Id is invalid or missing"));
                    return(null);
                }

                return(brandRepository.FindByIdEager(id));
            });
        }
Ejemplo n.º 2
0
        public CarBrandMutation(CarBrandRepository brandRepository)
        {
            /**
             * NEW BRAND
             */
            Field <CarBrandType, CarBrand>()
            .Name("createBrand")
            .Argument <NonNullGraphType <CarBrandInputType> >("brand", "brand input")
            .ResolveAsync(async ctx =>
            {
                var brand = ctx.GetArgument <CarBrand>("brand");
                return(await brandRepository.Add(brand));
            });

            /**
             * UPDATE BRAND
             */
            Field <CarBrandType, CarBrand>()
            .Name("updateBrand")
            .Argument <NonNullGraphType <CarBrandInputType> >("brand", "brand input")
            .ResolveAsync(async ctx =>
            {
                var brand = ctx.GetArgument <CarBrand>("brand");

                // Check if brand exists
                var currentBrand = await brandRepository.FindById(brand.Id);
                if (currentBrand == null)
                {
                    ctx.Errors.Add(new ExecutionError("Brand not found"));
                    return(null);
                }
                // Update brand
                return(await brandRepository.Update(brand));
            });

            /**
             * DELETE BRAND
             */
            Field <CarBrandType, CarBrand>()
            .Name("deleteBrand")
            .Argument <NonNullGraphType <IdGraphType> >("id", "brand id input")
            .ResolveAsync(async ctx =>
            {
                var id = ctx.GetArgument <int>("id");

                // Check if brand exists
                var currentBrand = await brandRepository.FindById(id);
                if (currentBrand == null)
                {
                    ctx.Errors.Add(new ExecutionError("Brand not found"));
                    return(null);
                }
                // delete brand
                await brandRepository.Remove(id);

                return(null);
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main program runs here
        /// </summary>
        public static void Main()
        {
            using (CarShopDataEntities carShopDataEntities = new CarShopDataEntities())
            {
                ICarBrandRepository         carBrandRepository         = new CarBrandRepository(carShopDataEntities);
                IModelRepository            modelRepository            = new ModelRepository(carShopDataEntities);
                IExtraRepository            extraRepository            = new ExtraRepository(carShopDataEntities);
                IModelExtraSwitchRepository modelExtraSwitchRepository = new ModelExtraSwitchRepository(carShopDataEntities);
                IJava  javarepo = new Java();
                ILogic logic    = new CarBrandLogic(carBrandRepository, modelRepository, extraRepository, modelExtraSwitchRepository, javarepo);

                ConsoleMenu(logic);
            }
        }