Example #1
0
        public IActionResult AddToWishList(string site, string item)
        {
            AddToWishListOutputModel OutPutData = new AddToWishListOutputModel();
            AddToWishListInputModel  filter     = new AddToWishListInputModel();

            filter.UserID     = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
            filter.SiteID     = Guid.Parse(site);
            filter.SiteItemID = Guid.Parse(item);
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseAPI + "Site/");
                var responseTask = client.PostAsJsonAsync <AddToWishListInputModel>("AddToWishList", filter);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var content = result.Content.ReadAsStringAsync();
                    AddToWishListResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <AddToWishListResponseModel>(content.Result);
                    OutPutData = resutl.data;
                }
                else                 //web api sent error response
                {
                    //log response status here..
                    ModelState.AddModelError(string.Empty, "Terjadi kesalahan. Mohon hubungi admin.");
                }
            }
            return(Json(OutPutData));
        }
Example #2
0
        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));
            }
        }
Example #3
0
        public JsonResult AddToWishList(AddToWishListInputModel model)
        {
            try
            {
                Assert.ArgumentNotNull(model, "model");

                var validationResult = new BaseApiModel();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(this.Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var wishLists = new List <WishListHeader>();
                var response  = this.WishListManager.AddLinesToWishList(this.StorefrontContext.Current, Context.User.Name, model);
                var result    = new WishListsBaseApiModel(response.ServiceProviderResult);
                if (response.ServiceProviderResult.Success && response.Result != null)
                {
                    wishLists = this.WishListsHeaders(result);
                }

                result.Initialize(wishLists);
                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("AddToWishList", e), JsonRequestBehavior.AllowGet));
            }
        }
Example #4
0
        public AddToWishListOutputModel Save(AddToWishListInputModel data)
        {
            WishListRepository repo = new WishListRepository(db);

            WishList temp = new WishList();

            temp.SiteID     = data.SiteID;
            temp.UserID     = data.UserID;
            temp.SiteItemID = data.SiteItemID;

            var res = repo.Insert(temp);

            AddToWishListOutputModel output = new AddToWishListOutputModel();

            output.SiteID = data.SiteID;


            return(output);
        }
Example #5
0
        public ActionResult <AddToWishListResponseModel> AddToWishList([FromBody] AddToWishListInputModel data)
        {
            AddToWishListResponseModel res = new AddToWishListResponseModel();

            try
            {
                WishListBL bl   = new WishListBL(DbContext);
                var        temp = bl.Save(data);

                res.data     = temp;
                res.Message  = "Success";
                res.Response = true;

                return(res);
            }
            catch (Exception ex)
            {
                res.Message  = ex.Message;
                res.Response = false;

                return(res);
            }
        }
        /// <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));
        }