public async Task CreateProductAsync(Product.Create product) { using (var content = new StringContent(JsonConvert.SerializeObject(product), Encoding.UTF8, "application/json")) using (var response = await this.PostAsync(string.Empty, content)) { if (response.StatusCode != HttpStatusCode.Created) { // TODO : Better threat failures for UI throw new InvalidOperationException($"Product was not created due to '{response.ReasonPhrase}'."); } } }
public IActionResult Create([FromBody] Product.Create model) { if (ModelState.IsValid) { var item = mapper.Map(model, new Entity.Product()); repository.SaveOrUpdate(item); return(Created($"Api/Product/{item.Id}", mapper.Map <Product.Edit>(item))); } return(BadRequest(ModelState)); }
public async Task <IActionResult> PostAsync(Product.Create model) { await _productOrchestrator.CreateProductAsync(model); return(CreatedAtAction(nameof(GetAsync), new { model.Code }, null)); }