public IActionResult AddItemToBasket(AddItemRequest model) { _log.LogInformation($"Adding: {model.Name} to basket, quantity: {model.Quantity}."); return(Ok(_basketService.AddItemToBasket(new BasketItem { Id = model.Id, Name = model.Name, Price = model.Price, Quantity = model.Quantity }))); }
public async Task <IActionResult> AddToCart(CatalogItem productDetails) { try { if (productDetails.Id != null) { var user = _appUserParser.Parse(HttpContext.User); var product = new BasketItem() { Id = Guid.NewGuid().ToString(), Quantity = 1, ProductName = productDetails.Name, PictureUrl = productDetails.PictureUri, UnitPrice = productDetails.Price, ProductId = productDetails.Id }; await _basketSvc.AddItemToBasket(user, product); } return(RedirectToAction("Index", "Catalog")); } catch (BrokenCircuitException) { // Catch error when Basket.api is in circuit-opened mode HandleBrokenCircuitException(); } return(RedirectToAction("Index", "Catalog", new { errorMsg = ViewBag.BasketInoperativeMsg })); }
public async Task <IActionResult> OnPost(CatalogItemViewModel productDetails) { if (productDetails?.CatalogItemId == null) { return(RedirectToPage("/Index")); } await SetBasketModelAsync(); var options = await _basketService.GetFirstOptionFromAttributeAsync(productDetails.CatalogItemId); await _basketService.AddItemToBasket(BasketModel.Id, productDetails.CatalogItemId, productDetails.Price, 1, options.Item1, options.Item2, options.Item3, addToExistingItem : true); await SetBasketModelAsync(); return(new OkObjectResult(new { items = BasketModel.Items.Sum(x => x.Quantity), total = BasketModel.SubTotal() })); }
public async Task <IActionResult> OnPost(int wishListItemId) { var wishlist = await _wishlistViewModelService.GetOrCreateWishlistForUser(User.Identity.Name); if (wishlist == null) { //throw new Exception("Invalid Wishlist"); return(BadRequest("Invalid Wishlist")); } var wishListItem = wishlist.Items.Where(x => x.Id == wishListItemId).FirstOrDefault(); if (wishListItem == null) { //throw new Exception("Invalid Wishlist"); return(BadRequest("Item already in Wishlist")); } var basket = await _basketViewModelService.GetOrCreateBasketForUser(User.Identity.Name); if (basket == null) { return(RedirectToPage("/Login")); } var catalogItem = await _catalogItemRepository.GetByIdAsync(wishListItem.CatalogItemId); await _basketService.AddItemToBasket(basket.Id, wishListItem.CatalogItemId, catalogItem.Price); return(RedirectToPage("/Basket/Index")); }
private async Task AddToBasket(IDialogContext context, JObject json, int quantity) { BotData userData = await identityService.GetBotDataAsync(context); AuthUser authUser = userData.GetUserAuthData(); // TODO Check Expired if (authUser != null) { var reply = context.MakeMessage(); var producName = json.GetValue("ProductName").ToString(); var product = new BasketItem() { Id = Guid.NewGuid().ToString(), Quantity = quantity, ProductName = producName, PictureUrl = UIHelper.ReplacePictureUri(json.GetValue("PictureUrl").ToString()), UnitPrice = json.GetValue("UnitPrice").ToObject <decimal>(), ProductId = json.GetValue("ProductId").ToString(), }; await basketService.AddItemToBasket(authUser.UserId, product, authUser.AccessToken); reply.Text = string.Format(TextResources.You_have_added_to_your_basket, producName); context.Call(dialogFactory.CreateBasketDialog(), BasketAsync); } }
public IActionResult Privacy([FromServices] IBasketService basketService) { basketService.AddItemToBasket(1, "Kola", 3.5m, "", 3); ViewBag.items = basketService.BasketItems; string value = HttpContext.Session.GetString("basket"); return(View()); }
public async Task <IActionResult> AddtemToBasket(CatalogItemViewModel productDetails) { await _basketService.AddItemToBasket(BasketModel.Id, productDetails.Id, productDetails.Price, 1); var BasketModelS = await _basketViewModelService.GetOrCreateBasketForUser("alexis"); return(Ok(BasketModelS)); }
public async Task <IActionResult> AddToBasket(int productId, int quantity) { var basketId = await _basketViewModelService.GetOrCreateBasketIdAsync(); await _basketService.AddItemToBasket(basketId, productId, quantity); return(Json(await _basketViewModelService.GetBasketItemsCountViewModel(basketId))); }
public async Task <IActionResult> AddItemToBasket(int basketid, [FromBody] BasketAddItemRequest request) { await _basketService.AddItemToBasket(basketid, request.ProductId, request.Price, request.Quantity); return(Ok(new BasketAddItemResponse() { Success = true })); }
public async Task <IActionResult> AddToCart(CatalogItem productDetails) { try { if (productDetails?.Id != null) { var user = _appUserParser.Parse(HttpContext.User); await _basketSvc.AddItemToBasket(user, productDetails.Id); } return(RedirectToAction("Index", "Catalog")); } catch (BrokenCircuitException) { // Catch error when Basket.api is in circuit-opened mode HandleBrokenCircuitException(); } return(RedirectToAction("Index", "Catalog", new { errorMsg = ViewBag.BasketInoperativeMsg })); }
public async Task <IActionResult> AddToBasket(int productId, int quantity) { // application core projesinde BasketService : IBasketService // AddItemToBasket(int basketId, int catalogItemId, int quantity) var basketId = await _basketViewModelService.GetOrCreateBasketIdAsync(); await _basketService.AddItemToBasket(basketId, productId, quantity); // sepetteki yeni öğe sayısını döndür. return(Json(await _basketViewModelService.GetBasketItemsCountViewModel(basketId))); }
// GET: /Cart/AddToCart // TODO: This should be a POST. public async Task <IActionResult> AddToCart(CatalogItem productDetails) { if (productDetails?.Id == null) { return(RedirectToAction("Index", "Catalog")); } var basket = await GetBasketFromSessionAsync(); await _basketService.AddItemToBasket(basket, productDetails.Id, 1); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddToBasket(CatalogItemViewModel productDetails) { if (productDetails?.Id == null) { return(RedirectToAction("Index", "Catalog")); } var basketViewModel = await GetBasketViewModelAsync(); await _basketService.AddItemToBasket(basketViewModel.Id, productDetails.Id, productDetails.Price, 1); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddItemToBasket([FromBody] BasketItemRequest basketItemRequest) { var apiUser = BuildApiUser(); if (apiUser == null) { return(Unauthorized("Invalid or no X_API_SECRET")); } await _basketService.AddItemToBasket(apiUser.CustomerKey, BasketItemRequestMapper.MapToDto(basketItemRequest)); return(Ok(basketItemRequest)); }
public void Execute(string[] args) { var basket = _basketService.CreateBasket(); var products = GetProductsByNames(args); foreach (var product in products) { basket = _basketService.AddItemToBasket(basket.Id, product.Id, product.Price, 1); } basket = _basketService.ApplyDiscounts(basket.Id); PrintBasket(basket); Console.ReadLine(); }
public async Task <IActionResult> AddToBasket(int basketId, [FromBody] AddItem item) { var catalogueItem = await _catalogueService.GetCatalogueItem(item.CatalogueItemId.Value); if (catalogueItem == null) { return(NotFound("No CatalogueItem found")); } await _basketService.AddItemToBasket(basketId, catalogueItem.Id, catalogueItem.Price, item.Quantity.Value); return(Ok()); }
public async Task <IActionResult> OnPost(CatalogItemViewModel productDetails) { if (productDetails?.Id == null) { return(RedirectToPage("/Index")); } await SetBasketModelAsync(); await _basketService.AddItemToBasket(BasketModel.Id, productDetails.Id, productDetails.Price); await SetBasketModelAsync(); return(RedirectToPage()); }
public async Task <IActionResult> OnPost(CatalogItemViewModel productDetails, string catName = null, string typeName = null) { if (productDetails?.CatalogItemId == null) { return(RedirectToPage("/Index")); } await SetBasketModelAsync(); await _basketService.AddItemToBasket(BasketModel.Id, productDetails.CatalogItemId, productDetails.Price, 1, addToExistingItem : true); await SetBasketModelAsync(); StatusMessage = $"Adicionado {productDetails.CatalogItemName} ao carrinho!"; if (!string.IsNullOrEmpty(catName) && string.IsNullOrEmpty(typeName)) { return(RedirectToPage("/Category/Index", new { id = catName })); } else if (!string.IsNullOrEmpty(catName) && !string.IsNullOrEmpty(typeName)) { return(RedirectToPage("/Category/Type/Index", new { cat = catName, type = typeName })); } return(RedirectToPage("/Index")); }
public async Task <IActionResult> OnPost(CatalogItemViewModel product) { if (product.id == 0) { return(Page()); } await SetBasketModelAsync(); await _basketService.AddItemToBasket(basketModel.Id, product.id, product.price); await SetBasketModelAsync(); return(Page()); }
public async Task TransferWishlistItemToBasket(int wishListItemId, int basketId, int catalogItemId, int quantity = 1) { var wishListItem = await _wishlistItemRepository.GetByIdAsync(wishListItemId); if (wishListItem == null) { throw new Exception("Wishlist item doen't exist"); } var catalogItem = await _catalogItemRepository.GetByIdAsync(wishListItem.CatalogItemId); await _basketService.AddItemToBasket(basketId, wishListItem.CatalogItemId, catalogItem.Price, quantity); await _wishlistItemRepository.DeleteAsync(wishListItem); }
public async Task <IActionResult> AddToBasket(int productId, int quantity) { // application core projesinde BasketService:IBasketService //AddItemToBasket(int basketId, int catologId,int quantity) //sepette varsa adedini güncelle yoksa ekle //sepetteki öğe sayısını döndür var basketId = await _basketViewModelService.GetOrCreateBasketIdAsync(); await _basketService.AddItemToBasket(basketId, productId, quantity); int basketItemsCount = await _basketService.BasketItemsCount(basketId); return(Json(await _basketViewModelService.GetBasketItemsCountViewModel(basketId))); }
public async Task <IActionResult> OnPost(StoreProductItemViewModel productDetails) { if (productDetails?.Id == null) { return(RedirectToPage("/Index")); } await SetBasketModelAsync(); await _basketService.AddItemToBasket(BasketModel.Id, productDetails.StoreId, productDetails.SecondaryId, productDetails.ProductId, productDetails.OptionId, productDetails.Name, productDetails.PictureUri, productDetails.Price); await SetBasketModelAsync(); return(RedirectToPage()); }
public async Task <IActionResult> OnPost(CatalogItemViewModel productDetails) { if (productDetails?.Id == null) { return(RedirectToPage("/Index")); } await SetBasketModelAsync(); await _basketService.AddItemToBasket(BasketModel.Id, productDetails.Id, productDetails.Price); await SetBasketModelAsync(); StatusMessage = "Product was successfull added to your Basket. Continue buying the hapiness."; return(RedirectToPage("/Index")); }
public async Task <IActionResult> OnPost(CatalogItemViewModel productDetails) { if (productDetails?.Id == null) { return(RedirectToPage("/Index")); } var username = GetOrSetBasketCookieAndUserName(); var basket = await _basketService.AddItemToBasket(username, productDetails.Id, productDetails.Price); BasketModel = await _basketViewModelService.Map(basket); return(RedirectToPage()); }
public async Task <IActionResult> AddToCart(CatalogItem productDetails) { if (productDetails.Id != null) { var user = _appUserParser.Parse(HttpContext.User); var product = new BasketItem() { Id = Guid.NewGuid().ToString(), Quantity = 1, ProductName = productDetails.Name, PictureUrl = productDetails.PictureUri, UnitPrice = productDetails.Price, ProductId = productDetails.Id }; await _basketSvc.AddItemToBasket(user, product); } return(RedirectToAction("Index", "Catalog")); }
public ActionResult <BasketItem> AddItemToBasket(string customerId, [FromBody] BasketItem item) { // Check if the basket cannot be found if (!_basketRepository.TryGetBasket(customerId, out ShoppingBasket shoppingBasket)) { return(BasketNotFound(customerId)); } // Check if item already exists in basket if (_basketRepository.TryGetItemInBasket(item.ProductId, customerId, out BasketItem existingItem)) { return(ItemAlreadyFound(customerId, item.ProductId)); } _basketService.AddItemToBasket(shoppingBasket, item); return(CreatedAtRoute("GetItemInBasket", new { customerId, itemId = item.ProductId }, item)); }
public async Task <IActionResult> AddToCart(int itemId) { try { if (itemId > 0) { var user = _appUserParser.Parse(HttpContext.User); await _basketSvc.AddItemToBasket(user, itemId); } return(RedirectToAction("Index", "Cart")); } catch (Exception e) { _logger.LogError(e, "Add to cart failed"); } return(RedirectToAction("Index", "Catalog", new { errorMsg = "Basket Service is inoperative, please try later on. (Business Msg Due to Circuit-Breaker)" })); }
public async Task <IActionResult> AddToCart(ScholarshipItem scholarshipItemDetails) { try { if (scholarshipItemDetails?.Id != null) { var user = _appUserParser.Parse(HttpContext.User); await _basketSvc.AddItemToBasket(user, scholarshipItemDetails.Id); } return(RedirectToAction("Index", "Scholarship")); } catch (Exception ex) { // Catch error when Basket.api is in circuit-opened mode HandleException(ex); } return(RedirectToAction("Index", "Scholarship", new { errorMsg = ViewBag.BasketInoperativeMsg })); }
public async Task <IActionResult> OnPostTransferBasket(Dictionary <string, int> items) { await SetBasketModelAsync(); foreach (var kvp in items) { var wishListItemId = int.Parse(kvp.Key); var wishlistItem = await _wishListItemsRepo.GetByIdAsync(wishListItemId); if (wishlistItem == null) { _logger.LogInformation($"No item found in the catalog."); } // wishlistItem.CatalogItemId CatalogItem catalogItem = await _catalogItemsRepo.GetByIdAsync(wishlistItem.CatalogItemId); await _basketService.AddItemToBasket(BasketModel.Id, wishlistItem.CatalogItemId, catalogItem.Price, kvp.Value); } return(RedirectToPage("/Basket/Index")); }
private static void BasketHandler(ShelfItem[] shelfItems, IBasketService basketService) { while (true) { Write("\n ENTER ITEM NUMBER TO ADD IT TO THE BASKET (ENTER 'N' TO CHECKOUT): "); var userInput = ReadKey(); if (!Helper.ValidUserInput(userInput, "PLEASE ENTER ONE OF THE NUMBERS FROM THE ABOVE LIST")) { break; } var shelfItemId = int.Parse(userInput.KeyChar.ToString()); if (shelfItems.All(s => s.Id != shelfItemId)) { WriteLine("\n PLEASE ENTER ONE OF THE NUMBERS FROM THE ABOVE LIST \n"); continue; } var selectedShelfItem = shelfItems.SingleOrDefault(s => s.Id == shelfItemId); if (selectedShelfItem == null) { continue; } Write($"\n ENTER QTY OF {selectedShelfItem.Name.ToUpper()}: "); var qtyUserInput = ReadLine(); if (!Helper.ValidUserInput(qtyUserInput, "QUANTITY MUST BE A WHOLE NUMBER")) { continue; } int.TryParse(qtyUserInput, out var quantity); basketService.AddItemToBasket(selectedShelfItem, quantity); } }