Exemplo n.º 1
0
        private async Task <CartItem> ValidateItem(Guid productId, CartCustomer cart, CartItem item = null)
        {
            if (item != null && productId != item.ProductId)
            {
                AddErrorInProcess("The item does not correspond to the informed");
                return(null);
            }

            if (cart == null)
            {
                AddErrorInProcess("Cart not found");
                return(null);
            }

            var itemCart = await _cartDbContext.CartItems
                           .FirstOrDefaultAsync(i => i.CartId == cart.Id && i.ProductId == productId);

            if (itemCart == null || !cart.CartItemExisting(itemCart))
            {
                AddErrorInProcess("The item is not in the cart");
                return(null);
            }

            return(itemCart);
        }
Exemplo n.º 2
0
        private void ManipulateNewCart(CartItem item)
        {
            var cart = new CartCustomer(_user.GetUserId());

            cart.AddNewItem(item);

            ValidateCart(cart);
            _cartDbContext.CartCustomers.Add(cart);
        }
Exemplo n.º 3
0
        private bool ValidateCart(CartCustomer cart)
        {
            if (cart.IsValid())
            {
                return(true);
            }

            cart.ValidationResult.Errors.ToList().ForEach(e => AddErrorInProcess(e.ErrorMessage));
            return(false);
        }
Exemplo n.º 4
0
 // GET: Customer
 public ActionResult Index()
 {
     if (Authenticate.IsAuthenticated())
     {
         cc            = new CartCustomer();
         ViewBag.Title = "Assign to Customer";
         cc.Customers  = CustomerManager.Load();
         cc.Cart       = (ShoppingCart)Session["cart"];
         return(View(cc));
     }
     else
     {
         return(RedirectToAction("Login", "User", new { returnurl = HttpContext.Request.Url }));
     }
 }
Exemplo n.º 5
0
        private void ManipulateExistingCart(CartCustomer cart, CartItem item)
        {
            var productExisting = cart.CartItemExisting(item);

            cart.AddNewItem(item);
            ValidateCart(cart);

            if (productExisting)
            {
                _cartDbContext.CartItems.Update(cart.GetProductById(item.ProductId));
            }
            else
            {
                _cartDbContext.CartItems.Add(item);
            }

            _cartDbContext.CartCustomers.Update(cart);
        }
        private static CartCustomerResponse MapCartCustomerToProtoResponse(CartCustomer cart)
        {
            var cartProto = new CartCustomerResponse
            {
                Id           = cart.Id.ToString(),
                Customerid   = cart.CustomerId.ToString(),
                Totalvalue   = (double)cart.TotalValue,
                Discount     = (double)cart.Discount,
                Voucherusage = cart.VoucherUsage,
            };

            if (cart.Voucher != null)
            {
                cartProto.Voucher = new VoucherResponse
                {
                    Code = cart.Voucher.Code,
                    Discountpercentage = (double?)cart.Voucher.DiscountPercentage ?? 0,
                    Discountvalue      = (double?)cart.Voucher.DiscountValue ?? 0,
                    Discounttype       = (int)cart.Voucher.DiscountType
                };
            }

            foreach (var item in cart.Items)
            {
                cartProto.Items.Add(new CartitemsResponse
                {
                    Id        = item.Id.ToString(),
                    Name      = item.Name,
                    Image     = item.Image,
                    Productid = item.ProductId.ToString(),
                    Quantity  = item.Quantity,
                    Value     = (double)item.Value
                });
            }

            return(cartProto);
        }