public async Task <IActionResult> PutProductItem(int id, [FromBody] ProductItem body) { if (ModelState.IsValid) { await Db.Connection.OpenAsync(); var query = new ProductItemQuery(Db); var result = await query.FindOneAsync(id); if (result is null) { return(new NotFoundResult()); } result.Title = body.Title; result.Price = body.Price; result.Image_url = body.Image_url; result.Created_at = body.Created_at; result.Updated_at = body.Updated_at; result.Description = body.Description; await result.UpdateAsync(); return(new OkObjectResult(result)); } return(BadRequest(ModelState)); }
public async Task <ActionResult <IEnumerable <ProductItem> > > GetProductItems([FromQuery] ProductParameters productParameters) { await Db.Connection.OpenAsync(); var query = new ProductItemQuery(Db); var result = await query.GetAllProducts(productParameters); var count = await query.GetCount(); return(Ok(new Responce <ProductItem>(result, count))); }
public async Task <ActionResult <ProductItem> > GetProductItem(int id) { await Db.Connection.OpenAsync(); var query = new ProductItemQuery(Db); var result = await query.FindOneAsync(id); if (result is null) { return(new NotFoundResult()); } return(new OkObjectResult(result)); }
public async Task <IActionResult> DeleteProductItem(int id) { await Db.Connection.OpenAsync(); var query = new ProductItemQuery(Db); var result = await query.FindOneAsync(id); if (result is null) { return(new NotFoundResult()); } await result.DeleteAsync(); return(new OkResult()); }