Ejemplo n.º 1
0
        public async Task <IActionResult> CreateProductAsync([FromBody] CreateProductRequest request, [FromServices] ICreateProductRequestToProductMapper mapper, [FromServices] ICreatePhotoRequestToRequestFileMapper photoMapper)
        {
            ModelState.Validate();

            var product = mapper.Map(request);
            var profile = photoMapper.Map(request.ProfilePhoto);
            var photos  = request.Photos?.Select(photoMapper.Map)?.ToList();

            await _service.RegisterNewProductAsync(product, photos, profile);

            var urlParameters = new { controller = "products", key = product.Key };
            var link          = _urlHelper.Link(GetProductRouteName, urlParameters);

            return(Created(link, link));
        }