public JsonResult RemoveItem(int productId) { ModifyBasketRequest request = new ModifyBasketRequest(); request.ItemsToRemove.Add(productId); request.BasketId = base.GetBasketId(); ModifyBasketResponse reponse = _basketService.ModifyBasket(request); SaveBasketSummaryToCookie(reponse.Basket.NumberOfItems, reponse.Basket.BasketTotal); BasketDetailView basketDetailView = new BasketDetailView(); basketDetailView.BasketSummary = new BasketSummaryView() { BasketTotal = reponse.Basket.BasketTotal, NumberOfItems = reponse.Basket.NumberOfItems }; basketDetailView.Basket = reponse.Basket; basketDetailView.DeliveryOptions = _basketService.GetAllDespatchOptions().DeliveryOptions; return Json(basketDetailView); }
public JsonResult UpdateShipping(int shippingServiceId) { ModifyBasketRequest request = new ModifyBasketRequest(); request.SetShippingServiceIdTo = shippingServiceId; request.BasketId = base.GetBasketId(); BasketDetailView basketDetailView = new BasketDetailView(); ModifyBasketResponse reponse = _basketService.ModifyBasket(request); SaveBasketSummaryToCookie(reponse.Basket.NumberOfItems, reponse.Basket.BasketTotal); basketDetailView.BasketSummary = new BasketSummaryView() { BasketTotal = reponse.Basket.BasketTotal, NumberOfItems = reponse.Basket.NumberOfItems }; basketDetailView.Basket = reponse.Basket; basketDetailView.DeliveryOptions = _basketService.GetAllDespatchOptions().DeliveryOptions; return Json(basketDetailView); }
public ModifyBasketResponse ModifyBasket(ModifyBasketRequest request) { ModifyBasketResponse response = new ModifyBasketResponse(); Basket basket = _basketRepository.FindBy(request.BasketId); if (basket == null) throw new BasketDoesNotExistException(); AddProductsToBasket(request.ProductsToAdd, basket); UpdateLineQtys(request.ItemsToUpdate, basket); RemoveItemsFromBasket(request.ItemsToRemove, basket); if (request.SetShippingServiceIdTo != 0) { DeliveryOption deliveryOption = _deliveryOptionRepository.FindBy(request.SetShippingServiceIdTo); basket.SetDeliveryOption(deliveryOption); } ThrowExceptionIfBasketIsInvalid(basket); _basketRepository.Save(basket); _uow.Commit(); response.Basket = basket.ConvertToBasketView(); return response; }
public JsonResult UpdateItems(JsonBasketQtyUpdateRequest jsonBasketQtyUpdateRequest) { ModifyBasketRequest request = new ModifyBasketRequest(); request.BasketId = base.GetBasketId(); request.ItemsToUpdate = jsonBasketQtyUpdateRequest.ConvertToBasketItemUpdateRequests(); ; BasketDetailView basketDetailView = new BasketDetailView(); ModifyBasketResponse reponse = _basketService.ModifyBasket(request); SaveBasketSummaryToCookie(reponse.Basket.NumberOfItems, reponse.Basket.BasketTotal); basketDetailView.BasketSummary = new BasketSummaryView() { BasketTotal = reponse.Basket.BasketTotal, NumberOfItems = reponse.Basket.NumberOfItems }; basketDetailView.Basket = reponse.Basket; basketDetailView.DeliveryOptions = _basketService.GetAllDespatchOptions().DeliveryOptions; return Json(basketDetailView); }
public JsonResult AddToBasket(int productId) { BasketSummaryView basketSummaryView = new BasketSummaryView(); Guid basketId = base.GetBasketId(); bool createNewBasket = basketId == Guid.Empty; if (createNewBasket == false) { ModifyBasketRequest modifyBasketRequest = new ModifyBasketRequest(); modifyBasketRequest.ProductsToAdd.Add(productId); modifyBasketRequest.BasketId = basketId; try { ModifyBasketResponse response = _basketService.ModifyBasket(modifyBasketRequest); basketSummaryView = response.Basket.ConvertToSummary(); SaveBasketSummaryToCookie(basketSummaryView.NumberOfItems, basketSummaryView.BasketTotal); } catch (BasketDoesNotExistException ex) { createNewBasket = true; } } if (createNewBasket) { CreateBasketRequest createBasketRequest = new CreateBasketRequest(); createBasketRequest.ProductsToAdd.Add(productId); CreateBasketResponse response = _basketService.CreateBasket(createBasketRequest); SaveBasketIdToCookie(response.Basket.Id); basketSummaryView = response.Basket.ConvertToSummary(); SaveBasketSummaryToCookie(basketSummaryView.NumberOfItems, basketSummaryView.BasketTotal); } return Json(basketSummaryView); }