コード例 #1
0
        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
                {
                });
            }
        }
コード例 #2
0
        protected override async Task Handle(RegisterUserCommand command)
        {
            IPDetail ipDetail = new FIL.Contracts.DataModels.IPDetail();

            var country = _countryRepository.GetByAltId(new Guid(command.PhoneCode.Split("~")[1]));
            var user    = new FIL.Contracts.DataModels.User
            {
                AltId          = Guid.NewGuid(),
                Email          = command.Email,
                Password       = command.PasswordHash,
                RolesId        = command.ChannelId == Channels.Feel ? 11 : 2, // TODO: XXX: Need a default
                CreatedBy      = command.ModifiedBy,
                CreatedUtc     = DateTime.UtcNow,
                UserName       = command.UserName,
                FirstName      = command.FirstName,
                LastName       = command.LastName,
                PhoneCode      = command.PhoneCode.Split("~")[0],
                PhoneNumber    = command.PhoneNumber,
                ChannelId      = command.ChannelId,
                SignUpMethodId = command.SignUpMethodId,
                IsEnabled      = true,
                IsRASVMailOPT  = command.IsMailOpt,
                CountryId      = country.Id
            };

            user.IPDetailId = user.IPDetailId == 0 ? null : user.IPDetailId;
            var userDetails = _userRepository.Save(user);

            if (command.ChannelId == Channels.Feel)
            {
                var feelUserAdditional = new FeelUserAdditionalDetail
                {
                    UserId         = Convert.ToInt32(userDetails.Id),
                    OptedForMailer = Convert.ToBoolean(command.IsMailOpt),
                    SocialLoginId  = null,
                    SignUpMethodId = Convert.ToInt32(command.SignUpMethodId),
                    IsEnabled      = true
                };
                _feelUserAdditionalDetailRepository.Save(feelUserAdditional);
            }
            try
            {
                if (command.ReferralId != null)
                {
                    var referral = _referralRepository.GetByAltId(Guid.Parse(command.ReferralId));
                    if (referral != null)
                    {
                        userDetails.ReferralId = referral.Id;
                    }
                }
                ipDetail = _saveIPProvider.SaveIp(command.Ip);
                if (ipDetail != null)
                {
                    userDetails.IPDetailId = ipDetail.Id;
                    _userRepository.Save(userDetails);
                }
            }
            catch
            {
                ipDetail = null;
            }
            if (command.SiteId == Site.RASVSite)
            {
                await _mediator.Publish(new Events.Event.HubSpot.VisitorInfoEvent(user));
            }
        }
