public async Task <ActionResult> AddItem(ShoppingCartLineUpdateModel line, string shoppingCartId = null) { ShoppingCartItem parsedLine = await _shoppingCartHelpers.ParseCartLine(line); if (parsedLine is null) { await _notifier.AddAsync(NotifyType.Error, H["Product with SKU {0} not found.", line.ProductSku]); return(RedirectToAction(nameof(Index), new { shoppingCartId })); } parsedLine = (await _priceService.AddPrices(new[] { parsedLine })).Single(); if (!parsedLine.Prices.Any()) { await _notifier.AddAsync(NotifyType.Error, H["Can't add product {0} because it doesn't have a price.", line.ProductSku]); return(RedirectToAction(nameof(Index), new { shoppingCartId })); } ShoppingCart cart = await _shoppingCartPersistence.Retrieve(shoppingCartId); cart.AddItem(parsedLine); await _shoppingCartPersistence.Store(cart, shoppingCartId); if (_workflowManager != null) { await _workflowManager.TriggerEventAsync( nameof(ProductAddedToCartEvent), new { LineItem = parsedLine }, "ShoppingCart-" + _shoppingCartPersistence.GetUniqueCartId(shoppingCartId)); } return(RedirectToAction(nameof(Index), new { shoppingCartId })); }
/// <summary> /// Adds a new UI notification of type Success /// </summary> /// <seealso cref="INotifier.AddAsync"/> /// <param name="notifier">The <see cref="INotifier"/></param> /// <param name="message">A localized message to display</param> public static ValueTask SuccessAsync(this INotifier notifier, LocalizedHtmlString message) => notifier.AddAsync(NotifyType.Success, message);
/// <summary> /// Adds a new UI notification of type Error /// </summary> /// <seealso cref="INotifier.AddAsync"/> /// <param name="notifier">The <see cref="INotifier"/></param> /// <param name="message">A localized message to display</param> public static ValueTask ErrorAsync(this INotifier notifier, LocalizedHtmlString message) => notifier.AddAsync(NotifyType.Error, message);
/// <summary> /// Adds a new UI notification of type Warning /// </summary> /// <seealso cref="INotifier.AddAsync"/> /// <param name="notifier">The <see cref="INotifier"/></param> /// <param name="message">A localized message to display</param> public static ValueTask WarningAsync(this INotifier notifier, LocalizedHtmlString message) => notifier.AddAsync(NotifyType.Warning, message);
/// <summary> /// Adds a new UI notification of type Information /// </summary> /// <seealso cref="INotifier.AddAsync"/> /// <param name="notifier">The <see cref="INotifier"/></param> /// <param name="message">A localized message to display</param> public static ValueTask InformationAsync(this INotifier notifier, LocalizedHtmlString message) => notifier.AddAsync(NotifyType.Information, message);