Пример #1
0
        public async Task <IActionResult> GetOne(int id)
        {
            //"server=localhost;user id=root;password=ch@rm1n9;port=3306;database=miracakesdb"
            using (var db = new AppDb())
            {
                await db.Connection.OpenAsync();

                var query  = new ProductQuery(db);
                var result = await query.FindOneAsync(id);

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                return(new OkObjectResult(result));
            }
        }
Пример #2
0
        public async Task <IActionResult> DeleteOne(int id)
        {
            using (var db = new AppDb())
            {
                await db.Connection.OpenAsync();

                var query  = new ProductQuery(db);
                var result = await query.FindOneAsync(id);

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                await result.DeleteAsync();

                return(new OkResult());
            }
        }
Пример #3
0
        public async Task <IActionResult> PutOne(int id, [FromBody] Product body)
        {
            using (var db = new AppDb())
            {
                await db.Connection.OpenAsync();

                var query  = new ProductQuery(db);
                var result = await query.FindOneAsync(id);

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                result.ProductName = body.ProductName;
                await result.UpdateAsync();

                return(new OkObjectResult(result));
            }
        }