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); }
public async Task <ActionResult <Product> > CreateAsync(Product product) { await _repository.AddProductAsync(product); return(CreatedAtAction(nameof(GetByIdAsync), new { id = product.Id }, product)); }
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)); }
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 })); } }
public async Task <IActionResult> PostProductAsync([FromBody] ProductModel product) { product.SellerId = int.Parse(User.Identity.Name); return(Ok(await productsRepository.AddProductAsync(product))); }