public bool ProcessPaymentFor(IStore store, ICart cart, IAccount account) { LoggingService.Log("______________________"); LoggingService.Log("Processing Payment ..."); if (!account.IsLoggedIn) { throw new Exception("Unauthorized"); } if (cart.IsEmpty()) { throw new Exception("cart is empty"); } if (!cart.HasPaymentMethod()) { throw new Exception("Payment method is not set"); } var oldPrice = cart.Items.GetTotalPrice(); var price = Models.CurrencyUtils.CurrencyUtils.Convert(oldPrice, store.Currency, cart.PaymentMethod.Currency); LoggingService.Log($"Paying with {cart.PaymentMethod.GetType().ToString().Split(".").LastOrDefault()}"); if (cart.PaymentMethod.Withdraw(price)) { LoggingService.Log("Done."); LoggingService.Log("______________________"); cart.Clear(); return(true); } LoggingService.Log("Failed: Not Enough Amount!"); LoggingService.Log("______________________"); return(false); }
public IActionResult RemoveAllItems() { var UserID = _userManager.GetUserId(User); _cartService.Clear(UserID); return(RedirectToAction("Index")); }
public bool ClearCart(IStore store, ICart cart) { var cardItems = cart.Items; foreach (var item in cardItems) { store.AddItem(item.Item, item.Quantity); } cart.Clear(); return(true); }
public static void Clear(int userId) { if (userId > 0) { dal.Clear(userId); } else { CartHelper.ClearCart(); } }
public void AddItem() { var firstItem = catalog.All().First(); cart.AddItem(firstItem); Assert.AreEqual(firstItem, cart.Items().First().Key); Assert.AreEqual(1, cart.Items().First().Value); cart.Clear(); Assert.IsFalse(cart.Items().Any()); }
public Order Checkout(ICart cart, Person person) { var order = new Order { Id = Guid.NewGuid(), Lines = cart.Items().Select(i => new OrderLine { Item = i.Key, Quantity = i.Value }).ToList(), Person = person }; orderRepository.Add(order); cart.Clear(); return(order); }
private void CreateAndPostOrder(IVoucherService voucherService) { var createVoucher = new CreateVoucherDTO { vouchertypeId = Properties.Settings.Default.VoucherTypeId, maxRedemptions = 0, firstName = _customerDetailViewModel.FirstName, lastName = _customerDetailViewModel.SecondName, email = _customerDetailViewModel.Email }; foreach (var itemLine in _cart.Lines) { var attribute = new AttributeDTO { attributeId = itemLine.Experience.Code, value = itemLine.Quantity.ToString(), }; createVoucher.attributes.Add(attribute); } var voucherDetail = voucherService.CreateVoucher(createVoucher).Result; _cart.Clear(); var model = new VoucherDetailViewModel { VoucherToken = voucherDetail.voucherToken, VoucherDescription = voucherDetail.voucherDescription, Name = voucherDetail.name, VoucherPurchasedOn = voucherDetail.voucherPurchasedOn, UsedOn = voucherDetail.usedOn }; _voucherDetailViewModel = null; _voucherDetailViewModel = model; }
public CartClearResponse ClearCart(CartClearRequest request) { var response = new CartClearResponse(); var validationErrors = _cartValidation.CartClearRequestValidation.Validate(request); var dbErrors = new List <DatabaseErrors>(); if (validationErrors.Count != 0) { response.ValidationErrors = validationErrors; } else { try { response.HasClear = _cartRepository.Clear(request.CartId); } catch (SqlException) { dbErrors.Add(DatabaseErrors.DB_CONNECTION_FAILED); } response.DBErrors = dbErrors; } return(response); }
public void OnPostClear() { Cart.Clear(); }
public ViewResult Completed() { cart.Clear(); return(View()); }
public IActionResult ClearCart() { cart.Clear(); //return Redirect(Url.Action("Index", "Order")); return(RedirectToAction(actionName: nameof(Index))); }
private void UpdateInventory() { _productService.UpdateProductQuantities(); _cart.Clear(); }
public IActionResult Completed() { _cart.Clear(); return(View()); }
public RedirectToActionResult ClearCart() { _cart.Clear(); return(RedirectToAction("Index", "Home")); }
public void Clear() { _cart.Clear(); _session.Remove(SerializationName); }