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 }); } }
protected override async Task Handle(SaveEventScheduleCommand command) { foreach (var eventDetail in command.SubEventList) { var eventDetailData = new EventDetail(); if (eventDetail.id == 0) // check for create or edit insert if 0 { eventDetailData = new FIL.Contracts.DataModels.EventDetail { Name = eventDetail.name, EventId = eventDetail.eventId, AltId = Guid.NewGuid(), VenueId = eventDetail.venueId, MetaDetails = null, Description = eventDetail.Description, GroupId = 1, StartDateTime = DateTime.Parse(eventDetail.startDateTime), EndDateTime = DateTime.Parse(eventDetail.endDateTime), IsEnabled = false, CreatedUtc = DateTime.UtcNow, ModifiedBy = command.userAltId }; _eventDetailRepository.Save(eventDetailData); } else // update sub event { eventDetailData = _eventDetailRepository.Get(eventDetail.id); eventDetailData.Name = eventDetail.name; eventDetailData.EventId = eventDetail.eventId; eventDetailData.VenueId = eventDetail.venueId; eventDetailData.Description = eventDetail.Description; eventDetailData.StartDateTime = DateTime.Parse(eventDetail.startDateTime); eventDetailData.EndDateTime = DateTime.Parse(eventDetail.endDateTime); eventDetailData.ModifiedBy = command.userAltId; _eventDetailRepository.Save(eventDetailData); } //check for existing delivery type details var deliveryTypeData = _eventDeliveryTypeDetailRepository.GetByEventDetailId(eventDetailData.Id); if (deliveryTypeData.Count() > 0) { foreach (var newDeliveryType in deliveryTypeData) { //update existing delivery type details if (Convert.ToInt16(newDeliveryType.DeliveryTypeId) != command.DeliveryValue) { var deliveryValue = _eventDeliveryTypeDetailRepository.Get(newDeliveryType.Id); deliveryValue.DeliveryTypeId = (DeliveryTypes)command.DeliveryValue; _eventDeliveryTypeDetailRepository.Save(deliveryValue); } } } else // insert new deliveryType { var deliveryType = new FIL.Contracts.DataModels.EventDeliveryTypeDetail { EventDetailId = eventDetailData.Id, DeliveryTypeId = (DeliveryTypes)command.DeliveryValue, Notes = "<p><strong>Delivery<br /></strong>Ticket packages are shipped to your preferred address (signature upon receival required), or are arranged for a secure pickup location at or near the circuit.</p>", EndDate = DateTime.UtcNow, IsEnabled = true, CreatedUtc = DateTime.UtcNow, ModifiedBy = command.userAltId, }; _eventDeliveryTypeDetailRepository.Save(deliveryType); } var matchAttributeData = _matchAttributeRepository.GetByEventDetailId(eventDetail.id); if (matchAttributeData.Count() > 0) { foreach (var oldMatchAttribute in matchAttributeData) { foreach (var newMatchAttribute in eventDetail.matches) { if (oldMatchAttribute.Id == newMatchAttribute.id) { var updatedMatchAttribute = _matchAttributeRepository.Get(newMatchAttribute.id); updatedMatchAttribute.TeamA = newMatchAttribute.teamA; updatedMatchAttribute.TeamB = newMatchAttribute.teamB; updatedMatchAttribute.MatchNo = newMatchAttribute.matchNo; updatedMatchAttribute.MatchDay = newMatchAttribute.matchDay; updatedMatchAttribute.MatchStartTime = DateTime.Parse(newMatchAttribute.startDateTime); _matchAttributeRepository.Save(updatedMatchAttribute); } } } } else { //check for not null if (eventDetail.matches.Count > 0) { foreach (var match in eventDetail.matches) { //check for if team is exits if not insert new var teamA = match.teamA != 0 ? _teamRepository.Get(match.teamA) : _teamRepository.Save( new Team { Name = match.teamAName, AltId = Guid.NewGuid(), IsEnabled = true, Description = "", CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId, UpdatedBy = command.userAltId } ); var teamB = match.teamB != 0 ? _teamRepository.Get(match.teamB) : _teamRepository.Save( new Team { Name = match.teamBName, AltId = Guid.NewGuid(), IsEnabled = true, Description = "", CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId, UpdatedBy = command.userAltId } ); var matchAttribute = new FIL.Contracts.DataModels.MatchAttribute { EventDetailId = eventDetailData.Id, TeamA = teamA.Id, TeamB = teamB.Id, MatchNo = match.matchNo, MatchDay = match.matchDay, IsEnabled = true, MatchStartTime = DateTime.Parse(match.startDateTime), CreatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId, ModifiedBy = command.userAltId }; _matchAttributeRepository.Save(matchAttribute); } } } var TicketDetailData = _eventTicketDetailRepository.GetByEventDetailId(eventDetail.id); if (TicketDetailData.Count() > 0) { foreach (var oldTicketCategory in TicketDetailData) { var newEventTicketDetail = eventDetail.ticketCategories.Where(s => s.id == oldTicketCategory.Id).FirstOrDefault(); if (newEventTicketDetail != null) { //update existing eventTicketDetail var updatedEventTicketDetail = _eventTicketDetailRepository.Get(newEventTicketDetail.id); updatedEventTicketDetail.TicketCategoryId = newEventTicketDetail.ticketCategoryId; _eventTicketDetailRepository.Save(updatedEventTicketDetail); //update event ticket attributes var updatedTicketAttibutesData = _eventTicketAttributeRepository.GetByEventTicketDetailId(updatedEventTicketDetail.Id); updatedTicketAttibutesData.AvailableTicketForSale = newEventTicketDetail.capacity; updatedTicketAttibutesData.RemainingTicketForSale = newEventTicketDetail.capacity; updatedTicketAttibutesData.Price = newEventTicketDetail.price; updatedTicketAttibutesData.LocalPrice = newEventTicketDetail.price; updatedTicketAttibutesData.CurrencyId = newEventTicketDetail.currencyId; updatedTicketAttibutesData.LocalCurrencyId = newEventTicketDetail.currencyId; _eventTicketAttributeRepository.Save(updatedTicketAttibutesData); //get exisiting ticket fee details var oldticketFeeDetailData = _ticketFeeDetailRepository.GetAllByEventTicketAttributeId(updatedTicketAttibutesData.Id).ToList(); foreach (var feeType in command.FeeTypes) { if (feeType.id == 0) { var ticketFeeDetailData = new FIL.Contracts.DataModels.TicketFeeDetail { EventTicketAttributeId = updatedTicketAttibutesData.Id, FeeId = (Int16)feeType.feeId, DisplayName = feeType.displayName, ValueTypeId = (Int16)feeType.valueTypeId, Value = feeType.value, IsEnabled = true, CreatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId }; _ticketFeeDetailRepository.Save(ticketFeeDetailData); } } if (oldticketFeeDetailData.Count() > 0) { foreach (var oldTicketFeeDetail in oldticketFeeDetailData) { var newTicketFeeDetail = command.FeeTypes.Where(s => s.id == oldTicketFeeDetail.Id).FirstOrDefault(); if (newTicketFeeDetail != null) { var updatedTicketFeeDetail = _ticketFeeDetailRepository.Get(oldTicketFeeDetail.Id); updatedTicketFeeDetail.FeeId = Convert.ToInt16(newTicketFeeDetail.feeId); updatedTicketFeeDetail.ValueTypeId = Convert.ToInt16(newTicketFeeDetail.valueTypeId); updatedTicketFeeDetail.Value = newTicketFeeDetail.value; _ticketFeeDetailRepository.Save(updatedTicketFeeDetail); } else { var updatedTicketFeeDetail = _ticketFeeDetailRepository.Get(oldTicketFeeDetail.Id); updatedTicketFeeDetail.IsEnabled = false; _ticketFeeDetailRepository.Save(updatedTicketFeeDetail); } } } } else { var updatedEventTicketDetail = _eventTicketDetailRepository.Get(oldTicketCategory.Id); updatedEventTicketDetail.IsEnabled = false; _eventTicketDetailRepository.Save(updatedEventTicketDetail); } } } if (eventDetail.ticketCategories.Count > 0) { foreach (var eventTicketDetail in eventDetail.ticketCategories) { if (eventTicketDetail.id == 0) // insert new category { //check for if ticket category is exits if not insert new var ticketCategory = eventTicketDetail.ticketCategoryId != 0 ? _ticketCategoryRepository.Get(eventTicketDetail.ticketCategoryId) : _ticketCategoryRepository.Save( new TicketCategory { Name = eventTicketDetail.ticketCategoryName, IsEnabled = true, CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId, UpdatedBy = command.userAltId } ); //insert new ticket detail data var eventTicketDetailData = new FIL.Contracts.DataModels.EventTicketDetail { EventDetailId = eventDetailData.Id, TicketCategoryId = ticketCategory.Id, IsEnabled = true, CreatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId, ModifiedBy = command.userAltId, IsBOEnabled = false }; _eventTicketDetailRepository.Save(eventTicketDetailData); //save event ticket attributes var eventTicketAttibutesData = new FIL.Contracts.DataModels.EventTicketAttribute { EventTicketDetailId = eventTicketDetailData.Id, CurrencyId = eventTicketDetail.currencyId, TicketTypeId = FIL.Contracts.Enums.TicketType.Adult, ChannelId = FIL.Contracts.Enums.Channels.Website, AvailableTicketForSale = eventTicketDetail.capacity, RemainingTicketForSale = eventTicketDetail.capacity, Price = eventTicketDetail.price, LocalPrice = eventTicketDetail.price, CreatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId, IsEnabled = true, IsEMIApplicable = false, IsInternationalCardAllowed = false, IsSeatSelection = false, ViewFromStand = "", TicketCategoryDescription = "", LocalCurrencyId = eventTicketDetail.currencyId, SalesStartDateTime = DateTime.UtcNow, SalesEndDatetime = DateTime.UtcNow, }; _eventTicketAttributeRepository.Save(eventTicketAttibutesData); if (command.FeeTypes.Count > 0) { foreach (var feeType in command.FeeTypes) { //save ticket fee details var ticketFeeDetailData = new FIL.Contracts.DataModels.TicketFeeDetail { EventTicketAttributeId = eventTicketAttibutesData.Id, FeeId = (Int16)feeType.feeId, DisplayName = feeType.displayName, ValueTypeId = (Int16)feeType.valueTypeId, Value = feeType.value, IsEnabled = true, CreatedUtc = DateTime.UtcNow, CreatedBy = command.userAltId }; _ticketFeeDetailRepository.Save(ticketFeeDetailData); } } } } } } }