public async Task <IActionResult> AddOrUpdatePropertyAsync(string key, [FromBody] CreatePropertyRequest request, [FromServices] ICreatePropertyRequestToPropertyMapper mapper) { if (ModelState.IsValid) { var property = mapper.Map(request); await _service.AddOrUpdateProductPropertyAsync(property, key); var link = _urlHelper.Link(GetPropertiesByProductRouteName, new { controller = "properties", key = key }); return(Created(link, link)); } return(BadRequest()); }
public ProductEntity Map(CreateProductRequest source) { if (source == null) { return(null); } var properties = source?.Properties?.Select(p => _propertyMapper.Map(p)).ToList(); var launches = source?.Launches?.Select(l => _launchMapper.Map(l)).ToList(); var price = _priceMapper.Map(source.Price); return(new ProductEntity { Key = KeyBuilder.Build(), Code = source.Code, Name = source.Name, Properties = properties, Launches = launches, Price = price, IsEnabled = true }); }