public void UpdateStake() { var newStake = TicketsInBasket.ToSyncList().Sum(x => x.Stake); if (newStake != stake) { stake = newStake; OnPropertyChanged("Stake"); } }
public void CopyValues() { if (!ChangeTracker.TicketBuyActive) { foreach (var ticket in TicketsInBasket.ToSyncList()) { foreach (var tipItemVw in ticket.TipItems.ToSyncList()) { tipItemVw.Value = tipItemVw.OddView.Value; } } } }
// return the content of user's basket public async Task <IActionResult> Basket() { // find user logged in var user = await _userManager.GetUserAsync(User); // get all the tickets saved in the basket var basketTickets = _context.BasketTickets.Include(x => x.Performance).ThenInclude(y => y.Play) .Include(x => x.BookedSeat).ThenInclude(y => y.Seat).Where(bt => bt.BasketId == user.Id); // find the basket var basket = await _context.Basket.FindAsync(user.Id); // model for showing multiple components of a basket ViewBasket viewBasket = new ViewBasket { DeliveryMethod = new List <string>(), tickets = new List <TicketsInBasket>() }; // add second option for shipping viewBasket.DeliveryMethod.Add("Pick from collection booth"); if (basketTickets != null) { // filter what details to show for tickets foreach (var item in basketTickets) { TicketsInBasket ticket = new TicketsInBasket { Price = item.Price, RowNumber = item.BookedSeat.Seat.RowNumber, SeatLetter = item.BookedSeat.Seat.ColumnLetter, PerformanceName = item.Performance.Play.Name, Id = item.Id, PerformanceTime = item.Performance.Date, }; viewBasket.Total += item.Price; viewBasket.tickets.Add(ticket); } viewBasket.ApprovedDiscounts = user.ApprovedMultipleDiscounts; viewBasket.SavedCard = user.SavedCustomerCard; viewBasket.DeliveryMethod.Add(basket.ShippingMethod); return(View(viewBasket)); } return(View(viewBasket)); }
//private decimal CalculateConfidenceFactor(Ticket ticket) //{ // string localDelimeter = "*"; // string serverDelimeter = "|"; // decimal matchConfidenceFactor = 0; // decimal maxBetLiability = 0; // decimal marketConfidenceFactor = 0; // for (int i = 0; i < ticket.TipItems.Count; i++) // { // string matchId = ticket.TipItems.ElementAt(i).Match.MatchId.ToString(); // string oddTag = ticket.TipItems.ElementAt(i).Odd.OddTag.Value; // string tournamentId = ticket.TipItems.ElementAt(i).Match.MatchView.TournamentView.LineObject.SvrGroupId.ToString(); // string sportId = ticket.TipItems.ElementAt(i).Match.MatchView.SportView.LineObject.SvrGroupId.ToString(); // LiabilityLn liab = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue(matchId + localDelimeter + LineSr.MATCH_FACTOR); // if (liab != null && (liab.factor.Value < matchConfidenceFactor || matchConfidenceFactor == 0)) // { // matchConfidenceFactor = liab.factor.Value; // } // liab = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue(tournamentId + localDelimeter + LineSr.TOURN_CONF_RATING); // if (liab != null) // { // LiabilityLn franchisorRating = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue(liab.factor.Value.ToString() + localDelimeter + LineSr.CONF_RATING_VALUES); // if (franchisorRating != null && (franchisorRating.factor.Value < maxBetLiability || maxBetLiability == 0)) // maxBetLiability = franchisorRating.factor.Value; // } // else // { // LiabilityLn franchisorRating = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue("3" + localDelimeter + LineSr.CONF_RATING_VALUES); // if (franchisorRating != null && (franchisorRating.factor.Value < maxBetLiability || maxBetLiability == 0)) // maxBetLiability = franchisorRating.factor.Value; // } // //marketConfidenceFactor "MATCH|180201|BD_TAG_0_1*LIMIT_FACTORS" // liab = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue("MATCH" + serverDelimeter + matchId + serverDelimeter + oddTag + localDelimeter + LineSr.LIMIT_FACTORS); // if (liab == null) // { // liab = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue("TOURNAMENT" + serverDelimeter + tournamentId + serverDelimeter + oddTag + localDelimeter + LineSr.LIMIT_FACTORS); // if (liab == null) // { // liab = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue("SPORT" + serverDelimeter + sportId + serverDelimeter + oddTag + localDelimeter + LineSr.LIMIT_FACTORS); // if (liab == null) // { // liab = LineSr.Instance.AllObjects.Liabilities.SafelyGetValue("SPORT" + serverDelimeter + sportId + serverDelimeter + "DEFAULT" + localDelimeter + LineSr.LIMIT_FACTORS); // if (liab != null && (liab.factor.Value < marketConfidenceFactor || marketConfidenceFactor == 0)) // { // marketConfidenceFactor = liab.factor.Value; // } // } // else if (liab.factor.Value < marketConfidenceFactor || marketConfidenceFactor == 0) // { // marketConfidenceFactor = liab.factor.Value; // } // } // else if (liab.factor.Value < marketConfidenceFactor || marketConfidenceFactor == 0) // { // marketConfidenceFactor = liab.factor.Value; // } // } // else if(liab.factor.Value < marketConfidenceFactor || marketConfidenceFactor == 0) // { // marketConfidenceFactor = liab.factor.Value; // } // } // if (matchConfidenceFactor == 0) // matchConfidenceFactor = 1; // if (marketConfidenceFactor == 0) // marketConfidenceFactor = 1; // return matchConfidenceFactor * maxBetLiability * marketConfidenceFactor; //} public void UpdateTicket() { lock (_lockUpdate) { var ticketsInBasket = TicketsInBasket.ToSyncList(); foreach (var ticket in ticketsInBasket) { ticket.User = ChangeTracker.CurrentUser; if (TicketState == TicketStates.Single && ticket.TipItems.ToSyncList().Count(x => x.IsChecked) >= 2) { TicketState = TicketStates.Multy; } if (TicketState != TicketStates.Single && ticket.TipItems.ToSyncList().Count(x => x.IsChecked) < 2) { if (ticketsInBasket.Count == 1) { ticketsInBasket.First().TicketState = TicketStates.Single; } TicketState = TicketStates.Single; } DataBinding.UpdateSystemOrCombiticket(ticket); if (ticket.Stake > ticket.MaxBet && ChangeTracker.CurrentUser.Cashpool > 0) { OnChangeStake("max", ticket, ChangeTracker.CurrentUser.Cashpool); } } UpdateStake(); } OnPropertyChanged("MaxBet"); OnPropertyChanged("MaxWin"); OnPropertyChanged("MinBet"); OnPropertyChanged("CurrentTicketPossibleWin"); OnPropertyChanged("Count"); OnPropertyChanged("TotalOddDisplay"); OnPropertyChanged("ManipulationFeeValue"); OnPropertyChanged("ManipulationFeePercentage"); OnPropertyChanged("BonusValue"); OnPropertyChanged("BonusValueRounded"); OnPropertyChanged("IsVisibleBank"); OnPropertyChanged("BonusPercentage"); }
// basket checkout public async Task <IActionResult> Checkout(string stripeToken, bool RememberMe, string customerName, decimal Total, string selectedDelivery) { var user = await _userManager.GetUserAsync(User); var role = await _userManager.GetRolesAsync(user); var tickets = await _context.BasketTickets.Include(x => x.Performance).ThenInclude(y => y.Play) .Include(x => x.BookedSeat).ThenInclude(y => y.Seat).Where(x => x.BasketId == user.Id).ToListAsync(); // check if any seats if (tickets.Count > 0 && Total > 0) { long amount = long.Parse(Total.ToString("#.00").Replace(".", "")); if (amount < 100) { amount *= 100; } // verify payment succeeds if (Charge(user.Email, stripeToken, amount, RememberMe)) { // charge succeeded, create an order Models.Order newOrder = new Models.Order() { OrderTime = DateTime.Now, UserId = user.Id, DeliveryMethod = selectedDelivery, IsPrinted = false }; // check the type of client if (role[0] == "Customer") { newOrder.ClientName = user.FirstName + " " + user.LastName; } else if (role[0] == "AgencyOrClub") { newOrder.ClientName = user.AgencyOrClubName; } else { newOrder.DeliveryMethod = "Pick from collection booth"; newOrder.ClientName = customerName; } // see if there was a discount DateTime time = DateTime.Now; bool discount = false; if (((int)time.DayOfWeek < 5) && ((int)time.DayOfWeek > 0)) { discount = true; } List <TicketsInBasket> ticketsBought = new List <TicketsInBasket>(); // create a sold ticket for each seat reserved foreach (BasketTicket basketTicket in tickets) { TicketsInBasket ticket = new TicketsInBasket { Price = basketTicket.Price, RowNumber = basketTicket.BookedSeat.Seat.RowNumber, SeatLetter = basketTicket.BookedSeat.Seat.ColumnLetter, PerformanceName = basketTicket.Performance.Play.Name, Id = basketTicket.Id, PerformanceTime = basketTicket.Performance.Date }; ticketsBought.Add(ticket); SoldTicket soldTicket = new SoldTicket { PlayName = basketTicket.Performance.Play.Name, UserId = user.Id, CustomerName = newOrder.ClientName, PerformanceTimeAndDate = basketTicket.Performance.Date, ColumnLetter = ticket.SeatLetter, Band = basketTicket.BookedSeat.Seat.Band, RowNumber = ticket.RowNumber }; if (discount) { soldTicket.PaidPrice = basketTicket.Price * 8 / 10; } else { soldTicket.PaidPrice = basketTicket.Price; } newOrder.SoldTickets.Add(soldTicket); } decimal finalPrice = 0; // add order to database await _context.Orders.AddAsync(newOrder); foreach (BasketTicket basketTicket in tickets) { var bookedSeat = await _context.BookedSeats .FirstOrDefaultAsync(x => x.Id == basketTicket.BookedSeatId); if (discount) { finalPrice += basketTicket.Price; } bookedSeat.Booked = 2; _context.Update(bookedSeat); } var basket = await _context.Basket.Include(x => x.Tickets).FirstOrDefaultAsync(x => x.UserId == user.Id); basket.Tickets.Clear(); await _context.SaveChangesAsync(); if (role[0] == "AgencyOrClub" && ticketsBought.Count > 19) { if (user.ApprovedMultipleDiscounts == true) { finalPrice = finalPrice * 9 / 10; } else { finalPrice = finalPrice * (decimal)9.5 / 10; } } // cereate tickets and receipt view TicketAndReceipt ticketAndReceipt = new TicketAndReceipt() { TotalCost = Total, OrderId = newOrder.Id, PersonName = newOrder.ClientName, Tickets = ticketsBought, DiscountApplied = discount, Saved = 0 }; if (discount) { ticketAndReceipt.Saved = Total - finalPrice; } return(View(ticketAndReceipt)); } else { return(RedirectToAction(nameof(Basket))); } } TempData["UserNotifier"] = new UserNotifier() { CssFormat = "alert-danger", Content = "Payment was declined", MessageType = "Error!" }; return(View()); }
// use when customer saved card details public async Task <IActionResult> UseSavedCard(decimal Total, string selectedDelivery) { var user = await _userManager.GetUserAsync(User); var role = await _userManager.GetRolesAsync(user); var tickets = await _context.BasketTickets.Include(x => x.Performance).ThenInclude(y => y.Play) .Include(x => x.BookedSeat).ThenInclude(y => y.Seat).Where(x => x.BasketId == user.Id).ToListAsync(); long amount = 0; // check if any seats if (tickets.Count > 0 && Total > 0) { // calculate the amount amount = long.Parse(Total.ToString("#.00").Replace(".", "")); if (amount < 100) { amount *= 100; } } else { // if basket empty return Basket View return(RedirectToAction(nameof(Basket))); } var chargeOptions = new ChargeCreateOptions { Amount = amount, Currency = "gbp", Description = "Theatre charge", CustomerId = user.SavedCustomerCard }; var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeOptions); // if charge succeeded create order if (charge.Status.ToLower() == "succeeded") { // charge succeeded, create an order Models.Order newOrder = new Models.Order() { OrderTime = DateTime.Now, UserId = user.Id, DeliveryMethod = selectedDelivery, IsPrinted = false }; // check who is the customer if (role[0] == "Customer") { newOrder.ClientName = user.FirstName + " " + user.LastName; } else if (role[0] == "AgencyOrClub") { newOrder.ClientName = user.AgencyOrClubName; } // see if there was a discount DateTime time = DateTime.Now; bool discount = false; if (((int)time.DayOfWeek < 5) && ((int)time.DayOfWeek > 0)) { discount = true; } List <TicketsInBasket> ticketsBought = new List <TicketsInBasket>(); // create a sold ticket for each seat reserved foreach (BasketTicket basketTicket in tickets) { TicketsInBasket ticket = new TicketsInBasket { Price = basketTicket.Price, RowNumber = basketTicket.BookedSeat.Seat.RowNumber, SeatLetter = basketTicket.BookedSeat.Seat.ColumnLetter, PerformanceName = basketTicket.Performance.Play.Name, Id = basketTicket.Id, PerformanceTime = basketTicket.Performance.Date }; ticketsBought.Add(ticket); SoldTicket soldTicket = new SoldTicket { PlayName = basketTicket.Performance.Play.Name, UserId = user.Id, CustomerName = newOrder.ClientName, PerformanceTimeAndDate = basketTicket.Performance.Date, ColumnLetter = ticket.SeatLetter, Band = basketTicket.BookedSeat.Seat.Band, RowNumber = ticket.RowNumber }; // check if there is a discount for week days if (discount) { soldTicket.PaidPrice = basketTicket.Price * 8 / 10; } else { soldTicket.PaidPrice = basketTicket.Price; } newOrder.SoldTickets.Add(soldTicket); } decimal finalPrice = 0; // add order to database await _context.Orders.AddAsync(newOrder); //reserve seats foreach (BasketTicket basketTicket in tickets) { var bookedSeat = await _context.BookedSeats .FirstOrDefaultAsync(x => x.Id == basketTicket.BookedSeatId); if (discount) { finalPrice += basketTicket.Price; } bookedSeat.Booked = 2; _context.Update(bookedSeat); } var basket = await _context.Basket.Include(x => x.Tickets).FirstOrDefaultAsync(x => x.UserId == user.Id); // remove all the tickets in the basket basket.Tickets.Clear(); await _context.SaveChangesAsync(); // if agency/club and approved, receive discounts for more than 20 tickets if (role[0] == "AgencyOrClub" && ticketsBought.Count > 19) { if (user.ApprovedMultipleDiscounts == true) { finalPrice = finalPrice * 9 / 10; } else { finalPrice = finalPrice * (decimal)9.5 / 10; } } // create tickets and receipt view TicketAndReceipt ticketAndReceipt = new TicketAndReceipt() { TotalCost = Total, OrderId = newOrder.Id, PersonName = newOrder.ClientName, Tickets = ticketsBought, DiscountApplied = discount, Saved = 0 }; if (discount) { ticketAndReceipt.Saved = Total - finalPrice; } return(View(nameof(Checkout), ticketAndReceipt)); } else { // if payment failed resend to basket return(RedirectToAction(nameof(Basket))); } }