Exemplo n.º 1
0
        public IHttpActionResult PutBillModel(int id, Bill billModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != billModel.id)
            {
                return(BadRequest());
            }

            Bill billToChange = billService.UpdateBill(id, billModel);

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

            // The following two clauses are from the third iteration:
            if (billToChange.paymentMade)
            {
                // TODO vouchersService.CreateVoucher(updatedBill);
                Voucher newVoucher = voucherService.CreateVoucherAfterBillPayment(billToChange);

                emailsService.SendEmail(newVoucher);
            }

            if (billToChange.paymentCancelled)
            {
                // The service method I didn't know it's function
                offerService.UpdateOffer(billToChange.offerModel, false);
            }

            return(Ok(billToChange));
        }