Example #1
0
        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"));
        }
Example #3
0
        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);
        }
Example #4
0
 public static void Clear(int userId)
 {
     if (userId > 0)
     {
         dal.Clear(userId);
     }
     else
     {
         CartHelper.ClearCart();
     }
 }
Example #5
0
        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());
        }
Example #6
0
        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);
        }
Example #9
0
 public void OnPostClear()
 {
     Cart.Clear();
 }
Example #10
0
 public ViewResult Completed()
 {
     cart.Clear();
     return(View());
 }
Example #11
0
 public IActionResult ClearCart()
 {
     cart.Clear();
     //return Redirect(Url.Action("Index", "Order"));
     return(RedirectToAction(actionName: nameof(Index)));
 }
Example #12
0
 private void UpdateInventory()
 {
     _productService.UpdateProductQuantities();
     _cart.Clear();
 }
Example #13
0
 public IActionResult Completed()
 {
     _cart.Clear();
     return(View());
 }
Example #14
0
 public RedirectToActionResult ClearCart()
 {
     _cart.Clear();
     return(RedirectToAction("Index", "Home"));
 }
Example #15
0
 public void Clear()
 {
     _cart.Clear();
     _session.Remove(SerializationName);
 }