コード例 #1
0
        public async Task <IActionResult> Create(CreateProductQuery query)
        {
            var result = await mediator.Send(query);

            if (result.Success)
            {
                return(View(result.Content));
            }

            TempData["ErrorMessage"] = "Something wrong happend, please try again";

            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
        public async Task <IActionResult> Create([FromBody] CreateProductQuery createQuery)
        {
            var createProductParams = _mapper.Map <CreateProductParams>(createQuery);

            var createdProduct = await _productService.CreateProductAsync(createProductParams);

            if (createdProduct == null)
            {
                return(NotFound());
            }

            var locationUri = _uriGeneratorService.GetProductUri(createdProduct.ProductId);

            return(Created(locationUri, new Response <ProductDto>(createdProduct)));
        }