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; 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) { CommerceLog.Current.Error("GetLoyaltyCards", this, e); return Json(new BaseJsonResult("GetLoyaltyCards", 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 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); } }