public JsonResult AddToWishList(AddToWishListInputModel model) { try { Assert.ArgumentNotNull(model, "model"); var validationResult = new BaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return Json(validationResult, JsonRequestBehavior.AllowGet); } var wishLists = new List<WishListHeader>(); var response = this.WishListManager.AddLinesToWishList(this.CurrentStorefront, this.CurrentVisitorContext, model); var result = new WishListsBaseJsonResult(response.ServiceProviderResult); if (response.ServiceProviderResult.Success && response.Result != null) { wishLists = this.WishListsHeaders(result); } result.Initialize(wishLists); return Json(result, JsonRequestBehavior.AllowGet); } catch (Exception e) { CommerceLog.Current.Error("AddToWishList", this, e); return Json(new BaseJsonResult("AddToWishList", e), JsonRequestBehavior.AllowGet); } }
/// <summary> /// Adds the lines to wish list. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="model">The model.</param> /// <returns> /// The manager response with the wish list as the result. /// </returns> public virtual ManagerResponse<AddLinesToWishListResult, WishList> AddLinesToWishList([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, AddToWishListInputModel model) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(model, "model"); var product = new CommerceCartProduct { ProductCatalog = model.ProductCatalog, ProductId = model.ProductId, ProductVariantId = model.VariantId }; var line = new WishListLine { Product = product, Quantity = model.Quantity == null ? 1 : (uint)model.Quantity }; if (line.Product.ProductId.Equals(storefront.GiftCardProductId, StringComparison.OrdinalIgnoreCase)) { line.Properties.Add("GiftCardAmount", model.GiftCardAmount); } // create wish list if (model.WishListId == null && !string.IsNullOrEmpty(model.WishListName)) { var newList = this.CreateWishList(storefront, visitorContext, model.WishListName).Result; if (newList == null) { return new ManagerResponse<AddLinesToWishListResult, WishList>(new AddLinesToWishListResult { Success = false }, null); } model.WishListId = newList.ExternalId; } var result = this.AddLinesToWishList(storefront, visitorContext, model.WishListId, new List<WishListLine> { line }); return new ManagerResponse<AddLinesToWishListResult, WishList>(result.ServiceProviderResult, result.ServiceProviderResult.WishList); }