Exemplo n.º 1
0
        public async Task <ActionResult <Check> > GetCheck(int id)
        {
            var check = await _checkService.GetAsync(id);

            if (check == null)
            {
                return(NotFound());
            }

            return(check);
        }
        public async Task <ActionResult <Purchase> > PostPurchase([FromBody] Purchase purchase)
        {
            try
            {
                Check check = await _checkService.GetAsync((int)purchase.CheckId);

                check.Purchases = new List <Purchase>();
                purchase.Check  = check;
                purchase        = await _purchaseService.CreateAsync(purchase);

                check.Purchases.Add(purchase);
                await _checkService.UpdateAsync(check);
            }
            catch (Exception e)
            {
                return(BadRequest(e.InnerException));
            }
            //return CreatedAtAction("GetPurchase", new { id = purchase.Id }, purchase);
            return(CreatedAtAction(nameof(GetPurchase), new { id = purchase.Id }, purchase));
        }