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!"));
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            var apiBills = new ApiBills();

            apiBills.Id           = 1;
            apiBills.UserId       = 2;
            apiBills.PurchaseName = "Mock";
            apiBills.Quantity     = 2;
            apiBills.Cost         = 3;
            apiBills.BillDate     = new DateTime();
            apiBills.Location     = "Mock Location";
            Assert.True(true);
        }
        public async Task <ActionResult> PostBills(ApiBills bills)
        {
            try
            {
                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)
                };

                await _repo.AddBillAsync(resource);

                return(Ok("Bill had been added!"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Something went wrong. {e.Message}"));
            }
        }