public IHttpActionResult PutPurchaseTicket(int id, PurchaseTicket purchaseTicket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(purchaseTicket).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PurchaseTicketExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostPurchaseTicket(PurchaseTicket purchaseTicket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PurchaseTickets.Add(purchaseTicket);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = purchaseTicket.Id }, purchaseTicket));
        }
        public IHttpActionResult DeletePurchaseTicket(int id)
        {
            PurchaseTicket purchaseTicket = db.PurchaseTickets.Find(id);

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

            db.PurchaseTickets.Remove(purchaseTicket);
            db.SaveChanges();

            return(Ok(purchaseTicket));
        }
Exemplo n.º 4
0
        private void btnPurchaseTicket_Click(object sender, EventArgs e)
        {
            foreach (Form c in this.ParentForm.MdiChildren)
            {
                if (c.GetType() == new PurchaseTicket().GetType())
                {
                    pt = true;
                }
            }

            if (!pt)
            {
                PurchaseTicket purchaseTicket = new PurchaseTicket();
                purchaseTicket.MdiParent = this.ParentForm;
                purchaseTicket.Show();
            }
        }
Exemplo n.º 5
0
        public async Task Handle(ConsumeContext <PurchaseTicket> context)
        {
            PurchaseTicket message = context.Message;

            var units = message.order.quantity == 1 ? "ticket" : "tickets";

            Console.WriteLine($"Handling purchase for {message.order.quantity} {units}");

            // Consume the offer only once (Idempotent)
            bool offerHasBeenConsumed = await HasOfferBeenConsumed(message.offer.offerGuid);

            if (offerHasBeenConsumed)
            {
                Console.WriteLine("Already consumed");
                return;
            }

            // Validate the request
            if (message.order.quantity > message.offer.maximumQuantity ||
                message.order.quantity < message.offer.minimumQuantity)
            {
                Console.WriteLine("Invalid request");
                throw new InvalidOperationException("Order quantity is out of range");
            }

            // Test invariants
            int quantityRemaining = 3;

            if (message.order.quantity > quantityRemaining)
            {
                Console.WriteLine("Invariant violated");
                await context.Publish(new PurchaseTicketFailed
                {
                    failureReason = FailureReasons.SoldOut,
                    offer         = message.offer,
                    order         = message.order
                });
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Purchase([FromBody] PurchaseTicket command)
        {
            await ticketService.PurchaseAsync(UserId(), command.EventId, command.Amount);

            return(NoContent());
        }