コード例 #1
0
 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}'.");
             }
         }
 }
コード例 #2
0
        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));
        }
コード例 #3
0
        public async Task <IActionResult> PostAsync(Product.Create model)
        {
            await _productOrchestrator.CreateProductAsync(model);

            return(CreatedAtAction(nameof(GetAsync), new { model.Code }, null));
        }