示例#1
0
        public async Task <IActionResult> Put(int id, [FromBody] Orders body)
        {
            await Db.Connection.OpenAsync();

            body.Id = id;
            body.Db = Db;
            var orderQuery = new OrdersQuery(Db);
            var result     = await orderQuery.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }

            await result[0].UpdateAsync(body, result[0].OrdersD);
            await body.UpdateOrderAsync();

            var order = await orderQuery.FindOneAsync(id);

            if (order[0] is null)
            {
                return(new NotFoundResult());
            }

            return(new OkObjectResult(order[0]));
        }
示例#2
0
        public async Task <IActionResult> Post([FromBody] Orders body)
        {
            await Db.Connection.OpenAsync();

            body.Db = Db;
            var itemQuery = new ItemsQuery(Db);


            for (int i = 0; i < body.OrdersD.Count; i++)
            {
                var itemId     = body.OrdersD[i].IdItem;
                var findItemID = itemQuery.FindOneAsync(itemId);

                if (findItemID.Result == null)
                {
                    FoundExceptions.NotFoundException(itemId);
                }
            }


            var orderId = await body.InsertOrdersAsync();

            await body.InsertOrderDetailAsync(body);

            var orderQuery = new OrdersQuery(Db);
            var result     = await orderQuery.FindOneAsync(orderId);



            return(new OkObjectResult(result[0]));
        }
示例#3
0
        public async Task <ActionResult> Get(int id)
        {
            await Db.Connection.OpenAsync();

            var query  = new OrdersQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result[0] is null)
            {
                return(new NotFoundResult());
            }
            return(new OkObjectResult(result[0]));
        }