public JsonResult ActivateAccount()
        {
            try
            {
                var loyaltyCards = new List <LoyaltyCard>();
                var userResponse = this.AccountManager.GetUser(Context.User.Name);
                var result       = new LoyaltyCardsJsonResult(userResponse.ServiceProviderResult);
                if (userResponse.ServiceProviderResult.Success && userResponse.Result != null)
                {
                    var response = this.LoyaltyProgramManager.ActivateAccount(this.CurrentStorefront, this.CurrentVisitorContext);
                    result.SetErrors(response.ServiceProviderResult);

                    if (response.ServiceProviderResult.Success && response.Result != null && !string.IsNullOrEmpty(response.Result.CardNumber))
                    {
                        loyaltyCards = this.AllCards(result);
                    }
                }

                result.Initialize(loyaltyCards);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("ActivateAccount", this, e);
                return(Json(new BaseJsonResult("ActivateAccount", e), JsonRequestBehavior.AllowGet));
            }
        }
        private List <LoyaltyCard> AllCards(LoyaltyCardsJsonResult result)
        {
            var response = this.LoyaltyProgramManager.GetLoyaltyCards(this.CurrentStorefront, this.CurrentVisitorContext.UserId);
            var cards    = new List <LoyaltyCard>();

            if (response.ServiceProviderResult.Success && response.Result != null)
            {
                cards = response.Result.ToList();
            }

            result.SetErrors(response.ServiceProviderResult);
            return(cards);
        }
        public JsonResult ActiveLoyaltyCards()
        {
            try
            {
                var loyaltyCards = new List <LoyaltyCard>();
                var userResponse = this.AccountManager.GetUser(Context.User.Name);
                var result       = new LoyaltyCardsJsonResult(userResponse.ServiceProviderResult);
                if (userResponse.ServiceProviderResult.Success && userResponse.Result != null)
                {
                    loyaltyCards = this.AllCards(result).Take(5).ToList();
                }

                result.Initialize(loyaltyCards);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("ActiveLoyaltyCards", this, e);
                return(Json(new BaseJsonResult("ActiveLoyaltyCards", e), JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
        public JsonResult GetLoyaltyCards()
        {
            try
            {
                var loyaltyCards = new List <LoyaltyCard>();
                var userResponse = this.AccountManager.GetUser(Context.User.Name);
                var result       = new LoyaltyCardsJsonResult(userResponse.ServiceProviderResult);
                if (userResponse.ServiceProviderResult.Success && userResponse.Result != null)
                {
                    loyaltyCards = this.AllCards(result);
                    if (result.Success)
                    {
                        foreach (var card in loyaltyCards)
                        {
                            foreach (var loyaltyRewardPoint in card.RewardPoints)
                            {
                                var point = (LoyaltyRewardPoint)loyaltyRewardPoint;
                                // NOTE: the stab while we don't have 'point.RewardPointId' yet.
                                var transactionResponse = this._loyaltyProgramManager.GetLoyaltyCardTransactions(card.ExternalId, Guid.NewGuid().ToGuidString(), 50);
                                //var transactionResponse = this.LoyaltyProgramManager.GetLoyaltyCardTransactions(card.ExternalId, point.RewardPointId, 50);
                                if (transactionResponse.ServiceProviderResult.Success && transactionResponse.Result != null)
                                {
                                    point.SetPropertyValue("Transactions", transactionResponse.Result.ToList());
                                }

                                result.SetErrors(transactionResponse.ServiceProviderResult);
                            }
                        }
                    }
                }

                result.Initialize(loyaltyCards);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                _logger.LogError("GetLoyaltyCards", this, e);
                return(Json(new BaseJsonResult("GetLoyaltyCards", e), JsonRequestBehavior.AllowGet));
            }
        }