Exemple #1
0
        public ActionResult Create([Bind(Include = "Title,Description,Capacity,Length,RunStart,RunEnd")] Game game)
        {
            if (ModelState.IsValid)
            {
                db.Games.Add(game);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(game));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "Id,Start,Price,SoldOut,Title,Color")] Session session)
        {
            if (ModelState.IsValid)
            {
                db.Sessions.Add(session);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Title = new SelectList(db.Games, "Title", "Tag", session.Title);
            return(View(session));
        }
Exemple #3
0
        public ActionResult Selection(SessionModel model)
        {
            int basketId = -1;

            try
            {
                using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities())
                {
                    Basket basket = new Basket();

                    basket.SessionID = model.Id;
                    for (int i = 0; i < model.OrderQty; i++)
                    {
                        basket.Players.Add(new Player {
                        });
                    }
                    basket.ReservedUntilDate = DateTime.UtcNow.AddMinutes(15);
                    entities.Baskets.Add(basket);
                    entities.SaveChanges();

                    basketId = basket.ID;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(RedirectToAction("Payment", "CheckOut", new { ID = basketId }));
        }
Exemple #4
0
        public ActionResult Success(CheckOut checkout, int id)
        {
            //initialize variables for email
            string userName  = "";
            string userEmail = "";
            string gameName  = "";
            string gameDate  = "";
            string players   = "";
            string numTix    = "";

            //pull from database
            using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities())
            {
                //get players and add info from form
                List <int?> list = entities.sp_basketPlayers(id).ToList();

                int i = 0;

                foreach (int?item in list)
                {
                    var player = entities.Players.Single(x => x.Id == item);
                    player.FirstName = checkout.Players[i].FirstName;
                    player.LastName  = checkout.Players[i].LastName;
                    player.Email     = checkout.Players[i].Email;
                    players         += player.FirstName + " " + player.LastName + ", ";
                    entities.SaveChanges();
                    i++;
                }

                //get basket and info for email info
                Basket basket = entities.Baskets.Single(x => x.ID == id);
                User   user   = entities.Users.Single(x => x.Id == basket.UserID);
                userName  = user.FirstName;
                userEmail = user.Email;
                numTix    = (i).ToString();
                gameName  = basket.Session.Title.ToString();
                gameDate  = basket.Session.Start.ToString();
                players   = players.Substring(0, players.Length - 2);
            }

            string apiKey = ConfigurationManager.AppSettings["SendGrid.Key"];

            SendGrid.SendGridAPIClient client = new SendGrid.SendGridAPIClient(apiKey);

            SendGrid.Helpers.Mail.Email from = new SendGrid.Helpers.Mail.Email("*****@*****.**");
            string subject = "Your Super Fake Chicago Unlocked Tickets";

            SendGrid.Helpers.Mail.Email to = new SendGrid.Helpers.Mail.Email(userEmail);
            string emailContent            = string.Format("<html><body><p>{0}!</p><p>Thank you for purchasing {1} fake tickets to {2} on {3}. If this was not totally fake, we would also reach out to these players: {4}. This website is a work in progress for the purpose of experimenting with .Net technologies. Please let me know any feedback you have!</p> <a href='mailto:[email protected]? subject = ChicagoUnlocked'>Email Some Feedback</a></body></html>",
                                                           userName, numTix, gameName, gameDate, players);

            SendGrid.Helpers.Mail.Content content = new SendGrid.Helpers.Mail.Content("Text/html", emailContent);
            SendGrid.Helpers.Mail.Mail    mail    = new SendGrid.Helpers.Mail.Mail(from, subject, to, content);
            client.client.mail.send.post(requestBody: mail.Get());
            return(RedirectToAction("About", "Home"));
        }
        public ActionResult Index(RegistrationModel model)
        {
            if (ModelState.IsValid)
            {
                using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities())
                {
                    var user = entities.Users.Single(x => x.Email == User.Identity.Name);
                    user.FirstName = model.FirstName;
                    user.LastName  = model.LastName;
                    user.Phone     = model.Phone;

                    entities.SaveChanges();
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemple #6
0
        public ActionResult Payment(CheckOut model, int?id)
        {
            Basket b = new Basket();

            using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities())
            {
                //create basket
                b = entities.Baskets.Single(x => x.ID == id);

                //if logged in, update record and add basket
                if (User.Identity.IsAuthenticated)
                {
                    User user = entities.Users.Single(X => X.Email == User.Identity.Name);
                    user.FirstName   = model.FirstName;
                    user.LastName    = model.LastName;
                    user.Email       = model.Email;
                    user.Phone       = model.Phone;
                    user.DateCreated = DateTime.UtcNow;
                    b.User           = user;
                    entities.SaveChanges();
                }

                //if no login, create user and add basket
                else
                {
                    User user = new Models.User();
                    user.FirstName   = model.FirstName;
                    user.LastName    = model.LastName;
                    user.Email       = model.Email;
                    user.Phone       = model.Phone;
                    user.DateCreated = DateTime.UtcNow;
                    b.User           = user;
                    entities.SaveChanges();
                }
            }

            using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities())
            {
                b = entities.Baskets.Single(x => x.ID == id);
                model.numPlayers = b.Players.Count;
                model.session    = new Models.Session
                {
                    Id    = b.Session.Id,
                    Price = b.Session.Price,
                    Title = b.Session.Title,
                    Start = b.Session.Start
                };
                model.Players = b.Players.ToArray();
            }

            //configure braintree connection and take payment
            string clientID   = ConfigurationManager.AppSettings["Braintree.ClientID"];
            string privateKey = ConfigurationManager.AppSettings["Braintree.PrivateKey"];
            string publicKey  = ConfigurationManager.AppSettings["Braintree.PublicKey"];

            Braintree.IBraintreeGateway gateway = new Braintree.BraintreeGateway(Braintree.Environment.SANDBOX, clientID, publicKey, privateKey);

            Braintree.TransactionRequest request = new Braintree.TransactionRequest
            {
                Amount             = model.session.Price * model.numPlayers,
                PaymentMethodNonce = "fake-valid-nonce",
                Customer           = new Braintree.CustomerRequest
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = model.Email
                },
                BillingAddress = new Braintree.AddressRequest
                {
                    FirstName         = model.FirstName,
                    LastName          = model.LastName,
                    StreetAddress     = model.Address,
                    ExtendedAddress   = model.Unit,
                    Locality          = model.City,
                    Region            = model.State,
                    PostalCode        = model.Zip.ToString(),
                    CountryCodeAlpha2 = "US"
                },

                Options = new Braintree.TransactionOptionsRequest
                {
                    SubmitForSettlement = true,
                    StoreInVault        = true
                },
            };



            Braintree.Result <Braintree.Transaction> result = gateway.Transaction.Sale(request);

            if (result.IsSuccess())
            {
                using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities())
                {
                    Basket completedBasket = entities.Baskets.Single(x => x.ID == id);
                    completedBasket.PurchaseDate = DateTime.UtcNow;
                    entities.SaveChanges();
                }

                return(RedirectToAction("Success", "Checkout", new { id = b.ID }));
            }
            else
            {
                string errorMessages = "";
                foreach (Braintree.ValidationError error in result.Errors.DeepAll())
                {
                    errorMessages += "Error: " + (int)error.Code + " - " + error.Message + "\n";
                }
                TempData["Flash"] = errorMessages;

                return(RedirectToAction("Payment", "Checkout", new { id = b.ID }));
            }
        }