Exemplo n.º 1
0
        public ActionResult Payment(BookingPayment bookingPayment)
        {
            Event e                = _eventRequester.Get(bookingPayment.EventId);
            bool  enoughTickets    = e.Tickets >= bookingPayment.TicketsPurchased;
            int?  ticketsRemaining = e.Tickets - bookingPayment.TicketsPurchased;

            try
            {
                if (enoughTickets)
                {
                    //if (SessionManager.User.Id != 0 && !(SessionManager.User.Token is null))
                    //{
                    //    _apiTokenRequester.GetAllWithToken<G.PaymentMethod>("paymentMethod/all/" + SessionManager.User.Id, SessionManager.User.Token);
                    //}

                    if (_apiTokenRequester.UpdateWithToken(new Event(e.Id, e.Name, e.Type, e.Organizer, e.Date, e.Location, ticketsRemaining, e.Price, e.Description)
                                                           , "event/" + bookingPayment.EventId, SessionManager.User.Token))
                    {
                        _apiTokenRequester.CreateWithToken(new G.Booking()
                        {
                            UserId           = bookingPayment.UserId,
                            EventId          = bookingPayment.EventId,
                            PurchaseDate     = DateTime.Now,
                            TicketsPurchased = bookingPayment.TicketsPurchased,
                            TicketsPrice     = bookingPayment.TicketsPrice,
                            Amount           = bookingPayment.Amount
                        }, "booking", SessionManager.User.Token);
                    }

                    if (_apiTokenRequester.GetAllWithToken <G.PaymentMethod>("paymentMethod/all/" + SessionManager.User.Id, SessionManager.User.Token)
                        .Where(p => p.CardNumber == bookingPayment.CardNumber)
                        .FirstOrDefault() is null)
                    {
                        _apiTokenRequester.CreateWithToken(new G.PaymentMethod
                        {
                            UserId         = bookingPayment.UserId,
                            CardHolder     = bookingPayment.CardHolder,
                            CardNumber     = bookingPayment.CardNumber,
                            ExpirationDate = bookingPayment.ExpirationDate,
                            CVVnumber      = bookingPayment.CVVnumber
                        }, "paymentMethod", SessionManager.User.Token);
                    }

                    TempData["Message"] = "Booking successfully completed";

                    return(RedirectToAction("Index", "Booking"));
                }

                ViewBag.Message = $"Only {e.Tickets} ticket(s) remaining";
                return(View(bookingPayment));
            }
            catch
            {
                return(View("Error"));
            }
        }
Exemplo n.º 2
0
        // GET: Booking
        public ActionResult Index()
        {
            if (!(SessionManager.User is null))
            {
                ViewBag.Message = TempData["Message"];
                return(View(_apiTokenRequester.GetAllWithToken <GetBooking>("booking/user/" + SessionManager.User.Id, SessionManager.User.Token)));
            }

            return(View("Index", "Auth"));
        }