コード例 #1
0
        public async Task<IActionResult> CreateAsync(Product product)
        {
            if (product.Description.Contains("XYZ Widget"))
            {
                return BadRequest();
            }

            await _repository.AddProductAsync(product);

            return CreatedAtAction(nameof(GetById), new { id = product.Id }, product);
        }
コード例 #2
0
        public async Task <ActionResult <Product> > CreateAsync(Product product)
        {
            await _repository.AddProductAsync(product);

            return(CreatedAtAction(nameof(GetByIdAsync),
                                   new { id = product.Id }, product));
        }
コード例 #3
0
        public async Task <IActionResult> CreateAsync([FromBody] Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _repository.AddProductAsync(product);

            return(CreatedAtAction(nameof(GetById), new { id = product.Id }, product));
        }
コード例 #4
0
 public async Task <ActionResult> AddProductAsync(Product product)
 {
     if (product != null)
     {
         return(new OkObjectResult(await _rep.AddProductAsync(product)));
     }
     else
     {
         return(new BadRequestObjectResult(new { ErrorMessage = ErrorMessages.ObjectNotFound }));
     }
 }
コード例 #5
0
 public async Task <IActionResult> PostProductAsync([FromBody] ProductModel product)
 {
     product.SellerId = int.Parse(User.Identity.Name);
     return(Ok(await productsRepository.AddProductAsync(product)));
 }