コード例 #1
0
        public async Task <IActionResult> PutBills(int id, ApiBills bills)
        {
            if (id != bills.BillId)
            {
                return(BadRequest("Bill does not exist."));
            }

            var resource = new CoreBills
            {
                BillId    = bills.BillId,
                BillLate  = bills.BillLate,
                BillName  = bills.BillName,
                BillPrice = bills.BillPrice,
                DueDate   = bills.DueDate,
                User      = await _userRepo.GetUserById(bills.UserId)
            };

            try
            {
                await _repo.UpdateBillAsync(resource);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await _repo.BillExistAsync(id))
                {
                    return(NotFound("Bill not found"));
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Bill updated!"));
        }