Ejemplo n.º 1
0
        protected override async Task <ICommandResult> Handle(DeleteTicketCommand command)
        {
            try
            {
                var eventTicketDetail               = _eventTicketDetailRepository.GetByAltId(command.ETDAltId);
                var etdTicketCategoryMapping        = _eventTicketDetailTicketCategoryTypeMappingRepository.GeAlltByEventTicketDetail(eventTicketDetail.Id);
                var eventTicketAttribute            = _eventTicketAttributeRepository.GetByEventTicketDetailId(eventTicketDetail.Id);
                var ticketFeelDetails               = _ticketFeeDetailRepository.GetAllByEventTicketAttributeId(eventTicketAttribute.Id);
                var eventTicketDetailDiscountDetail = _eventTicketDiscountDetailRepository.GetAllByEventTicketAttributeId(eventTicketAttribute.Id);
                var transactionDetails              = _transactionDetailRepository.GetByEventTicketAttributeId(eventTicketAttribute.Id);

                if (!transactionDetails.Any())
                {
                    foreach (var etdTicketCat in etdTicketCategoryMapping)
                    {
                        _eventTicketDetailTicketCategoryTypeMappingRepository.Delete(etdTicketCat);
                    }

                    foreach (var ticketFeeDetail in ticketFeelDetails)
                    {
                        _ticketFeeDetailRepository.Delete(ticketFeeDetail);
                    }

                    foreach (var etdDiscount in eventTicketDetailDiscountDetail)
                    {
                        _eventTicketDiscountDetailRepository.Delete(etdDiscount);
                    }

                    if (eventTicketAttribute != null)
                    {
                        _eventTicketAttributeRepository.Delete(eventTicketAttribute);
                    }

                    if (eventTicketDetail != null)
                    {
                        _eventTicketDetailRepository.Delete(eventTicketDetail);
                    }

                    var eventStepDetails = _stepProvider.SaveEventStepDetails(command.EventId, command.CurrentStep, command.TicketLength == 1 ? false : true, command.ModifiedBy);
                    return(new DeleteTicketCommandResult
                    {
                        Success = true,
                        CompletedStep = eventStepDetails.CompletedStep,
                        CurrentStep = eventStepDetails.CurrentStep,
                    });
                }
                else
                {
                    return(new DeleteTicketCommandResult {
                        IsTicketSold = true
                    });
                }
            }
            catch (Exception e)
            {
                _logger.Log(LogCategory.Error, e);
                return(new DeleteTicketCommandResult {
                });
            }
        }