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
        public ActionResult Edit(int id, EditUser form)
        {
            User u          = _userRequester.Get(SessionManager.User.Id);
            bool canUpdate  = form.LastName != u.LastName || form.FirstName != u.FirstName || form.ScreenName != u.ScreenName || form.Email != u.Email || form.Address != u.Address;
            bool screenName = _userRequester.GetAll().Where(u => u.Id != SessionManager.User.Id && u.ScreenName == form.ScreenName).FirstOrDefault() is null;
            bool email      = _userRequester.GetAll().Where(u => u.Id != SessionManager.User.Id && u.Email == form.Email).FirstOrDefault() is null;

            try
            {
                if (ModelState.IsValid && (SessionManager.User.Id == id) && !(SessionManager.User.Token is null))
                {
                    if (canUpdate)
                    {
                        if (screenName && email)
                        {
                            _apiTokenRequester.UpdateWithToken(new User(id, form.LastName, form.FirstName, form.ScreenName, form.Email, form.Address)
                                                               , "user/" + id, SessionManager.User.Token);

                            ViewBag.Message = "Profile successfully updated";
                            return(RedirectToAction(nameof(Index)));
                        }

                        else if (!screenName)
                        {
                            ViewBag.Message = "Screen Name already used";
                        }

                        else
                        {
                            ViewBag.Message = "Email address not avilable";
                        }

                        return(View(form));
                    }

                    ViewBag.Message = "You changed nothing, nice try";
                    return(View(form));
                }

                ViewBag.Message = "Session has expired";
                return(RedirectToAction("Index", "Auth"));
            }
            catch
            {
                return(View("Error"));
            }
        }