Esempio n. 1
0
        public List <Item> GetBonusKickerAvailableReward(int custId)
        {
            var customerEx =
                Exigo.GetCustomerExtendedDetails(custId,
                                                 (int)CustomerExtendedGroup.BonusKicker)
                .Where(x => x.Field5 != "1");
            var rewardItems = customerEx.Select(custEx => Exigo.GetItem(custEx.Field3)).ToList();

            return(rewardItems);
        }
Esempio n. 2
0
        //This will get the Customer Extended Reward Configuration for a given customer and phase
        public EBRewardDiscount GetCustomerEbRewardDiscount(int customerId, int phase)
        {
            int _phase   = 0;
            var details  = Exigo.GetCustomerExtendedDetails(customerId, (int)CustomerExtendedGroup.EbRewards /* EB Rewards Extended Group ID */);
            var ebReward = (from d in details
                            where true == int.TryParse(d.Field1, out _phase) //Field1 is the Phase Number
                            select new EBRewardDiscount()
            {
                PhaseNumber = int.Parse(d.Field1),
                CompletionDate = DateTime.Parse(d.Field2)
            }).FirstOrDefault(i => i.PhaseNumber.Equals(phase));

            return(ebReward);
        }
Esempio n. 3
0
        //This will get all the Customer Extended Reward Configuration for a given customer
        public IList <EBRewardDiscount> GetCustomerEbRewardDiscounts(int customerId)
        {
            var details = Exigo.GetCustomerExtendedDetails(customerId, (int)CustomerExtendedGroup.EbRewards /* EB Rewards Extended Group ID */);

            var ebReward = (from d in details
                            select new EBRewardDiscount()
            {
                CustomerExtendedDetailId = d.CustomerExtendedDetailID,
                PhaseNumber = int.Parse(d.Field1),
                CompletionDate = DateTime.Parse(d.Field2)
            }
                            );

            return(ebReward.ToList());
        }
Esempio n. 4
0
        public HostSpecialDiscount GetHostSpecialReward(int eventId)
        {
            var details = Exigo.GetCustomerExtendedDetails(eventId, (int)CustomerExtendedGroup.PartyDetails);

            var hostSpecialReward = (from d in details
                                     select new HostSpecialDiscount
            {
                CustomerExtendedDetailId = d.CustomerExtendedDetailID,
                ItemCode = d.Field8 == string.Empty ? string.Empty : d.Field8,
                DiscountAmount = string.IsNullOrEmpty(d.Field9) ? 0M : decimal.Parse(d.Field9),
                HasBeenRedeemed = !string.IsNullOrEmpty(d.Field10) && d.Field10 != "FALSE" && int.Parse(d.Field10) == 1,
                // d.Field10 != string.Empty && Convert.ToBoolean(d.Field10)),
                SalesThreshold = string.IsNullOrEmpty(d.Field11) ? 0M : decimal.Parse(d.Field11),
            }).FirstOrDefault();

            return(hostSpecialReward);
        }
