protected override Task <ICommandResult> Handle(SaveEventTicketDetailCommand command) { var EventTicketDetail = new EventTicketDetail(); SaveEventTicketDetailResult saveEventTicketDetailResult = new SaveEventTicketDetailResult(); var checkForEventTicketDetail = _eventTicketDetailRepository.Get(command.Id); if (checkForEventTicketDetail != null) { EventTicketDetail = new EventTicketDetail { Id = checkForEventTicketDetail.Id, EventDetailId = command.EventDetailId, TicketCategoryId = command.TicketCategoryId, IsEnabled = command.IsEnabled, CreatedUtc = DateTime.UtcNow, CreatedBy = command.ModifiedBy }; } else { EventTicketDetail = new EventTicketDetail { Id = command.Id, EventDetailId = command.EventDetailId, TicketCategoryId = command.TicketCategoryId, IsEnabled = command.IsEnabled, CreatedUtc = DateTime.UtcNow, CreatedBy = command.ModifiedBy }; } FIL.Contracts.DataModels.EventTicketDetail result = _eventTicketDetailRepository.Save(EventTicketDetail); saveEventTicketDetailResult.Id = result.Id; return(Task.FromResult <ICommandResult>(saveEventTicketDetailResult)); }
public FIL.Contracts.DataModels.EventTicketDetail CreateEventTicketDetails(long eventDetailId, int ticketCatId) { EventTicketDetail eventTicketDetail = new EventTicketDetail(); eventTicketDetail.EventDetailId = eventDetailId; eventTicketDetail.TicketCategoryId = ticketCatId; eventTicketDetail.IsEnabled = true; eventTicketDetail.CreatedUtc = DateTime.UtcNow; eventTicketDetail.CreatedBy = Guid.NewGuid(); var data = _eventTicketDetail.Save(eventTicketDetail); return(data); }
protected void UpdateAllOptions(SaveExOzProductOptionCommand command) { List <long> apiProductOptionIds = command.OptionList.Select(w => w.Id).ToList(); var exOzProductOptions = _exOzProductOptionRepository.GetByOptionIds(apiProductOptionIds); var eventTicketDetailIds = exOzProductOptions.Select(w => w.EventTicketDetailId).ToList(); var FilEventTicketDetails = _eventTicketDetailRepository.GetByIds(eventTicketDetailIds); var ticketCategoryIds = FilEventTicketDetails.Select(w => w.TicketCategoryId).ToList(); var FilTicketCategories = _ticketCategoryRepository.GetByTicketCategoryIds(ticketCategoryIds); foreach (var item in command.OptionList) { int optionCount = command.OptionList.Where(w => w.SessionId == item.SessionId).ToList().Count; try { string TicketCategoryName = GetTicketCategoryName(item, optionCount); ExOzProductOption exOzProductOption = exOzProductOptions.Where(w => w.ProductOptionId == item.Id).FirstOrDefault(); ExOzProductSession exOzProductSession = _exOzProductSessionRepository.GetBySessionId(item.SessionId); ExOzProduct exOzProduct = _exOzProductRepository.Get(exOzProductSession.ProductId); EventTicketDetail FilEventTicketDetail = FilEventTicketDetails.Where(w => w.Id == exOzProductOption.EventTicketDetailId).FirstOrDefault(); TicketCategory FilTicketCategory = FilTicketCategories.Where(w => w.Name == TicketCategoryName).FirstOrDefault(); TicketCategory retTicketCategory = UpdateTicketCategory(TicketCategoryName, FilTicketCategory, command.ModifiedBy); EventTicketDetail retEventTicketDetail = UpdateEventTicketDetail(FilEventTicketDetail, exOzProduct.EventDetailId, retTicketCategory.Id, command.ModifiedBy); EventTicketAttribute eventTicketAttribute = _eventTicketAttributeRepository.GetByEventTicketDetailId(retEventTicketDetail.Id); EventTicketAttribute FilTicketAttribute = UpdateEventTicketAttribute(item, eventTicketAttribute, retEventTicketDetail.Id, command.ModifiedBy); TicketFeeDetail ticketFeeDetail = _ticketFeeDetailRepository.GetByEventTicketAttributeId(FilTicketAttribute.EventTicketDetailId); TicketFeeDetail FilTicketFeedDetail = UpdateTicketFeeDetails(ticketFeeDetail, FilTicketAttribute.Id, command.ModifiedBy); ExOzProductOption retOption = updateProductOption(item, exOzProductOption, retEventTicketDetail.Id, exOzProductSession.Id, command.ModifiedBy); updatedOptions.OptionList.Add(retOption); } catch (Exception e) { throw; } } }
protected EventTicketDetail UpdateEventTicketDetail(EventTicketDetail FilEventTicketDetail, long FilEventDetailId, long FilTicketCategoryId, Guid ModifiedBy) { EventTicketDetail FilEventTicketDetailInserted = new EventTicketDetail(); if (FilEventTicketDetail == null) { var newFilEventTicketDetail = new EventTicketDetail { EventDetailId = FilEventDetailId, TicketCategoryId = FilTicketCategoryId, ModifiedBy = ModifiedBy, IsEnabled = true, }; FilEventTicketDetailInserted = _eventTicketDetailRepository.Save(newFilEventTicketDetail); } else { FilEventTicketDetailInserted = FilEventTicketDetail; } return(FilEventTicketDetailInserted); }
public FIL.Contracts.DataModels.EventTicketDetail SaveEventTicketDetails( CreateTicketCommand command, FIL.Contracts.Models.CreateEventV1.TicketModel ticketModel, FIL.Contracts.DataModels.EventDetail eventDetail, List <FIL.Contracts.DataModels.EventTicketDetail> eventTicketDetails) { EventTicketDetail eventTicketDetail = new EventTicketDetail(); eventTicketDetail = ticketModel.ETDId != 0 ? eventTicketDetails.Where(s => s.Id == ticketModel.ETDId).FirstOrDefault() : eventTicketDetail; eventTicketDetail.Id = ticketModel.ETDId == 0 ? 0 : ticketModel.ETDId; eventTicketDetail.AltId = ticketModel.ETDId == 0 ? Guid.NewGuid() : eventTicketDetails.Where(s => s.Id == ticketModel.ETDId).FirstOrDefault().AltId; eventTicketDetail.EventDetailId = eventDetail.Id; eventTicketDetail.TicketCategoryId = ticketModel.TicketCategoryId; eventTicketDetail.IsEnabled = ticketModel.isEnabled; eventTicketDetail.CreatedUtc = eventTicketDetail.Id != 0 ? eventTicketDetail.CreatedUtc : DateTime.UtcNow; eventTicketDetail.UpdatedUtc = eventTicketDetail.Id != 0 ? DateTime.UtcNow : eventTicketDetail.CreatedUtc; eventTicketDetail.CreatedBy = eventTicketDetail.Id != 0 ? eventTicketDetail.CreatedBy : command.ModifiedBy; eventTicketDetail.UpdatedBy = command.ModifiedBy; eventTicketDetail.ModifiedBy = command.ModifiedBy; return(_eventTicketDetailRepository.Save(eventTicketDetail)); }
public CheckoutCommandResult BlockSeat(List <SeatDetail> seatData, TransactionDetail transactionDetail, FIL.Contracts.DataModels.EventTicketAttribute eventTicketAttribute, EventTicketDetail eventTicketDetail, Guid userAltId, Channels channelId) { try { CheckoutCommandResult checkoutCommandResult = new CheckoutCommandResult(); FIL.Contracts.DataModels.EventDetail eventDetails = _eventDetailRepository.Get(eventTicketDetail.EventDetailId); var BarcodeNumber = ""; int seatCounter = 0; if (eventTicketDetail.InventoryTypeId == InventoryType.Seated || eventTicketDetail.InventoryTypeId == InventoryType.SeatedWithSeatSelection) { if (seatData != null) { foreach (var seat in seatData) { FIL.Contracts.DataModels.MatchLayoutSectionSeat matchLayoutSectionSeats = _matchLayoutSectionSeatRepository.Get(seat.MatchLayoutSectionSeatId); if (matchLayoutSectionSeats != null && matchLayoutSectionSeats.SeatStatusId != SeatStatus.Sold) { Random rd = new Random(); BarcodeNumber = eventDetails.StartDateTime.ToString("ddMM"); int uniqueIdLength = 4; string uniqueIdChars = "1234567890"; char[] uniqueIdChar = new char[uniqueIdLength]; for (int j = 0; j < uniqueIdLength; j++) { uniqueIdChar[j] = uniqueIdChars[rd.Next(0, uniqueIdChars.Length)]; } string uniqueId = new string(uniqueIdChar); matchLayoutSectionSeats.Id = matchLayoutSectionSeats.Id; matchLayoutSectionSeats.SeatStatusId = channelId == Channels.Corporate ? SeatStatus.BlockedforSponsor : SeatStatus.BlockedByCustomer; matchLayoutSectionSeats.UpdatedUtc = DateTime.UtcNow; matchLayoutSectionSeats.UpdatedBy = userAltId; _matchLayoutSectionSeatRepository.Save(matchLayoutSectionSeats); _matchSeatTicketDetailRepository.Save(new MatchSeatTicketDetail { AltId = Guid.NewGuid(), EventTicketDetailId = eventTicketDetail.Id, MatchLayoutSectionSeatId = matchLayoutSectionSeats.Id, BarcodeNumber = BarcodeNumber + "0" + (short)channelId + matchLayoutSectionSeats.Id + uniqueId, Price = transactionDetail.PricePerTicket, TransactionId = transactionDetail.TransactionId, ModifiedBy = userAltId, TicketTypeId = (TicketType)transactionDetail.TicketTypeId, SeatStatusId = SeatStatus.Sold, PrintStatusId = PrintStatus.NotPrinted, IsEnabled = true, EntryCountAllowed = 1, ChannelId = channelId, }); seatCounter++; } } if (seatData.Count == seatCounter) { checkoutCommandResult.Success = true; checkoutCommandResult.IsSeatSoldOut = false; } else { checkoutCommandResult.Success = false; checkoutCommandResult.IsSeatSoldOut = true; } } else { List <FIL.Contracts.DataModels.MatchLayoutSectionSeat> matchLayoutSectionSeats = AutoMapper.Mapper.Map <List <FIL.Contracts.DataModels.MatchLayoutSectionSeat> >(_matchLayoutSectionSeatRepository.GetByEventTicketDetails(eventTicketDetail.Id, transactionDetail.TotalTickets)); if (matchLayoutSectionSeats.Count == transactionDetail.TotalTickets) { foreach (var seatItem in matchLayoutSectionSeats) { Random rd = new Random(); BarcodeNumber = eventDetails.StartDateTime.ToString("ddMM"); int uniqueIdLength = 4; string uniqueIdChars = "1234567890"; char[] uniqueIdChar = new char[uniqueIdLength]; for (int j = 0; j < uniqueIdLength; j++) { uniqueIdChar[j] = uniqueIdChars[rd.Next(0, uniqueIdChars.Length)]; } string uniqueId = new string(uniqueIdChar); if (seatItem.SeatStatusId == SeatStatus.UnSold && (seatItem.SeatTypeId == SeatType.Available || seatItem.SeatTypeId == SeatType.WheelChair)) { if (seatItem.SeatTypeId == SeatType.WheelChair) { var wheelChairSeat = _masterLayoutCompanionSeatMappingRepository.GetByWheelChairSeatId(seatItem.Id); if (wheelChairSeat != null) { seatItem.Id = wheelChairSeat.CompanionSeatId; seatItem.SeatStatusId = channelId == Channels.Corporate ? SeatStatus.BlockedforSponsor : SeatStatus.BlockedByCustomer; seatItem.ModifiedBy = userAltId; _matchLayoutSectionSeatRepository.Save(seatItem); _matchSeatTicketDetailRepository.Save(new MatchSeatTicketDetail { AltId = Guid.NewGuid(), EventTicketDetailId = eventTicketDetail.Id, MatchLayoutSectionSeatId = wheelChairSeat.CompanionSeatId, BarcodeNumber = BarcodeNumber + "0" + (short)channelId + wheelChairSeat.CompanionSeatId + uniqueId, Price = transactionDetail.PricePerTicket, TransactionId = transactionDetail.TransactionId, ModifiedBy = userAltId, TicketTypeId = (TicketType)transactionDetail.TicketTypeId, SeatStatusId = SeatStatus.Sold, PrintStatusId = PrintStatus.NotPrinted, IsEnabled = true, EntryCountAllowed = 1, ChannelId = channelId, }); } seatItem.Id = seatItem.Id; seatItem.SeatStatusId = channelId == Channels.Corporate ? SeatStatus.BlockedforSponsor : SeatStatus.BlockedByCustomer; seatItem.ModifiedBy = userAltId; _matchLayoutSectionSeatRepository.Save(seatItem); _matchSeatTicketDetailRepository.Save(new MatchSeatTicketDetail { AltId = Guid.NewGuid(), EventTicketDetailId = eventTicketDetail.Id, MatchLayoutSectionSeatId = seatItem.Id, BarcodeNumber = BarcodeNumber + "0" + (short)channelId + seatItem.Id + uniqueId, Price = transactionDetail.PricePerTicket, TransactionId = transactionDetail.TransactionId, ModifiedBy = userAltId, TicketTypeId = (TicketType)transactionDetail.TicketTypeId, SeatStatusId = SeatStatus.Sold, PrintStatusId = PrintStatus.NotPrinted, IsEnabled = true, EntryCountAllowed = 1, ChannelId = channelId, }); } else { seatItem.Id = seatItem.Id; seatItem.SeatStatusId = channelId == Channels.Corporate ? SeatStatus.BlockedforSponsor : SeatStatus.BlockedByCustomer; seatItem.ModifiedBy = userAltId; _matchLayoutSectionSeatRepository.Save(seatItem); _matchSeatTicketDetailRepository.Save(new MatchSeatTicketDetail { AltId = Guid.NewGuid(), EventTicketDetailId = eventTicketDetail.Id, MatchLayoutSectionSeatId = seatItem.Id, BarcodeNumber = BarcodeNumber + "0" + (short)channelId + seatItem.Id + uniqueId, Price = transactionDetail.PricePerTicket, TransactionId = transactionDetail.TransactionId, ModifiedBy = userAltId, TicketTypeId = (TicketType)transactionDetail.TicketTypeId, SeatStatusId = SeatStatus.Sold, PrintStatusId = PrintStatus.NotPrinted, IsEnabled = true, EntryCountAllowed = 1, ChannelId = channelId, }); } seatCounter++; } } if (seatCounter == transactionDetail.TotalTickets) { checkoutCommandResult.Success = true; checkoutCommandResult.IsSeatSoldOut = false; } else { checkoutCommandResult.Success = false; checkoutCommandResult.IsSeatSoldOut = true; } } else { checkoutCommandResult.Success = false; checkoutCommandResult.IsSeatSoldOut = true; } } } else { for (int i = 1; i <= transactionDetail.TotalTickets * 1; i++) { Random rd = new Random(); BarcodeNumber = eventDetails.StartDateTime.ToString("ddMM"); int uniqueIdLength = 14; string uniqueIdChars = "abcdefghijklmnopqrstuvwxyz1234567890"; char[] uniqueIdChar = new char[uniqueIdLength]; for (int j = 0; j < uniqueIdLength; j++) { uniqueIdChar[j] = uniqueIdChars[rd.Next(0, uniqueIdChars.Length)]; } string uniqueId = new string(uniqueIdChar); _matchSeatTicketDetailRepository.Save(new MatchSeatTicketDetail { AltId = Guid.NewGuid(), EventTicketDetailId = eventTicketDetail.Id, BarcodeNumber = BarcodeNumber + "0" + (short)channelId + uniqueId, Price = transactionDetail.PricePerTicket, TransactionId = transactionDetail.TransactionId, ModifiedBy = userAltId, TicketTypeId = (TicketType)transactionDetail.TicketTypeId, SeatStatusId = SeatStatus.Sold, PrintStatusId = PrintStatus.NotPrinted, IsEnabled = true, EntryCountAllowed = 1, ChannelId = channelId, }); seatCounter++; } if (seatCounter == transactionDetail.TotalTickets) { checkoutCommandResult.Success = true; checkoutCommandResult.IsSeatSoldOut = false; } else { checkoutCommandResult.Success = false; checkoutCommandResult.IsSeatSoldOut = true; } } return(checkoutCommandResult); } catch (Exception e) { _logger.Log(Logging.Enums.LogCategory.Error, e); return(new CheckoutCommandResult { Success = false, IsSeatSoldOut = true }); } }
public CheckoutCommandResult SaveTransaction(CheckoutCommand checkoutCommand, IEnumerable <Contracts.Models.EventTicketAttribute> eventTicketAttributeModel, FIL.Contracts.DataModels.User user) { try { var isPaymentBypass = false; var StripeAccount = FIL.Contracts.Enums.StripeAccount.None; List <TransactionDetail> transactionDetailList = new List <TransactionDetail>(); List <FIL.Contracts.Models.CartItemModel> lstEventDetailId = new List <FIL.Contracts.Models.CartItemModel>(); FIL.Contracts.DataModels.Transaction transaction = new FIL.Contracts.DataModels.Transaction(); decimal grossTicketAmount = 0; long eventDetailId = 0, ticketCategoryId = 0; decimal netTicketAmount = 0; decimal totalDiscountAmount = 0; if (checkoutCommand.IsASI == null) { checkoutCommand.IsASI = false; } var allETD = _eventTicketDetailRepository.GetByEventTicketDetailsIds(eventTicketAttributeModel.Select(s => s.EventTicketDetailId).Distinct()).Distinct(); var allED = _eventDetailRepository.GetByIds(allETD.Select(s => s.EventDetailId).Distinct()).Distinct(); foreach (Contracts.Commands.Transaction.EventTicketAttribute ticketAttributes in checkoutCommand.EventTicketAttributeList) { var currentTA = ticketAttributes; var transactionType = checkoutCommand.IsQrTransaction ? TransactionType.QRCode : checkoutCommand.TransactionType == TransactionType.Itinerary ? TransactionType.Itinerary : ticketAttributes.TicketType == TicketType.SeasonPackage ? TransactionType.Season : ticketAttributes.TransactionType == TransactionType.LiveOnline ? TransactionType.LiveOnline : ticketAttributes.TransactionType == TransactionType.AddOns ? TransactionType.AddOns : TransactionType.Regular; decimal discountAmount = 0, donationAmount = 0; if (ticketAttributes.DiscountedPrice > 0) { discountAmount = ticketAttributes.DiscountedPrice; } if (ticketAttributes.DonationAmount != null && ticketAttributes.DonationAmount > 0) { donationAmount = (decimal)ticketAttributes.DonationAmount; } Contracts.Models.EventTicketAttribute checkoutCommandEventTicketAttribute = eventTicketAttributeModel.Where(w => w.Id == ticketAttributes.Id).FirstOrDefault(); decimal pricePerTicket = checkoutCommandEventTicketAttribute.Price; EventTicketDetail eventTicketDetail = allETD.Where(s => s.Id == checkoutCommandEventTicketAttribute.EventTicketDetailId && s.IsEnabled).FirstOrDefault(); if (eventTicketDetail != null) { EventDetail eventDetail = allED.Where(s => s.Id == eventTicketDetail.EventDetailId && s.IsEnabled).FirstOrDefault(); if (eventDetail != null) { var visitStartDate = ticketAttributes.VisitDate; var visitEndDate = ticketAttributes.VisitDate; if (checkoutCommand.TransactionType == TransactionType.Itinerary) { visitStartDate = ticketAttributes.VisitStartTime.Split(":").Count() > 1 ? new DateTime(visitStartDate.Year, visitStartDate.Month, visitStartDate.Day, Convert.ToInt32(ticketAttributes.VisitStartTime.Split(":")[0]), Convert.ToInt32(ticketAttributes.VisitStartTime.Split(":")[1]), 0) : visitStartDate; visitEndDate = ticketAttributes.VisitEndTime.Split(":").Count() > 1 ? new DateTime(visitEndDate.Year, visitEndDate.Month, visitEndDate.Day, Convert.ToInt32(ticketAttributes.VisitEndTime.Split(":")[0]), Convert.ToInt32(ticketAttributes.VisitEndTime.Split(":")[1]), 0) : visitEndDate; } visitStartDate = visitStartDate < new DateTime(1753, 1, 1) ? DateTime.UtcNow : visitStartDate; visitEndDate = visitEndDate < new DateTime(1753, 1, 1) ? DateTime.UtcNow : visitEndDate; if ((bool)checkoutCommand.IsASI) { pricePerTicket = ticketAttributes.TicketType == TicketType.Child ? 0 : checkoutCommandEventTicketAttribute.Price; } if (ticketAttributes.OverridedAmount != null && checkoutCommand.IsBSPUpgrade && ticketAttributes.OverridedAmount != 0) { pricePerTicket = (decimal)ticketAttributes.OverridedAmount; } if (ticketAttributes.TicketType == TicketType.SeasonPackage) { eventDetailId = eventTicketDetail.EventDetailId; lstEventDetailId.Add(new FIL.Contracts.Models.CartItemModel { EventDetailId = eventDetailId }); ticketCategoryId = eventTicketDetail.TicketCategoryId; IEnumerable <EventDetail> seasonEventDetails = _eventDetailRepository.GetSeasonEventDetails(eventDetail.EventId, eventDetail.VenueId).Where(s => s.IsEnabled == true); IEnumerable <EventTicketDetail> seasonEventTicketDetails = _eventTicketDetailRepository.GetByEventDetailIds(seasonEventDetails.Select(s => s.Id).Distinct()).Where(w => w.TicketCategoryId == eventTicketDetail.TicketCategoryId); List <Contracts.DataModels.EventTicketAttribute> seasonEventTicketAttributes = _eventTicketAttributeRepository.GetByEventTicketDetailIds(seasonEventTicketDetails.Select(s => s.Id).Distinct()).Where(W => W.IsEnabled == true && W.SeasonPackage == true).ToList(); var seasonPrice = seasonEventTicketAttributes[0].SeasonPackagePrice; pricePerTicket = seasonPrice / seasonEventTicketAttributes.Count; } else { eventDetailId = eventDetail.Id; lstEventDetailId.Add(new FIL.Contracts.Models.CartItemModel { EventDetailId = eventTicketDetail.EventDetailId }); ticketCategoryId = eventTicketDetail.TicketCategoryId; } if (Convert.ToInt16(ticketAttributes.TotalTickets) <= checkoutCommandEventTicketAttribute.RemainingTicketForSale) { TransactionDetail transactionDetail = new TransactionDetail(); transactionDetail.EventTicketAttributeId = ticketAttributes.Id; transactionDetail.TotalTickets = Convert.ToInt16(ticketAttributes.TotalTickets); transactionDetail.PricePerTicket = checkoutCommand.TransactionType == TransactionType.Itinerary ? ticketAttributes.Price : pricePerTicket; transactionDetail.DiscountAmount = discountAmount; transactionDetail.VisitDate = visitStartDate; transactionDetail.VisitEndDate = visitEndDate; transactionDetail.TransactionType = transactionType; transactionDetail.TicketTypeId = checkoutCommand.TransactionType == TransactionType.Itinerary ? (short)(ticketAttributes.IsAdult ? 10 : 2) : (short)(TicketType)ticketAttributes.TicketType; if (checkoutCommand.ReferralId != null) { var referral = _referralProvider.GetReferral(checkoutCommand.ReferralId, eventDetail.EventId, checkoutCommand.ModifiedBy); if (referral != null && referral.Id != 0) { transactionDetail.ReferralId = referral.Id; } } if (checkoutCommand.ChannelId == Channels.Feel && checkoutCommand.TransactionType != TransactionType.Itinerary) { _geoCurrency.UpdateTransactionUpdates(transactionDetail, checkoutCommand.TargetCurrencyCode, checkoutCommandEventTicketAttribute.CurrencyId); } if (donationAmount > 0) // Donation doesn't need the local currency as the amount itself in the local currency { transactionDetail.PricePerTicket = transactionDetail.PricePerTicket + donationAmount; } netTicketAmount += ((ticketAttributes.TotalTickets * (decimal)transactionDetail.PricePerTicket) - ((decimal)transactionDetail.DiscountAmount)); grossTicketAmount += ((ticketAttributes.TotalTickets * transactionDetail.PricePerTicket)); totalDiscountAmount += (decimal)transactionDetail.DiscountAmount; transactionDetail.MembershipId = ticketAttributes.MembershipId; transactionDetailList.Add(transactionDetail); } else { EventDetail eventDetails = _eventDetailRepository.Get(eventDetailId); Contracts.DataModels.TicketCategory ticketCategory = _ticketCategoryRepository.Get((int)ticketCategoryId); return(new CheckoutCommandResult { Id = 0, Success = false, EventName = eventDetails.Name, TicketCategoryName = ticketAttributes.TicketType == TicketType.SeasonPackage ? "Season - " + ticketCategory.Name : ticketCategory.Name, IsTransactionLimitExceed = false, IsTicketCategorySoldOut = true }); } } else { EventDetail eventDetails = _eventDetailRepository.Get(eventDetailId); Contracts.DataModels.TicketCategory ticketCategory = _ticketCategoryRepository.Get((int)ticketCategoryId); return(new CheckoutCommandResult { Id = 0, Success = false, EventName = eventDetails.Name, TicketCategoryName = ticketAttributes.TicketType == TicketType.SeasonPackage ? "Season - " + ticketCategory.Name : ticketCategory.Name, IsTransactionLimitExceed = false, IsTicketCategorySoldOut = true }); } } else { EventDetail eventDetails = _eventDetailRepository.Get(eventDetailId); Contracts.DataModels.TicketCategory ticketCategory = _ticketCategoryRepository.Get((int)ticketCategoryId); return(new CheckoutCommandResult { Id = 0, Success = false, EventName = eventDetails.Name, TicketCategoryName = ticketAttributes.TicketType == TicketType.SeasonPackage ? "Season - " + ticketCategory.Name : ticketCategory.Name, IsTransactionLimitExceed = false, IsTicketCategorySoldOut = true }); } } var intialCurrencyId = eventTicketAttributeModel.Select(s => s.CurrencyId).FirstOrDefault(); var currencyId = eventTicketAttributeModel.Select(s => s.CurrencyId).FirstOrDefault(); if (checkoutCommand.ChannelId == Channels.Feel) // Update the currencyId { if (checkoutCommand.TransactionType == TransactionType.Itinerary) { currencyId = _geoCurrency.GetCurrencyID(checkoutCommand.TransactionCurrency).Id; } else { currencyId = _geoCurrency.GetCurrencyID(checkoutCommand.TargetCurrencyCode).Id; } } /*if (checkoutCommand.ISRasv) // NAB test bed * { * var splitprice = netTicketAmount.ToString("0.00").Split("."); * var price = splitprice[0] + ".00"; * netTicketAmount = Convert.ToDecimal(netTicketAmount); * }*/ transaction.ChannelId = checkoutCommand.ChannelId; transaction.CurrencyId = currencyId; transaction.TotalTickets = Convert.ToInt16(checkoutCommand.EventTicketAttributeList.Sum(s => s.TotalTickets)); transaction.GrossTicketAmount = grossTicketAmount; transaction.NetTicketAmount = netTicketAmount; transaction.DiscountAmount = totalDiscountAmount; transaction.TransactionStatusId = TransactionStatus.UnderPayment; transaction.FirstName = user.FirstName; transaction.LastName = user.LastName; transaction.PhoneCode = user.PhoneCode; transaction.PhoneNumber = user.Email == "*****@*****.**" ? checkoutCommand.GuestUser.PhoneNumber : user.PhoneNumber; transaction.EmailId = user.Email == "*****@*****.**" ? checkoutCommand.GuestUser.PhoneNumber : user.Email; transaction.CountryName = !string.IsNullOrWhiteSpace(user.PhoneCode) ? _countryRepository.GetByPhoneCode(user.PhoneCode).Name : "India"; transaction.CreatedBy = user.AltId; transaction.CreatedUtc = DateTime.UtcNow; try { var ipDetail = _saveIPProvider.SaveIp(checkoutCommand.Ip); if (ipDetail != null && ipDetail.Id > 0) { transaction.IPDetailId = ipDetail.Id; } } catch (Exception e) { _logger.Log(Logging.Enums.LogCategory.Error, e); transaction.IPDetailId = 1; } transaction.ModifiedBy = user.AltId; transaction.AltId = Guid.NewGuid(); if (transaction.CurrencyId != 7) { transaction.OTP = checkoutCommand.OTPCode; } if (checkoutCommand.DonationAmount != null && checkoutCommand.DonationAmount != 0) { transaction.DonationAmount = checkoutCommand.DonationAmount; } FIL.Contracts.DataModels.Transaction transactionResult = _transactionRepository.Save(transaction); foreach (TransactionDetail transactionDetail in transactionDetailList) { transactionDetail.TransactionId = transactionResult.Id; var currentTransactionDetail = _transactionDetailRepository.Save(transactionDetail); FIL.Contracts.DataModels.EventTicketAttribute eventTicketAttribute = AutoMapper.Mapper.Map <FIL.Contracts.DataModels.EventTicketAttribute>(_eventTicketAttributeRepository.Get(transactionDetail.EventTicketAttributeId)); FIL.Contracts.DataModels.EventTicketDetail eventTicketDetail = AutoMapper.Mapper.Map <FIL.Contracts.DataModels.EventTicketDetail>(_eventTicketDetailRepository.Get(eventTicketAttribute.EventTicketDetailId)); if (Convert.ToInt16(transactionDetail.TotalTickets) <= eventTicketAttribute.RemainingTicketForSale) { eventTicketAttribute.RemainingTicketForSale -= transactionDetail.TotalTickets; _eventTicketAttributeRepository.Save(eventTicketAttribute); if (checkoutCommand.ChannelId == Channels.Website) { if (eventTicketDetail.InventoryTypeId == InventoryType.Seated || eventTicketDetail.InventoryTypeId == InventoryType.SeatedWithSeatSelection || eventTicketDetail.InventoryTypeId == InventoryType.NoneSeated) { List <Contracts.Models.TMS.SeatDetail> seatDetail = new List <Contracts.Models.TMS.SeatDetail>(); if (checkoutCommand.SeatDetails != null) { seatDetail = AutoMapper.Mapper.Map <List <Contracts.Models.TMS.SeatDetail> >(checkoutCommand.SeatDetails.Where(w => w.EventTicketDetailId == eventTicketDetail.Id)); } else { seatDetail = null; } var seatBlock = _seatBlockingProvider.BlockSeat(seatDetail, transactionDetail, eventTicketAttribute, eventTicketDetail, user.AltId, Channels.Website); if (!seatBlock.Success && seatBlock.IsSeatSoldOut) { return(new CheckoutCommandResult { Success = false, Id = 0, TransactionAltId = Guid.NewGuid(), IsTransactionLimitExceed = false, IsTicketCategorySoldOut = false, IsSeatSoldOut = true }); } } } } else { EventDetail eventDetails = _eventDetailRepository.Get(eventDetailId); Contracts.DataModels.TicketCategory ticketCategory = _ticketCategoryRepository.Get((int)ticketCategoryId); return(new CheckoutCommandResult { Id = 0, Success = false, EventName = eventDetails.Name, TicketCategoryName = transactionDetail.TicketTypeId == (short)TicketType.SeasonPackage ? "Season - " + ticketCategory.Name : ticketCategory.Name, IsTransactionLimitExceed = false, IsTicketCategorySoldOut = true }); } /* Save Transaction Schedule Detail */ var currentTicket = checkoutCommand.EventTicketAttributeList.Where(s => s.Id == currentTransactionDetail.EventTicketAttributeId).FirstOrDefault(); if (currentTicket.ScheduleDetailId != null && currentTicket.ScheduleDetailId != 0) { _saveTransactionScheduleDetailProvider.SaveTransactionScheduleDetail(currentTransactionDetail.Id, (long)currentTicket.ScheduleDetailId); } } try { if (checkoutCommand.ChannelId == Channels.Feel || checkoutCommand.ChannelId == Channels.Website) // If Live Online Transaction with 0.00 price { var @event = _eventRepository.Get(allED.FirstOrDefault().EventId); if (@event != null) { if (@event.MasterEventTypeId == Contracts.Enums.MasterEventType.Online && transaction.NetTicketAmount == 0) { _zoomMeetingProvider.CreateMeeting(transaction, true); isPaymentBypass = true; } else if (@event.MasterEventTypeId == Contracts.Enums.MasterEventType.Online) { StripeAccount = _eventStripeConnectAccountProvider.GetEventStripeAccount(allED.FirstOrDefault().EventId, checkoutCommand.ChannelId); } } } } catch (Exception e) { _logger.Log(Logging.Enums.LogCategory.Error, e); } try { /*Check if referred transactionId already upgraded to BSP or successfull transaction, if yes then don't allow another transaction using same referral/ transaction id*/ if (checkoutCommand.IsBSPUpgrade && checkoutCommand.ReferralId != null) { var transactions = _transactionRepository.GetAllSuccessfulTransactionByReferralId(checkoutCommand.ReferralId); if (transactions.Any()) { return(new CheckoutCommandResult { Id = 0, Success = false, IsBSPUpgraded = true }); } } } catch (Exception e) { _logger.Log(Logging.Enums.LogCategory.Error, e); } return(new CheckoutCommandResult { Id = transactionResult.Id, CartBookingModel = lstEventDetailId, Transaction = transactionResult, IsPaymentByPass = isPaymentBypass, Success = true, StripeAccount = StripeAccount, }); } catch (Exception e) { _logger.Log(Logging.Enums.LogCategory.Error, e); return(new CheckoutCommandResult { }); } }
protected override async Task <ICommandResult> Handle(ReserveTimeSlotCommand command) { ReserveTimeSlotCommandResult results = new ReserveTimeSlotCommandResult(); ReserveTimeSlotReqestModel reserveTimelotRequestModel = new ReserveTimeSlotReqestModel(); IEnumerable <long> eventTicketAttributeIds = command.EventTicketAttributeList.Select(s => s.Id).Distinct(); IEnumerable <Contracts.Models.EventTicketAttribute> eventTicketAttributes = AutoMapper.Mapper.Map <IEnumerable <Contracts.Models.EventTicketAttribute> >(_eventTicketAttributeRepository.GetByIds(eventTicketAttributeIds)); var allETD = _eventTicketDetailRepository.GetByEventTicketDetailsIds(eventTicketAttributes.Select(s => s.EventTicketDetailId).Distinct()).Distinct(); var allTC = _ticketCategoryRepository.GetByTicketCategoryIds(allETD.Select(s => s.TicketCategoryId).Distinct()).Distinct(); var allED = _eventDetailRepository.GetByIds(allETD.Select(s => s.EventDetailId).Distinct()).Distinct().FirstOrDefault(); var citySightEventDetails = _citySightSeeingEventDetailMappingRepository.GetByEventDetailId(allED.Id); var citySightSeeingTickets = _citySightSeeingTicketRepository.Get(citySightEventDetails.CitySightSeeingTicketId); var citySightSeeingTicketDetails = _citySightSeeingTicketDetailRepository.GetByTicketId(citySightSeeingTickets.TicketId); var citySightSeeingLocations = _citySightSeeingLocationRepository.Get(citySightSeeingTickets.CitySightSeeingLocationId); var locationDetail = await _googleMapApi.GetLatLongFromAddress(citySightSeeingLocations.Name); string tz = ""; DateTime fromDate = DateTime.Now;; var offset = ""; if (locationDetail.Success) { double lat = Convert.ToDouble(locationDetail.Result.lat); double lng = Convert.ToDouble(locationDetail.Result.lng); tz = TimeZoneLookup.GetTimeZone(lat, lng).Result; TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo(tz); var visitDate = command.EventTicketAttributeList[0].VisitDate; var timeSlot = command.EventTicketAttributeList[0].TimeSlot; var utcOffset = tzi.BaseUtcOffset.ToString().Split(":")[0]; var minutes = Convert.ToInt64(tzi.BaseUtcOffset.ToString().Split(":")[1]); if (utcOffset.Contains("-")) { var hours = Convert.ToInt64((tzi.BaseUtcOffset.ToString().Split(":")[0]).Split("-")[1]); visitDate = visitDate.AddHours(hours).AddMinutes(minutes); offset = utcOffset; } else { var hours = Convert.ToInt64((tzi.BaseUtcOffset.ToString().Split(":")[0])); visitDate = visitDate.AddHours(-hours).AddMinutes(-minutes); offset = "+" + utcOffset; } var formattedDateTime = visitDate.Year + "-" + visitDate.Month + "-" + visitDate.Day + "T" + timeSlot; fromDate = Convert.ToDateTime(formattedDateTime); } var duration = citySightSeeingTicketDetails.Duration; reserveTimelotRequestModel.request_type = "reserve"; TimeSlotData timeSlotData = new TimeSlotData(); timeSlotData.distributor_id = _settings.GetConfigSetting <string>(SettingKeys.Integration.CitySightSeeing.DistributorId); timeSlotData.ticket_id = citySightSeeingTickets.TicketId; timeSlotData.pickup_point_id = (citySightSeeingTicketDetails.PickupPoints != null && citySightSeeingTicketDetails.PickupPoints != "") ? citySightSeeingTicketDetails.PickupPoints : ""; DateTime endDate = DateTime.Now; List <BookingTimeSlotDetail> bookingTimeSlotDetailList = new List <BookingTimeSlotDetail>(); foreach (Contracts.Commands.Transaction.EventTicketAttribute ticketAttributes in command.EventTicketAttributeList) { BookingTimeSlotDetail bookingTimeSlotDetail = new BookingTimeSlotDetail(); var currentTA = ticketAttributes; Contracts.Models.EventTicketAttribute checkoutCommandEventTicketAttribute = eventTicketAttributes.Where(w => w.Id == ticketAttributes.Id).FirstOrDefault(); EventTicketDetail eventTicketDetail = allETD.Where(s => s.Id == checkoutCommandEventTicketAttribute.EventTicketDetailId).FirstOrDefault(); var ticketCategoryId = allTC.Where(s => s.Id == eventTicketDetail.TicketCategoryId).FirstOrDefault(); bookingTimeSlotDetail.count = ticketAttributes.TotalTickets; var formattedTicketCat = ticketCategoryId.Name.Split("("); bookingTimeSlotDetail.ticket_type = formattedTicketCat[0].ToUpper(); bookingTimeSlotDetail.extra_options = null; bookingTimeSlotDetailList.Add(bookingTimeSlotDetail); } if (duration.Contains("day")) { string[] day = duration.Split("day"); endDate = fromDate.AddDays(Convert.ToDouble(day[0])); } if (duration.Contains("hour")) { string[] hour = duration.Split("hour"); endDate = fromDate.AddHours(Convert.ToDouble(hour[0])); } var fromDate_with_time_slot = Convert.ToDateTime(fromDate.ToString() + offset); var endDate_with_time_slot = Convert.ToDateTime(endDate.ToString() + offset); timeSlotData.from_date_time = fromDate_with_time_slot; timeSlotData.to_date_time = endDate_with_time_slot; timeSlotData.booking_details = bookingTimeSlotDetailList; reserveTimelotRequestModel.data = timeSlotData; reserveTimelotRequestModel.data.distributor_reference = RandomDigits(10); var response = Mapper <TimeSlotResponseModel> .MapFromJson(await ReserveBooking(reserveTimelotRequestModel)); if (response != null && response.data.booking_status == "Reserved") { results.Success = true; results.FromTime = fromDate.ToString() + offset; results.EndTime = endDate.ToString() + offset; results.Reservation_reference = response.data.reservation_reference; results.Reservation_valid_until = response.data.reservation_valid_until; results.Distributor_reference = response.data.distributor_reference; results.TicketId = citySightSeeingTicketDetails.TicketId; results.TimeSlot = command.EventTicketAttributeList[0].TimeSlot; } else { results.Success = false; } return(results); }