Esempio n. 1
0
        public ActionResult AddItemToCart(FormCollection fc)
        {
            int id = Convert.ToInt32(fc["itemId"]), quantityOfItems = 0;

            try
            {
                quantityOfItems = Convert.ToInt32(fc["quantity"]);
            }
            catch (ArgumentOutOfRangeException)
            {
                quantityOfItems = 1;
            }

            var  clientsCart = (Cart)Session["Cart"];
            Item item        = _itemDistributionControl.GetItem(id);


            if (item == null)
            {
                return(RedirectToAction("Cart"));
            }

            if (clientsCart == null)
            {
                clientsCart = new Cart()
                {
                    ItemsInCart = new List <ItemsInCart>()
                };
                Session["Cart"] = clientsCart;
            }

            if ((clientsCart.ItemsInCart.FirstOrDefault(i => i.Item.Id == id) != null))
            {
                clientsCart.ItemsInCart.Where(x => x.Item.Id == id).ToList()
                .ForEach(y => y.Quantity += quantityOfItems);
            }
            else
            {
                ItemsInCart cartItem = new ItemsInCart()
                {
                    Cart     = (Cart)Session["Cart"],
                    Item     = item,
                    Quantity = quantityOfItems
                };
                clientsCart.ItemsInCart.Add(cartItem);
            }

            clientsCart.CartsPrice = clientsCart.CountCartsPrice(clientsCart.ItemsInCart);
            Session["Count"]       = clientCartControl.CountItemsInCart(clientsCart.ItemsInCart);
            return(Json(new { message = item.Name + "(" + quantityOfItems + ")" + " buvo prideta i krepseli ", itemCount = Session["Count"] }));
        }
        //GET: Admin/ItemInformation
        public ActionResult ItemInformation(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Item item = _itemDistributionControl.GetItem(id.Value);

            if (item == null)
            {
                return(HttpNotFound());
            }

            return(View(item));
        }
        public PaymentInformation ConfirmPayment(int clientId, Cart cart, string cardNumber, int expirationYear, int expirationMonth, string cardHolder, string cvv)
        {
            using (var dbContextScope = _dbContextScopeFactory.Create())
            {
                var foundClientObject = _clientRepository.GetClient(clientId);
                if (foundClientObject == null)
                {
                    throw new Exception($"There was no client found with the {clientId} id");
                }

                // Assigning the values to the required fields of the card
                foundClientObject.Card.CardNumber          = cardNumber;
                foundClientObject.Card.CardExpirationYear  = expirationYear;
                foundClientObject.Card.CardExpirationMonth = expirationMonth;
                foundClientObject.Card.CardHolder          = cardHolder;
                foundClientObject.Card.CVV = cvv;


                var paymentInformation = _httpPaymentControl.InitializePayment(foundClientObject.Card, cart.CartsPrice);

                cart.ItemsInCart.ToList().ForEach(x => x.Item = _itemDistributionControl.GetItem(x.Item.Id));

                var order = new ClientOrders {
                    Cart = cart, OrderDate = DateTime.Now, OrderStatus = paymentInformation.OrderStatus
                };
                foundClientObject.ClientOrders.Add(order);
                _clientRepository.EditClient(foundClientObject);

                // Making cards information default or blank (for now)
                foundClientObject.Card.CardNumber          = "4111111111111111";
                foundClientObject.Card.CardExpirationYear  = 2021;
                foundClientObject.Card.CardExpirationMonth = 1;
                foundClientObject.Card.CardHolder          = "Vardenis Pavardenis";
                foundClientObject.Card.CVV = "111";
                dbContextScope.SaveChanges();
                return(paymentInformation);
            }
        }