Esempio n. 5
0
        public void CreateQualifiedRecruitReward(int customerId)
        {
            var api = Exigo.WebService();

            var lst = GetQualifiedRecruits(customerId);

            if (lst.Count <= 0)
            {
                return;
            }
            var previousAwardedRecruit = Exigo.GetCustomerExtendedDetails(customerId, (int)CustomerExtendedGroup.QualifiedRecruit).ToList();


            foreach (var item in lst.Where(item => previousAwardedRecruit.Where(i => i.Field1.Equals(item.RecruitID.ToString())).ToList().Count == 0))
            {
                decimal qualifiedRecruitCredit;
                var     enrollerEBProgramEndDate = item.EnrollerStartDate.AddDays(100);
                var     recruitedInEBProgram     = item.RecruitStartDate >= item.EnrollerStartDate && item.RecruitStartDate <= enrollerEBProgramEndDate;

                // we give $200 here and $200 comes from the Exigo recruiting reward at the beginning of the next month
                if (!recruitedInEBProgram)
                {
                    continue;
                }
                qualifiedRecruitCredit = (decimal)QualifiedRecruitThreshold.Phase2;

                var responseQualifiedRecruit = api.CreateCustomerExtended(new CreateCustomerExtendedRequest()
                {
                    CustomerID      = customerId,                                                    //Customer ID
                    ExtendedGroupID = (int)CustomerExtendedGroup.QualifiedRecruit,
                    Field1          = item.RecruitID.ToString(),                                     // Qualified Recruit Customer ID
                    Field2          = item.RecruitStartDate.ToString(CultureInfo.InvariantCulture),  // Recruit Start Date
                    Field3          = qualifiedRecruitCredit.ToString(CultureInfo.InvariantCulture), // Amount Awarded
                    Field4          = DateTime.Now.ToString(CultureInfo.InvariantCulture)            // creation date and time
                });

                var responsePointAccount = api.CreatePointTransaction(new CreatePointTransactionRequest
                {
                    Amount          = qualifiedRecruitCredit,
                    CustomerID      = customerId,
                    PointAccountID  = PointAccounts.QualifiedRecruit,
                    TransactionType = PointTransactionType.Adjustment
                });
            }
        }
        /// <summary>
        /// This method returns the list of item codes which the customer has already purchased.
        /// </summary>
        protected IList <string> PurchasedItemCodes()
        {
            List <string> itemCodes = new List <string>();

            var response = Exigo.GetCustomerExtendedDetails(CustomerId, (int)CustomerExtendedGroup.NewProductsLaunchPurchase);

            foreach (var row in response)
            {
                var sku = row.Field1;

                // There shouldn't be any duplicates but it is better to perform the check just in case versus having the application crash...
                if (!itemCodes.Contains(sku))
                {
                    itemCodes.Add(sku);
                }
            }

            return(itemCodes);
        }
