public ActionResult Selection(int id) { using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { Session session = entities.Sessions.Single(x => x.Id == id); SessionModel model = new SessionModel { Id = session.Id, Color = session.Color, InventoryList = new List <int>(), Price = session.Price, Start = session.Start, Title = session.Title }; model.Inventory = session.Baskets.Any() ? (session.Game.Capacity) - session.Baskets.Where(x => x.PurchaseDate.HasValue || x.ReservedUntilDate > DateTime.UtcNow).Sum(y => y.Players.Count()) : session.Game.Capacity; for (int i = 1; i <= model.Inventory; i++) { model.InventoryList.Add(i); } return(View(model)); } }
public ActionResult Index(WillCallModel model) { //parse selection to get usable id int selectedId = Convert.ToInt32(model.selection.Substring(0, model.selection.IndexOf(" ") + 1)); using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { model.session = entities.Sessions.Single(x => x.Id == selectedId); model.players = new List <string>(); model.stringSessions = new List <string>(); //get players var playerIdList = entities.sp_willCallPlayers(selectedId); foreach (var item in playerIdList) { Player p = entities.Players.Single(x => x.Id == item); string stringP = p.FirstName + " " + p.LastName + " " + p.Email + " " + p.Phone + " " + p.Measurements; model.players.Add(stringP); } List <Session> sessionList = new List <Session>(); //create dropdown list sessionList = entities.Sessions.Where(x => x.Start >= DateTime.UtcNow).ToList(); foreach (var item in sessionList) { string str = item.Id + " " + item.Game.Title + " " + item.Start; model.stringSessions.Add(str); } } return(View(model)); }
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 })); }
public ActionResult Payment(int?id) { CheckOut model = new CheckOut(); using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { Basket 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(); if (User.Identity.IsAuthenticated) { User u = entities.Users.Single(X => X.Email == User.Identity.Name); model.FirstName = u.FirstName; model.LastName = u.LastName; model.Email = u.Email; } } return(View(model)); }
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() { List <Game> model = new List <Game>(); using (EscapeRoomDBEntities entity = new EscapeRoomDBEntities()) { model = entity.Games.ToList(); } return(View(model)); }
// GET: Calendar public ActionResult Index(string showName) { using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { CalendarSearchModel model = new CalendarSearchModel { game = HttpUtility.UrlDecode(showName), games = entities.Games.Select(x => x.Title).ToArray() }; return(View(model)); } }
//GET: Account public ActionResult Index() { RegistrationModel model = new RegistrationModel(); using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { var user = entities.Users.Single(x => x.Email == User.Identity.Name); model.FirstName = user.FirstName; model.LastName = user.LastName; model.Phone = user.Phone; } return(View(model)); }
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")); }
public ActionResult Success(int id) { CheckOut model = new CheckOut(); using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { Basket b = entities.Baskets.Single(x => x.ID == id); model.numPlayers = b.Players.Count; model.Players = new Player[model.numPlayers]; model.session = new Models.Session { Id = b.Session.Id, Price = b.Session.Price, Title = b.Session.Title, Start = b.Session.Start }; return(View(model)); } }
// GET: WillCall public ActionResult Index() { WillCallModel model = new WillCallModel(); //TODO: Refactor this //get all current sessions and convert to string list for model List <Session> sessionList = new List <Session>(); model.stringSessions = new List <String>(); using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { sessionList = entities.Sessions.Where(x => x.Start >= DateTime.UtcNow).ToList(); foreach (var item in sessionList) { string str = item.Id + " " + item.Game.Title + " " + item.Start; model.stringSessions.Add(str); } } return(View(model)); }
public ActionResult Data(string showName, string minInventory) { List <SessionModel> list = null; int minInventoryNum = Convert.ToInt32(minInventory); using (EscapeRoomDBEntities entities = new EscapeRoomDBEntities()) { //search query for showname and minimum inventory if (!string.IsNullOrEmpty(showName) && !string.IsNullOrEmpty(minInventory)) { list = entities.Sessions.Where(x => x.Title == showName && (x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Any() ? (x.Game.Capacity) - x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Sum(y => y.Players.Count()) : x.Game.Capacity) >= minInventoryNum).Select(x => new SessionModel { Id = x.Id, Title = x.Title, Color = x.Color, Start = x.Start, Url = "../Checkout/Selection/" + x.Id, Inventory = x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Any() ? (x.Game.Capacity) - x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Sum(y => y.Players.Count()) : x.Game.Capacity }).ToList(); } //search query for only show name else if (!string.IsNullOrEmpty(showName)) { list = entities.Sessions.Where(x => x.Title == showName).Select(x => new SessionModel { Id = x.Id, Title = x.Title, Color = x.Color, Start = x.Start, Inventory = x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Any() ? (x.Game.Capacity) - x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Sum(y => y.Players.Count()) : x.Game.Capacity, Url = "../Checkout/Selection/" + x.Id }).ToList(); } //search query for only minimum inventory else if (!string.IsNullOrEmpty(minInventory)) { list = entities.Sessions.Where(x => minInventoryNum <= (x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Any() ? (x.Game.Capacity) - x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Sum(y => y.Players.Count()) : x.Game.Capacity)).Select(x => new SessionModel { Id = x.Id, Title = x.Title, Color = x.Color, Start = x.Start, Inventory = x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Any() ? (x.Game.Capacity) - x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Sum(y => y.Players.Count()) : x.Game.Capacity, Url = "../Checkout/Selection/" + x.Id }).ToList(); } //no search curriculum else { list = entities.Sessions.Select(x => new SessionModel { Id = x.Id, Title = x.Title, Color = x.Color, Start = x.Start, Inventory = x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Any() ? (x.Game.Capacity) - x.Baskets.Where(z => z.PurchaseDate.HasValue || z.ReservedUntilDate > DateTime.UtcNow).Sum(y => y.Players.Count()) : x.Game.Capacity, Url = "../Checkout/Selection/" + x.Id }).ToList(); } //shorten titles by getting first initials & deal with sold out shows foreach (var item in list) { //deal with sold out shows if (item.Inventory == 0) { //item.Color = "light" + item.Color; item.Url = "../Checkout/SoldOut"; item.SoldOut = true; } //get initials char[] array = item.Title.ToCharArray(); List <char> charList = new List <char>(); charList.Add(array[0]); for (var i = 1; i < array.Length; i++) { if (array[i - 1] == ' ') { charList.Add(array[i]); } } item.Title = new string(charList.ToArray()); } //change to camelcase from initial caps for compatability with FullCalendar package Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver camelSerializer = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); settings.ContractResolver = camelSerializer; string content = Newtonsoft.Json.JsonConvert.SerializeObject(list, settings); //return the list return(Content(content)); } }
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 })); } }