private ConcertListViewModel GetSearchedConcert(IEnumerable <SearchResult <ConcertSearchHit> > searchResults, string searchValue) { // If search result matches a single event var intConcertId = Convert.ToInt32(searchResults.First(r => r.Document.FullTitle == searchValue).Document.ConcertId); var selectedConcert = _concertRepository.GetConcertById(intConcertId); var venuesList = _venueRepository.GetVenues(); var selectedConcertVenue = venuesList.Find(v => v.VenueId.Equals(selectedConcert.VenueId)); selectedConcert.VenueModel = selectedConcertVenue; return(new ConcertListViewModel() { ConcertList = new List <ConcertListViewModel.ConcertViewModel>() { new ConcertListViewModel.ConcertViewModel() { ConcertId = selectedConcert.ConcertId, Name = selectedConcert.ConcertName, Date = selectedConcert.ConcertDate, Performer = selectedConcert.PerformerModel.ShortName, Venue = selectedConcert.VenueModel.VenueName } }, VenueList = venuesList.Select(v => new ConcertListViewModel.VenueViewModel() { VenueId = v.VenueId, VenueName = v.VenueName, CityId = v.VenueCityModel.CityId, CityName = v.VenueCityModel.CityName, StateId = v.VenueCityModel.StateModel.StateId, StateName = v.VenueCityModel.StateModel.StateName, ConcertCount = v.ConcertQty }).ToList() }); }
public ActionResult PurchaseTicketsWithCreditCard(FindSeatsViewModel viewModel) { // Check Information if (!ModelState.IsValid) { return(RedirectToAction("Index", "Home")); } var domainModels = new List <PurchaseTicketsModel>(); var seats = viewModel.Purchase.Seats.Replace(" ", "").Split(',').ToList(); var seatSectionId = viewModel.Purchase.SeatSectionId; var sectionName = _seatSectionRepository.GetSeatSectionDetails(seatSectionId).Description; //get concert date to calculate number of days prior concert var concertId = viewModel.Purchase.ConcertId; var selectedConcert = _concertRepository.GetConcertById(concertId); var concertDate = selectedConcert.ConcertDate; var daysToConcert = (concertDate - DateTime.Now).Days; foreach (var seat in seats) { // Map to Domain Model var domainModel = new PurchaseTicketsModel() { ConcertId = concertId, SeatSectionId = seatSectionId, Quantity = viewModel.Purchase.Quantity, Seat = seat, CustomerId = ((CustomerModel)Session["SessionUser"]).CustomerId, CustomerName = ((CustomerModel)Session["SessionUser"]).FirstName, TMinusDaysToConcert = daysToConcert }; //verify if seat has discount var discountedSeats = _discountRepository.GetDiscountedSeat(seatSectionId, Convert.ToInt32(seat)); //there is discount on this seat if (discountedSeats.Count > 0) { var discountSeatAndSeatSection = discountedSeats.First(); domainModel.Discount = discountSeatAndSeatSection.Discount; } domainModels.Add(domainModel); //update allseats table var fullSeatDescription = sectionName + " Seat " + seat; int tminusDaysToConcert = 0; if (daysToConcert >= 0 && daysToConcert <= 5) { tminusDaysToConcert = 5; } if (daysToConcert > 5 && daysToConcert <= 10) { tminusDaysToConcert = 10; } if (daysToConcert > 10 && daysToConcert <= 15) { tminusDaysToConcert = 15; } if (daysToConcert > 15 && daysToConcert <= 20) { tminusDaysToConcert = 20; } if (daysToConcert > 20 && daysToConcert <= 25) { tminusDaysToConcert = 25; } //update only when number of days is less than 25 days as only 0-25 days is required for probability of sales graph if (daysToConcert <= 25) { var seatDetails = _allSeatsRepository.GetSeatDetails(fullSeatDescription, tminusDaysToConcert); var count = 0; if (domainModel.Discount == 0) { count = seatDetails.DiscountZero; count++; } else if (domainModel.Discount == 10) { count = seatDetails.DiscountTen; count++; } else if (domainModel.Discount == 20) { count = seatDetails.DiscountTwenty; count++; } else if (domainModel.Discount == 30) { count = seatDetails.DiscountThirty; count++; } _allSeatsRepository.UpdateSeatDetails(Convert.ToInt32(domainModel.Discount), seatDetails.SeatDescription, domainModel.TMinusDaysToConcert, count); } } // Purchase Tickets and Display Result var ticketsPurchased = _ticketRepository.WriteNewTicketToDb(domainModels); DisplayMessage(ticketsPurchased != null ? string.Format("Successfully purchased tickets. You now have {0} tickets for this concert. Confirmation # {1}", ticketsPurchased.Count, ticketsPurchased[0].TicketId) : "Failed to purchase tickets."); return(RedirectToAction("Index", "Home")); }