Esempio n. 7
0
        ////Not being used anymore...just here for reference
        //public void CreateCustomerRecruitingRewards(int customerId)
        //{

        //    var api = Exigo.WebService();
        //    var reward = new RecruitingRewardDiscount();

        //    //Set start and expiry dates.
        //    var startDate = DateTime.Now;
        //    reward.CompletionDate = startDate.AddDays(60);

        //    //customerId = 1022;
        //    const int extendedGroupId = (int)CustomerExtendedGroup.RecruitingRewards;

        //    //Get Discount amount and check validity.
        //    reward.RewardAmount = Convert.ToDecimal(GetRecruitingReward(customerId));
        //    if (reward.DiscountAmount <= 0) return;

        //    //Check if the reward has already been added for the customer
        //    var customerEx = Exigo.GetCustomerExtendedDetails(customerId, extendedGroupId).Where(x => Convert.ToDateTime(x.Field2) == reward.CompletionDate);
        //    if (customerEx.Any()) return;

        //    var response = api.CreateCustomerExtended(new CreateCustomerExtendedRequest()
        //    {
        //        CustomerID = customerId,
        //        ExtendedGroupID = extendedGroupId,
        //        Field1 = reward.ItemCode, //Item Code
        //        Field2 = reward.CompletionDate.ToString(CultureInfo.InvariantCulture), //Completion Date
        //        Field4 = Convert.ToString(reward.RewardAmount, CultureInfo.InvariantCulture), //RewardAmount
        //        Field3 = 0.ToString(CultureInfo.InvariantCulture) //Redeemed

        //    });
        //}

        ////Also not being use at this time.
        //public decimal GetRecruitingReward(int customerId)
        //{

        //    var request = new GetPointAccountRequest()
        //    {
        //        CustomerID = customerId,
        //        PointAccountID = PointAccounts.RecruitingRewards
        //    };
        //    var rewardAmount = Exigo.GetRecruitingReward(request);

        //    return rewardAmount;
        //}

        //public IList<RecruitingRewardDiscount> GetCustomerRecruitingRewardDiscounts(int customerId)
        //{
        //    var details = Exigo.GetCustomerExtendedDetails(customerId, (int)CustomerExtendedGroup.RecruitingRewards /* Recruiting Rewards Extended Group ID */);

        //    var recruitingReward = (from d in details
        //                            select new RecruitingRewardDiscount()
        //                    {
        //                        CustomerExtendedDetailId = d.CustomerExtendedDetailID,
        //                        CompletionDate = DateTime.Parse(d.Field2),
        //                        ItemCode = d.Field1,
        //                        HasBeenRedeemed = (d.Field3 == "1"),
        //                        RewardAmount = Convert.ToDecimal(d.Field4)
        //                    }
        //     );

        //    return recruitingReward.ToList();

        //}

        #endregion Recruiting-Reward

        #region Enrollee-Reward

        //public void CreateCustomerEnrolleeRewards(int customerId)
        //{

        //    var api = Exigo.WebService();
        //    var reward = new EnrolleeRewardDiscount();

        //    //Set start and expiry dates.
        //    var startDate = DateTime.Now;
        //    reward.CompletionDate = startDate.AddDays(60);

        //    //customerId = 1022;
        //    const int extendedGroupId = (int)CustomerExtendedGroup.EnrolleeRewards;

        //    //Get Discount amount and check validity.
        //    reward.RewardAmount = Convert.ToDecimal(GetEnrolleeReward(customerId));
        //    if (reward.DiscountAmount <= 0) return;

        //    //Check if the reward has already been added for the customer
        //    var customerEx = Exigo.GetCustomerExtendedDetails(customerId, extendedGroupId).Where(x => Convert.ToDateTime(x.Field2) == reward.CompletionDate);
        //    if (customerEx.Any()) return;

        //    var response = api.CreateCustomerExtended(new CreateCustomerExtendedRequest()
        //    {
        //        CustomerID = customerId,
        //        ExtendedGroupID = extendedGroupId,
        //        Field1 = reward.CompletionDate.ToString(CultureInfo.InvariantCulture), //Completion Date
        //        Field2 = Convert.ToString(reward.RewardAmount), //RewardAmount
        //        Field3 = 0.ToString(CultureInfo.InvariantCulture) //Redeemed

        //    });
        //}

        //public decimal GetEnrolleeReward(int customerId)
        //{

        //    var request = new GetPointAccountRequest()
        //    {
        //        CustomerID = customerId,
        //        PointAccountID = PointAccounts.EnrolleeRewards
        //    };
        //    var rewardAmount = Exigo.GetEnrolleeReward(request);

        //    return rewardAmount;
        //}

        //public IList<EnrolleeRewardDiscount> GetCustomerEnrolleeRewardDiscounts(int customerId)
        //{
        //    var details = Exigo.GetCustomerExtendedDetails(customerId, (int)CustomerExtendedGroup.EnrolleeRewards /* Recruiting Rewards Extended Group ID */);

        //    var enrolleeReward = (from d in details
        //                          select new EnrolleeRewardDiscount()
        //                            {
        //                                CustomerExtendedDetailId = d.CustomerExtendedDetailID,
        //                                CompletionDate = DateTime.Parse(d.Field2),
        //                                ItemCode = d.Field3,
        //                                HasBeenRedeemed = (d.Field5 == "1")
        //                            }
        //     );

        //    return enrolleeReward.ToList();

        //}

        #endregion Enrollee-Reward


        public int CreateRewardsAutoOrder(string itemCode, int customerId, int ExtendedGroupID, int phase)
        {
            ShoppingCart.Items.Clear();
            try
            {
                Api = Exigo.WebService();

                CustomerExtendedDetails customerEx = Exigo.GetCustomerExtendedDetails(customerId, ExtendedGroupID).FirstOrDefault(x => x.Field3 == itemCode && x.Field1 == phase.ToString());
                if (customerEx != null)
                {
                    return(0);
                }
                var customer = Exigo.GetCustomer(customerId);
                // Start creating the API requests
                var details = new List <ApiRequest>();
                // Create the order request, if applicable
                ShoppingCartItem cartItem = ShoppingCartItem.Create();

                cartItem.ItemCode          = itemCode;
                cartItem.Quantity          = 1;
                cartItem.PriceEachOverride = 0;
                cartItem.PriceTypeID       = PriceTypes.Wholesale;
                cartItem.Type = ShoppingCartItemType.Order;

                ShoppingCart.Items.Add(cartItem);
                if (string.IsNullOrEmpty(itemCode))
                {
                    _log.TraceEvent(TraceEventType.Warning, 1, "IRewardService.CreateBonusKickerAutoOrder( String, int ): Entering method and ShoppingCart.Items is {0}.", (ShoppingCart.Items == null) ? "null" : "empty");
                    _nlog.Warn("IRewardService.CreateBonusKickerAutoOrder( String, int ): Entering method and ShoppingCart.Items is {0}.", (ShoppingCart.Items == null) ? "null" : "empty");
                }
                else
                {
                    _log.TraceEvent(TraceEventType.Information, 1, "IRewardService.CreateBonusKickerAutoOrder( String, int ): Entering method and ShoppingCart.Items is {0}.", ShoppingCart.Items.Count);
                    _nlog.Info("IOrderService.PlaceOrder( Shop, String ): Entering method with {0} products.", ShoppingCart.Items.Count);
                }
                // Create the autoorder request, if applicable
                var autoOrderRequest = new CreateOrderRequest(
                    AutoOrderConfiguration,
                    (int)ShipMethods.Standard,
                    string.Empty,
                    ShoppingCart.Items,
                    new ShippingAddress
                {
                    Address1    = string.IsNullOrEmpty(customer.MainAddress.Address1) ? customer.MailingAddress.Address1 : customer.MainAddress.Address1,
                    Address2    = string.IsNullOrEmpty(customer.MainAddress.Address2) ? customer.MailingAddress.Address2 : customer.MainAddress.Address2,
                    AddressType = AddressType.Mailing,
                    City        = string.IsNullOrEmpty(customer.MainAddress.City) ? customer.MailingAddress.City : customer.MainAddress.City,
                    Country     = string.IsNullOrEmpty(customer.MainAddress.Country) ? customer.MailingAddress.Country : customer.MainAddress.Country,
                    CustomerID  = customer.CustomerID,
                    Email       = customer.Email,
                    LastName    = customer.LastName,
                    FirstName   = customer.FirstName,
                    Phone       = customer.MobilePhone,
                    State       = string.IsNullOrEmpty(customer.MainAddress.State) ? customer.MailingAddress.State : customer.MainAddress.State,
                    Zip         = string.IsNullOrEmpty(customer.MainAddress.Zip) ? customer.MailingAddress.Zip : customer.MainAddress.Zip,
                },
                    shippingOverride: 0,
                    taxOverride: 0);

                autoOrderRequest.TaxRateOverride        = 0M;
                autoOrderRequest.ShippingAmountOverride = 0M;
                autoOrderRequest.CustomerID             = customerId;
                autoOrderRequest.Other15 = "1";

                details.Add(autoOrderRequest);

                // Process the transaction
                var transactionRequest = new TransactionalRequest {
                    TransactionRequests = details.ToArray()
                };
                var transactionResponse = Exigo.WebService().ProcessTransaction(transactionRequest);
                if (transactionResponse == null)
                {
                    _log.TraceEvent(TraceEventType.Error, 1, "There was no CreateOrderResponse.");
                }
                else
                {
                    _log.TraceEvent(TraceEventType.Information, 1, "ProcessTransaction.Result.TransactionKey = {0}", transactionResponse.Result.TransactionKey);
                    _log.TraceEvent(TraceEventType.Information, 1, "ProcessTransaction.Result.Reponse = {0}", transactionResponse.Result.Status);

                    if ((transactionResponse.Result.Errors != null) && (transactionResponse.Result.Errors.Length > 0))
                    {
                        _log.TraceEvent(TraceEventType.Error, 1, "ProcessTransaction.Result.Errors.Length = {0}", transactionResponse.Result.Errors.Length);
                        for (int i = 0; i < transactionResponse.Result.Errors.Length; i++)
                        {
                            _log.TraceEvent(TraceEventType.Error, 1, "ProcessTransaction.Result.Errors[{0}] = {1}", i, transactionResponse.Result.Errors[i]);
                        }
                    }
                }
                var newOrderId = 0;

                //process the response
                if (transactionResponse.Result.Status == ResultStatus.Success)
                {
                    foreach (var orderResponse in transactionResponse.TransactionResponses.OfType <CreateOrderResponse>())
                    {
                        newOrderId = orderResponse.OrderID;

                        var request = Api.CreateCustomerExtended(new CreateCustomerExtendedRequest()
                        {
                            CustomerID      = customer.CustomerID,
                            ExtendedGroupID = ExtendedGroupID,
                            Field1          = phase.ToString(),                         // phase # for bonus kicker or module for training
                            Field2          = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                            Field3          = itemCode,                                 //ItemCode
                            Field4          = 100.ToString(),                           //Discount Percent
                            Field5          = 1.ToString(CultureInfo.InvariantCulture), //Redeemed
                            Field6          = newOrderId.ToString()                     // orderid
                        });
                    }

                    var updateOrder = Api.ChangeOrderStatus(new ChangeOrderStatusRequest()
                    {
                        OrderID     = newOrderId,
                        OrderStatus = OrderStatusType.Accepted
                    });
                }
                return(newOrderId);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Esempio n. 8
0
        public Event GetEventDetails(int eventId)
        {
            Customer eventCustomer = Exigo.GetCustomerByIDandType(eventId, CustomerTypes.Party);

            //using (var context = Exigo.Sql())
            //{
            //    var sql = string.Format("exec GetCustomerByIDandType {0}, {1}", eventId, CustomerTypes.Party);
            //    eventCustomer = context.Query<Customer>(sql).FirstOrDefault();
            //}

            //if (null == eventCustomer)
            //{
            //    throw new ApplicationException("The provided event ID does not exist.");
            //}

            var eventCustomerSiteResponse = Exigo.GetCustomerSite(eventId);

            var eventCustomerEx = Exigo.GetCustomerExtendedDetails(eventId, (int)CustomerExtendedGroup.PartyDetails).FirstOrDefault();

            var creator           = new Customer();
            int creatorCustomerId = 0;

            if (int.TryParse(eventCustomerEx.Field5, out creatorCustomerId))
            {
                creator          = Exigo.GetCustomerByIDandType(creatorCustomerId, CustomerTypes.IndependentStyleAmbassador);
                creator.WebAlias = Exigo.GetCustomerWebAlias(creator.CustomerID);
            }

            var host           = new Customer();
            int hostCustomerId = 0;

            if (int.TryParse(eventCustomerEx.Field6, out hostCustomerId))
            {
                host = Exigo.GetCustomer(hostCustomerId);
            }

            // Retrieve the party sales total
            var salesTotal = GetPointAccountBalance(eventId, PointAccounts.PartySalesTotal);

            // Retieve the Host' rewards point accounts
            var pointAccounts = GetHostRewardPointAccounts(eventId);

            //var bookingRewards = GetBookingRewards();

            //int bookingRewardsOwnerId = 0;
            //int.TryParse(eventCustomerEx.Field7, out bookingRewardsOwnerId);

            // Create Missing Host Specials
            //CreateMissngHostSpecials(eventCustomerEx);


            var @event = new Event()
            {
                Id                 = eventCustomer.CustomerID,
                Name               = eventCustomer.FirstName,
                Location           = eventCustomer.MainAddress,
                Creator            = creator,
                Host               = host,
                TotalSales         = salesTotal,
                EventPointAccounts = null != pointAccounts?pointAccounts.ToArray() : null,
                                         //EventBookingRewards = bookingRewards,
                                         //BookingRewardsOwnerId = bookingRewardsOwnerId,
                                         WebAlias      = eventCustomerSiteResponse.WebAlias,
                                         StartDate     = Convert.ToDateTime(eventCustomerEx.Field1),
                                         ActualDate    = Convert.ToDateTime(eventCustomerEx.Field2),
                                         EventStatus   = eventCustomer.CustomerStatusID == 0 ? "Close" : Convert.ToDateTime(eventCustomerEx.Field4) < DateTime.Now ? "Close" : "Open",
                                         CloseDate     = Convert.ToDateTime(eventCustomerEx.Field3),
                                         LockoutDate   = Convert.ToDateTime(eventCustomerEx.Field4),
                                         DeletedEvents = eventCustomer.CustomerStatusID == 0?true:false,
                                         //HostSpecialReward = (HostSpecialDiscount)eventCustomerEx,
            };

            if ((@event.LockoutDate - @event.CloseDate).TotalDays <= 2.00)
            {
                @event.LockoutDate = @event.CloseDate.AddDays(7);
            }
            return(@event);
        }
Esempio n. 9
0
        EventConfirmation IEventService.EditEvent(Common.ModelsEx.Event.EventBooking eventBooking)
        {
            var confirmation             = new EventConfirmation();
            TransactionalResponse result = null;

            try
            {
                var requests = new List <ApiRequest>();

                // Need to create customer if new party customer
                if (eventBooking.Customer.CustomerID != 0)
                {
                    // TODO: gwb:20150111 - Need clarification which fields can be updated for a party
                    // Right now, updating party location
                    var updateCustomerRequest = new UpdateCustomerRequest
                    {
                        CustomerID   = eventBooking.Customer.CustomerID,
                        FirstName    = eventBooking.Customer.FirstName,
                        LastName     = eventBooking.Customer.LastName,
                        MainAddress1 = eventBooking.Customer.MainAddress.Address1,
                        MainAddress2 = eventBooking.Customer.MainAddress.Address2,
                        MainCity     = eventBooking.Customer.MainAddress.City,
                        MainState    = eventBooking.Customer.MainAddress.State,
                        MainZip      = eventBooking.Customer.MainAddress.Zip,
                        MainCountry  = eventBooking.Customer.MainAddress.Country
                    };
                    requests.Add(updateCustomerRequest);
                }
                else
                {
                    throw new ApplicationException("Cannot call EditEvent for a new event.  Call CreateEvent instead.");
                }

                var setCustomerSiteRequest = new SetCustomerSiteRequest(eventBooking.CustomerSite);
                requests.Add(setCustomerSiteRequest);

                var getCustomerExtendedRequest = new GetCustomerExtendedRequest()
                {
                    CustomerID      = eventBooking.Customer.CustomerID,
                    ExtendedGroupID = (int)CustomerExtendedGroup.PartyDetails // Party Extended Fields
                };
                var getCustomerExtendedResponse = Exigo.GetCustomerExtendedDetails(eventBooking.Customer.CustomerID, (int)CustomerExtendedGroup.PartyDetails).FirstOrDefault();

                var updateCustomerExtendedRequest = new UpdateCustomerExtendedRequest()
                {
                    CustomerExtendedID = getCustomerExtendedResponse.CustomerExtendedDetailID,
                    CustomerID         = eventBooking.Customer.CustomerID,
                    ExtendedGroupID    = (int)CustomerExtendedGroup.PartyDetails, // Party Extended Fields
                    Field2             = eventBooking.ActualStartDate.ToString(),
                    Field3             = eventBooking.CloseDate.ToString(),
                    Field4             = eventBooking.LockoutDate.ToString(),
                    Field12            = eventBooking.PartyDate.ToString(),
                    Field13            = eventBooking.PartyStartTime,
                    Field14            = eventBooking.PartyEndTime,
                    Field15            = eventBooking.TimeZone
                };
                requests.Add(updateCustomerExtendedRequest);

                result = Api.ProcessTransaction(new TransactionalRequest
                {
                    TransactionRequests = requests.ToArray()
                });
            }
            catch (Exception ex)
            {
                if (Status.Success.Equals(confirmation.Result.Status))
                {
                    confirmation.Result.Errors.Add("Your event was updated but an unexpected error was encountered: " + ex.Message);
                }
                else
                {
                    confirmation.Result.Errors.Add("There was an unexpected error while updating your event: " + ex.Message);
                }

                return(confirmation);
            }
            try
            {
                using (var context = Exigo.Sql())
                {
                    string sqlProcedure = string.Format("UpdateEvent {0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}'", eventBooking.Customer.CustomerID, eventBooking.Customer.FirstName, eventBooking.ActualStartDate.ToString(CultureInfo.InvariantCulture), eventBooking.CloseDate.ToString(CultureInfo.InvariantCulture), eventBooking.LockoutDate.ToString(CultureInfo.InvariantCulture), eventBooking.PartyStartTime, eventBooking.PartyEndTime, eventBooking.TimeZone, eventBooking.CustomerSite.WebAlias);
                    bool   eventUpdated = context.Query <bool>(sqlProcedure).FirstOrDefault();
                }
            }
            catch (Exception EX)
            {
            }

            ProcessUpdatePartyCustomerResponse(result, eventBooking, confirmation);
            return(confirmation);
        }