コード例 #1
0
        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));
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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());
        }