示例#1
0
        public IActionResult RemoveFromCart(int id)
        {
            try
            {
                CartModel cart = this.GetCart();

                CartLineModel model = cart.Items.Where(i => i.ProjectCase.Id == id).FirstOrDefault();

                if (model != null)
                {
                    if (model.Quantity > 1)
                    {
                        model.Quantity--;
                    }
                    else
                    {
                        cart.Items.Remove(model);
                    }
                }

                TempData["ItemRemoved"] = model != null;

                cart = this.UpdateCart(cart);

                return(View("Cart", cart));
            }
            catch (Exception ex)
            {
                return(View("Error", new ErrorViewModel {
                    Message = ex.Message
                }));
            }
        }
        public CartLineModel Initialize(CartLine model)
        {
            Assert.ArgumentNotNull(model, nameof(model));

            var result = new CartLineModel();

            result.Id = model.ExternalCartLineId;

            var commerceCartProduct = model.Product as CommerceCartProduct;

            var product = this.catalogRepository.GetProduct(model.Product.ProductId);

            result.Product  = product;
            result.Variant  = product.Variants?.FirstOrDefault(x => x.ProductVariantId == commerceCartProduct?.ProductVariantId);
            result.Quantity = model.Quantity;

            var price = new CartPriceModel();

            price.Initialize(model.Total, this.currencyProvider);
            result.Price = price;

            result.Temp = model;

            return(result);
        }
示例#3
0
        public IHttpActionResult EditCartLineDB(int idc, CartLineModel p)
        {
            CartLine cartLine = serviceCartLine.GetById(idc);

            cartLine.prixTotal       = (cartLine.prixDuProduit * p.quantiteChoisie);
            cartLine.quantiteChoisie = p.quantiteChoisie;
            serviceCartLine.Update(cartLine);
            serviceCartLine.Commit();

            return(Ok());
        }
        public OrderDisplayViewModel(OrderModel order, IMapper mapper, ICallEndpoint callEndpoint, IEventAggregator events)
        {
            this.mapper       = mapper;
            this.order        = mapper.Map <OrderDisplayModel>(order);
            this.callEndpoint = callEndpoint;
            this.events       = events;
            this.newCartLine  = new CartLineModel {
                Quantity = 1, OrderId = order.Id
            };

            IncreaseProductQuantityCommand = new Command(IncreaseProductQuantity, _ => true);
            ReduceProductQuantityCommand   = new Command(ReduceProductQuantity, _ => true);
            RemoveProductFromCartCommand   = new Command(RemoveProductFromCart, _ => true);
        }
示例#5
0
        public async Task <CartModel> AddToCart(CartLineModel model, string userId)
        {
            model  = model ?? throw new ArgumentNullException(nameof(model));
            userId = userId ?? throw new ArgumentNullException(nameof(userId));

            try
            {
                //Cart entity = await this.repo.AddToCart(model.ToEntity(), userId).ConfigureAwait(false);

                //CartModel addedModel = new CartModel();
                //addedModel.ToModel(entity);

                //return addedModel;
                return(null);
            }
            catch
            {
                throw;
            }
        }
示例#6
0
        public async Task <IActionResult> AddToCart(int id, int quantity = 1)
        {
            try
            {
                CartModel cart = this.GetCart();

                ProjectCaseModel model = await this.projectManagement.GetProjectCaseByIdAsync(id);

                if (model != null)
                {
                    CartLineModel existsItem = cart.Items.Where(i => i.ProjectCase.Id == id).FirstOrDefault();
                    if (existsItem != null)
                    {
                        existsItem.Quantity += quantity;
                    }
                    else
                    {
                        cart.Items.Add(new CartLineModel {
                            ProjectCase = model, Quantity = quantity
                        });
                    }

                    cart = this.UpdateCart(cart);
                }

                TempData["ItemAdded"] = model != null;

                return(View("Cart", cart));
            }
            catch (Exception ex)
            {
                return(View("Error", new ErrorViewModel {
                    Message = ex.Message
                }));
            }
        }