public TicketReservationPresentation ReserveTicketsFor(string EventId, int NoOfTkts) { TicketReservationPresentation reservation = new TicketReservationPresentation(); ReserveTicketResponse response = new ReserveTicketResponse(); ReserveTicketRequest request = new ReserveTicketRequest(); request.EventId = EventId; request.TicketQuantity = NoOfTkts; response = _ticketService.ReserveTicket(request); if (response.Success) { reservation.TicketWasSuccessfullyReserved = true; reservation.ReservationId = response.ReservationNumber; reservation.ExpiryDate = response.ExpirationDate; reservation.EventId = response.EventId; reservation.Description = String.Format("{0} ticket(s) reserved for {1}.<br/><small>This reservation will expire on {2} at {3}.</small>", response.NoOfTickets, response.EventName, response.ExpirationDate.ToLongDateString(), response.ExpirationDate.ToLongTimeString()); } else { reservation.TicketWasSuccessfullyReserved = false; reservation.Description = response.Message; } return(reservation); }
/// <summary> /// 订票 /// </summary> /// <param name="reserveTicketRequest">订票请求</param> /// <returns></returns> public ReserveTicketResponse ReserveTicket(ReserveTicketRequest reserveTicketRequest) { ReserveTicketResponse response = new ReserveTicketResponse(); try { //1 检索与请求的赛事相关的赛事 Event my_Event = _eventRepository.FindBy(new Guid(reserveTicketRequest.EventId)); TicketReservation reservation; //2 判断是否有传入的请求中所要求的预定票数 if (my_Event.CanReserveTicket(reserveTicketRequest.TicketQuantity)) { //2.1 预定指定数量的门票 reservation = my_Event.ReserveTicket(reserveTicketRequest.TicketQuantity); _eventRepository.Save(my_Event); //获取预定门票响应 response = reservation.ConvertToReserveTicketResponse(); response.Success = true; } else { response.Success = false; response.Message = String.Format("There are {0} ticket(s) available.", my_Event.AvailableAllocation()); } } catch (Exception ex) { // Shield Exceptions response.Message = ErrorLog.GenerateErrorRefMessageAndLog(ex); response.Success = false; } return(response); }
public ReserveTicketResponse ReserveTicket(ReserveTicketRequest reserveTicketRequest) { ReserveTicketResponse response = new ReserveTicketResponse(); try { Event Event = _eventRepository.FindBy(new Guid(reserveTicketRequest.EventId)); TicketReservation reservation; if (Event.CanReserveTicket(reserveTicketRequest.TicketQuantity)) { reservation = Event.ReserveTicket(reserveTicketRequest.TicketQuantity); _eventRepository.Save(Event); response = reservation.ConvertToReserveTicketResponse(); response.Success = true; } else { response.Success = false; response.Message = String.Format("There are {0} ticket(s) available.", Event.AvailableAllocation()); } } catch (Exception ex) { // Shield Exceptions response.Message = ErrorLog.GenerateErrorRefMessageAndLog(ex); response.Success = false; } return(response); }
public TicketReservationPresentation ReserveTicketsFor(string EventId, int NoOfTkts) { TicketReservationPresentation reservation = new TicketReservationPresentation(); ReserveTicketRequest request = new ReserveTicketRequest(); request.EventId = EventId; request.TicketQuantity = NoOfTkts; ReserveTicketResponse response = _ticketService.ReserveTicket(request); if (response.Success) { reservation.TicketWasSuccessfullyReserved = true; reservation.ReservationId = response.ReservationNumber; reservation.ExpiryDate = response.ExpirationDate; reservation.EventId = response.EventId; reservation.Description = string.Format("{0} ticket(s) reserved for {1}.<br/>" + "<small>This reservation will expire on {2} at {3}.</small>", response.NoOfTickets, response.EventName, response.ExpirationDate.ToLongDateString(), response.ExpirationDate.ToShortDateString() ); } else { reservation.TicketWasSuccessfullyReserved = false; reservation.Description = response.Message; } return reservation; }
public ReserveTicketResponse ReserveTicket(ReserveTicketRequest reserveTicketRequest) { return(base.Channel.ReserveTicket(reserveTicketRequest)); }
public async Task <IActionResult> ReserveTicket(string address, ReserveTicketRequest reserveTicketRequest) { // validate address if (!AddressParser.IsValidAddress(address, _network)) { return(StatusCode(StatusCodes.Status400BadRequest, $"Invalid address {address}")); } // check contract exists var numericAddress = address.ToUint160(_network); if (!_stateRepositoryRoot.IsExist(numericAddress)) { return(StatusCode(StatusCodes.Status404NotFound, $"No smart contract found at address {address}")); } // check for state of ticket var ticket = FindTicket(numericAddress, reserveTicketRequest.Seat); if (ticket.Equals(default(Ticket))) { return(StatusCode(StatusCodes.Status400BadRequest, $"Invalid seat {reserveTicketRequest.Seat.ToDisplayString()}")); } // check contract state if (!HasOpenSale(numericAddress)) { return(StatusCode(StatusCodes.Status409Conflict, "Sale is not currently open")); } if (ticket.Address != Address.Zero) { return(StatusCode(StatusCodes.Status400BadRequest, $"Ticket for seat {reserveTicketRequest.Seat.ToDisplayString()} not available to purchase")); } var requiresIdentityVerification = RetrieveIdentityVerificationPolicy(numericAddress); if (requiresIdentityVerification && string.IsNullOrWhiteSpace(reserveTicketRequest.CustomerName)) { return(StatusCode(StatusCodes.Status400BadRequest, $"Customer name is required")); } // check connections if (!_connectionManager.ConnectedPeers.Any()) { _logger.LogTrace("No connected peers"); return(StatusCode(StatusCodes.Status403Forbidden, "Can't send transaction as the node requires at least one connection.")); } var seatBytes = _serializer.Serialize(reserveTicketRequest.Seat); var seatParameter = $"{Serialization.TypeIdentifiers[typeof(byte[])]}#{Serialization.ByteArrayToHex(seatBytes)}"; var secret = _stringGenerator.CreateUniqueString(15); CbcResult secretCipherResult; using (var cipherProvider = _cipherFactory.CreateCbcProvider()) { secretCipherResult = cipherProvider.Encrypt(secret); } var secretParameter = $"{Serialization.TypeIdentifiers[typeof(byte[])]}#{Serialization.ByteArrayToHex(secretCipherResult.Cipher)}"; CbcResult customerNameCipherResult = null; string customerNameParameter = null; if (requiresIdentityVerification) { using (var cipherProvider = _cipherFactory.CreateCbcProvider()) { customerNameCipherResult = cipherProvider.Encrypt(reserveTicketRequest.CustomerName); } customerNameParameter = $"{Serialization.TypeIdentifiers[typeof(byte[])]}#{Serialization.ByteArrayToHex(customerNameCipherResult.Cipher)}"; } // build transaction var parameterList = new List <string> { seatParameter, secretParameter }; if (customerNameParameter != null) { parameterList.Add(customerNameParameter); } var callTxResponse = _smartContractTransactionService.BuildCallTx(new BuildCallContractTransactionRequest { AccountName = reserveTicketRequest.AccountName, Amount = StratoshisToStrats(ticket.Price), ContractAddress = address, FeeAmount = "0", GasLimit = SmartContractFormatLogic.GasLimitMaximum, GasPrice = reserveTicketRequest.GasPrice, MethodName = nameof(TicketContract.Reserve), Outpoints = reserveTicketRequest.Outpoints, Parameters = parameterList.ToArray(), Password = reserveTicketRequest.Password, Sender = reserveTicketRequest.Sender, WalletName = reserveTicketRequest.WalletName, }); if (!callTxResponse.Success) { return(StatusCode(StatusCodes.Status400BadRequest, callTxResponse.Message)); } // broadcast transaction var transaction = _network.CreateTransaction(callTxResponse.Hex); await _broadcasterManager.BroadcastTransactionAsync(transaction); var transactionBroadCastEntry = _broadcasterManager.GetTransaction(transaction.GetHash()); // check if transaction was added to mempool if (transactionBroadCastEntry?.State == Stratis.Bitcoin.Features.Wallet.Broadcasting.State.CantBroadcast) { _logger.LogError("Exception occurred: {0}", transactionBroadCastEntry.ErrorMessage); return(StatusCode(StatusCodes.Status500InternalServerError, transactionBroadCastEntry.ErrorMessage)); } var transactionHash = transaction.GetHash().ToString(); var cbcSecretValues = new CbcSecret { Plaintext = secret, Key = secretCipherResult.Key, IV = secretCipherResult.IV }; var cbcCustomerValues = requiresIdentityVerification ? new CbcValues { Key = customerNameCipherResult.Key, IV = customerNameCipherResult.IV } : null; return(Created( $"/api/smartContracts/receipt?txHash={transactionHash}", new TicketReservationDetailsResponse { TransactionHash = transactionHash, Secret = cbcSecretValues, CustomerName = cbcCustomerValues })); }