コード例 #3
0
        protected override async Task <ICommandResult> Handle(GuideDetailsCommand command)
        {
            GuideDetailsCommandResult guideDetailsCommandResult = new GuideDetailsCommandResult();

            try
            {
                var user    = _UserRepository.GetByEmailAndChannel(command.EmailId, Contracts.Enums.Channels.Feel, Contracts.Enums.SignUpMethods.None);
                var country = _countryRepository.GetByAltId(new Guid(command.TaxCountry));
                if (user == null)
                {
                    user = new FIL.Contracts.DataModels.User
                    {
                        AltId             = Guid.NewGuid(),
                        Email             = command.EmailId,
                        Password          = Guid.NewGuid().ToString(),
                        RolesId           = 20,// new guideID in Guid
                        CreatedBy         = command.ModifiedBy,
                        CreatedUtc        = DateTime.UtcNow,
                        UserName          = command.EmailId,
                        FirstName         = command.FirstName,
                        LastName          = command.LastName,
                        PhoneCode         = command.CountryCode,
                        PhoneNumber       = command.MobileNo,
                        ChannelId         = Contracts.Enums.Channels.Feel,
                        SignUpMethodId    = Contracts.Enums.SignUpMethods.None,
                        IsEnabled         = true,
                        LockOutEnabled    = false,
                        AccessFailedCount = 0,
                        LoginCount        = 0,
                        PhoneConfirmed    = true,
                        IsActivated       = true
                    };
                    user = _UserRepository.Save(user);
                }

                var zipCode = _zipcodeRepository.GetByZipcode(command.ZipCode);
                if (zipCode == null)
                {
                    zipCode = new Zipcode
                    {
                        AltId      = Guid.NewGuid(),
                        CityId     = command.CityId,
                        CreatedBy  = command.ModifiedBy,
                        CreatedUtc = DateTime.UtcNow,
                        IsEnabled  = true,
                        Postalcode = command.ZipCode,
                        ModifiedBy = command.ModifiedBy
                    };
                    zipCode = _zipcodeRepository.Save(zipCode);
                }

                var userAddress = _userAddressDetailRepository.GetByUserId(user.Id).FirstOrDefault();
                UserAddressDetail userAddressDetail = new UserAddressDetail
                {
                    Id            = userAddress != null ? userAddress.Id : 0,
                    AddressLine1  = command.AddressLineOne,
                    AddressLine2  = command.AddressLineTwo,
                    AddressTypeId = Contracts.Enums.AddressTypes.Billing,
                    AltId         = Guid.NewGuid(),
                    FirstName     = user.FirstName,
                    LastName      = user.LastName,
                    IsEnabled     = true,
                    CityId        = command.CityId,
                    PhoneCode     = user.PhoneCode,
                    UserId        = user.Id,
                    IsDefault     = true,
                    PhoneNumber   = user.PhoneNumber,
                    Zipcode       = zipCode.Id,
                    CreatedBy     = command.ModifiedBy,
                    CreatedUtc    = DateTime.UtcNow
                };
                if (userAddress != null)
                {
                    userAddress.UpdatedUtc = DateTime.UtcNow;
                    userAddress.ModifiedBy = command.ModifiedBy;
                    userAddress.UpdatedBy  = command.ModifiedBy;
                }
                userAddressDetail = _userAddressDetailRepository.Save(userAddressDetail);

                var guideDetails = _GuideDetailsRepository.GetByUserId(user.Id);
                Redemption_GuideDetails GuideDetails = new Redemption_GuideDetails
                {
                    ApproveStatusId = Contracts.Enums.ApproveStatus.Pending,
                    Id                  = guideDetails != null ? guideDetails.Id : 0,
                    IsEnabled           = false,
                    UserAddressDetailId = userAddressDetail.Id,
                    LanguageId          = String.Join(",", command.LanguageIds.ToArray()),
                    UserId              = user.Id,
                    CreatedBy           = command.ModifiedBy,
                    ModifiedBy          = command.ModifiedBy,
                    CreatedUtc          = DateTime.UtcNow
                };
                if (guideDetails != null)
                {
                    guideDetails.UpdatedUtc = DateTime.UtcNow;
                    guideDetails.ModifiedBy = command.ModifiedBy;
                    guideDetails.UpdatedBy  = command.ModifiedBy;
                }
                GuideDetails = _GuideDetailsRepository.Save(GuideDetails);
                foreach (int eventId in command.EventIDs)
                {
                    Redemption_GuidePlaceMappings GuidePlaceMappings = new Redemption_GuidePlaceMappings
                    {
                        ApproveStatusId = 1,
                        EventId         = Convert.ToInt64(eventId),
                        GuideId         = GuideDetails.Id,
                        IsEnabled       = true,
                        CreatedBy       = command.ModifiedBy,
                        ModifiedBy      = command.ModifiedBy,
                        CreatedUtc      = DateTime.UtcNow
                    };
                    GuidePlaceMappings = _GuidePlaceMappings.Save(GuidePlaceMappings);
                }

                var guideServices = _GuideServicesRepository.GetAllByGuideId(GuideDetails.Id);
                if (guideServices != null)
                {
                    foreach (Contracts.DataModels.Redemption.Redemption_GuideServices service in guideServices)
                    {
                        _GuideServicesRepository.Delete(service);
                    }
                }

                foreach (Contracts.DataModels.Redemption.Services service in command.Services)
                {
                    var currentService = service;
                    currentService.Id         = 0;
                    currentService.IsEnabled  = true;
                    currentService.CreatedBy  = command.ModifiedBy;
                    currentService.CreatedUtc = DateTime.UtcNow;
                    currentService            = _ServicesRepository.Save(service);
                    Redemption_GuideServices GuideServices = new Redemption_GuideServices
                    {
                        GuideId    = GuideDetails.Id,
                        IsEnabled  = true,
                        Notes      = command.Notes,
                        ServiceId  = currentService.Id,
                        CreatedBy  = command.ModifiedBy,
                        ModifiedBy = command.ModifiedBy,
                        CreatedUtc = DateTime.UtcNow
                    };
                    GuideServices = _GuideServicesRepository.Save(GuideServices);
                }

                MasterFinanceDetails masterFinanceDetails = new MasterFinanceDetails
                {
                    AccountNumber     = command.AccountNumber,
                    AccountTypeId     = command.AccountType,
                    BankAccountTypeId = command.BankAccountType,
                    BankName          = command.BankName,
                    BranchCode        = command.SwiftCode,
                    CountryId         = country.Id,
                    CurrenyId         = command.CurrencyId,
                    IsEnabled         = true,
                    StateId           = command.State,
                    TaxId             = command.TaxNumber,
                    RoutingNumber     = command.RoutingNumber,
                    CreatedBy         = command.ModifiedBy,
                    ModifiedBy        = command.ModifiedBy,
                    CreatedUtc        = DateTime.UtcNow
                };
                masterFinanceDetails = _MasterFinanceDetailsRepository.Save(masterFinanceDetails);

                var AllGuideFinanceMappings = _GuideFinanceMappingsRepository.GetAllByGuideId(GuideDetails.Id);
                foreach (Contracts.DataModels.Redemption.Redemption_GuideFinanceMappings guideFinanceMappings in AllGuideFinanceMappings)
                {
                    _GuideFinanceMappingsRepository.Delete(guideFinanceMappings);
                }
                Redemption_GuideFinanceMappings GuideFinanceMappings = new Redemption_GuideFinanceMappings
                {
                    GuideId               = GuideDetails.Id,
                    IsEnabled             = true,
                    CreatedBy             = command.ModifiedBy,
                    CreatedUtc            = DateTime.UtcNow,
                    MasterFinanceDetailId = masterFinanceDetails.Id
                };
                GuideFinanceMappings = _GuideFinanceMappingsRepository.Save(GuideFinanceMappings);

                var guideDocuments = _guideDocumentMappingsRepository.GetAllByGuideId(GuideDetails.Id);
                foreach (Contracts.DataModels.Redemption.Redemption_GuideDocumentMappings guideDocumentMappings in guideDocuments)
                {
                    _guideDocumentMappingsRepository.Delete(guideDocumentMappings);
                }
                var guideDocument = new Redemption_GuideDocumentMappings
                {
                    GuideId          = GuideDetails.Id,
                    IsEnabled        = true,
                    CreatedBy        = command.ModifiedBy,
                    ModifiedBy       = command.ModifiedBy,
                    CreatedUtc       = DateTime.UtcNow,
                    DocumentID       = command.Document,
                    DocumentSouceURL = "",
                };
                _guideDocumentMappingsRepository.Save(guideDocument);

                return(new GuideDetailsCommandResult
                {
                    UserId = user.Id,
                    Success = true
                });
            }
            catch (Exception ex)
            {
                _logger.Log(Logging.Enums.LogCategory.Error, ex);
                return(new GuideDetailsCommandResult
                {
                    Success = false
                });
            }
        }