Exemplo n.º 1
0
        public async Task <IActionResult> CreateProduct(
            [FromServices] CreateProduct createProduct,
            ProductViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var primaryImage = await _fileManager.SaveImage(rootPath, vm.PrimaryImageFile);

            var images = new List <string>();

            if (vm.ImageFiles != null)
            {
                foreach (var image in vm.ImageFiles)
                {
                    images.Add(await _fileManager.SaveImage(rootPath, image));
                }
            }

            var request = new CreateProduct.Request
            {
                Name         = vm.Name,
                Description  = vm.Description,
                Value        = vm.Value,
                PrimaryImage = primaryImage,
                Images       = images,
                CategoryId   = vm.CategoryId
            };

            return(Ok(await createProduct.Do(request)));
        }
Exemplo n.º 2
0
        public async Task CreateProductTest(string name, string description, decimal value, int saved, bool error)
        {
            var mock = new Mock <IProductManager>();

            mock.Setup(x => x.CreateProduct(It.IsAny <Product>()))
            .Returns(Task.FromResult(saved));

            var vm = new CreateProduct.Request
            {
                Name        = name,
                Description = description,
                Value       = value,
                Images      =
                {
                    new Image {
                        Index = 0, Path = "/image1"
                    },
                    new Image {
                        Index = 1, Path = "/image2"
                    },
                    new Image {
                        Index = 2, Path = "/image3"
                    }
                }
            };

            Func <Task <CreateProduct.Response> > act = () => new CreateProduct(mock.Object).Do(vm);

            if (error)
            {
                var exception = await Assert.ThrowsAsync <Exception>(act);

                Assert.Equal("Failed to create product", exception.Message);
                mock.Verify(x => x.CreateProduct(It.IsAny <Product>()), Times.Once);
            }
            else
            {
                CreateProduct.Response response = await act();

                mock.Verify(x => x.CreateProduct(It.IsAny <Product>()), Times.Once);
                Assert.Equal(name, response.Name);
                Assert.Equal(description, response.Description);
                Assert.Equal(value, response.Value);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateProduct(
            [FromForm] TempForm form,
            [FromServices] CreateProduct createProduct,
            [FromServices] S3Client s3Client)
        {
            var product = new CreateProduct.Request
            {
                Name        = form.Name,
                Description = form.Description,
                Value       = form.Value
            };

            var results = await Task.WhenAll(UploadFiles(s3Client, form.Images));

            product.Images.AddRange(results.Select((path, index) => new Image
            {
                Index = index,
                Path  = path,
            }));

            return(Ok(await createProduct.Do(product)));
        }
Exemplo n.º 4
0
 public async Task <IActionResult> CreateProduct([FromBody] CreateProduct.Request request) => Ok((await new CreateProduct(_ctx).Do(request)));
 public async Task CreateProduct(CreateProduct.Request request) => await _createProduct.DoAsync(request);
Exemplo n.º 6
0
 public async Task <IActionResult> CreateProduct([FromServices] CreateProduct createProduct, [FromBody] CreateProduct.Request request)
 {
     return(Ok((await createProduct.Do(request))));
 }
Exemplo n.º 7
0
 public async Task <IActionResult> CreateProduct(
     CreateProduct.Request request,
     [FromServices] CreateProduct createProduct) =>
 Ok(await createProduct.ActionAsync(request));
 public async Task <IActionResult> CreateProduct([FromBody] CreateProduct.Request request)
 {
     return(Ok(await new CreateProduct(_context).Do(request)));
 }
 public async Task <IActionResult> CreatPorduct(CreateProduct.Request request, [FromServices] CreateProduct createProduct) =>
 Ok(await createProduct.Do(request));       //didn;t pass the hossting
Exemplo n.º 10
0
 public async Task <IActionResult> CreateProduct([FromBody] CreateProduct.Request vm,
                                                 [FromServices] CreateProduct createProduct) => Ok(await createProduct.DoAsync(vm));
Exemplo n.º 11
0
 public async Task <IActionResult> CreateProduct([FromBody] CreateProduct.Request request) => Ok(await new CreateProduct(_context).Create(request));