Example #1
0
        public JsonResult ActivateAccount()
        {
            try
            {
                var loyaltyCards = new List <LoyaltyCard>();
                var userResponse = this.AccountManager.GetUser(Context.User.Name);
                var result       = new LoyaltyCardsBaseApiModel(userResponse.ServiceProviderResult);
                if (userResponse.ServiceProviderResult.Success && userResponse.Result != null)
                {
                    var response = this.LoyaltyProgramManager.ActivateAccount(this.StorefrontContext.Current, this.CommerceUserContext.Current.UserId);
                    result.SetErrors(response.ServiceProviderResult);

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

                result.Initialize(loyaltyCards);
                return(this.Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Sitecore.Commerce.OpenIDConnectionClosedUnexpectedlyException e)
            {
                this.CleanNotAuthorizedSession();
                return(this.Json(new ErrorApiModel("Login", e), JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(this.Json(new ErrorApiModel("ActivateAccount", e), JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        public JsonResult GetLoyaltyCards()
        {
            try
            {
                var loyaltyCards = new List <LoyaltyCard>();
                var userResponse = this.AccountManager.GetUser(Context.User.Name);
                var result       = new LoyaltyCardsBaseApiModel(userResponse.ServiceProviderResult);
                if (userResponse.ServiceProviderResult.Success && userResponse.Result != null)
                {
                    loyaltyCards = this.AllCards(result, true);
                    if (result.Success)
                    {
                        foreach (var card in loyaltyCards)
                        {
                            foreach (var loyaltyRewardPoint in card.RewardPoints)
                            {
                                var point = (LoyaltyRewardPoint)loyaltyRewardPoint;
                                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(this.Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Sitecore.Commerce.OpenIDConnectionClosedUnexpectedlyException e)
            {
                this.CleanNotAuthorizedSession();
                return(this.Json(new ErrorApiModel("Login", e), JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(this.Json(new ErrorApiModel("GetLoyaltyCards", e), JsonRequestBehavior.AllowGet));
            }
        }