Ejemplo n.º 1
0
        public IHttpActionResult Get_Cart()
        {
            var user_id     = User.Identity.GetUserId();
            var productCart = db.ProductCarts.Where(pc => pc.Cart_Id == user_id).ToList();


            ProductCartDto    productCartDto = new ProductCartDto();
            List <ProductDto> productDtoList = new List <ProductDto>();

            foreach (var item in productCart)
            {
                var        product    = db.Products.Find(item.Product_Id);
                ProductDto productDto = new ProductDto();
                productDto.Image       = product.Image;
                productDto.Name        = product.Name;
                productDto.Price       = product.Price;
                productDto.Quentity    = item.Quntity;
                productDto.Discount    = product.Discount;
                productDto.Description = product.Description;
                productDtoList.Add(productDto);
            }
            productCartDto.Productss = productDtoList;

            return(Ok(productCartDto));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Post([FromBody] ProductCartDto pcnew)
        {
            try
            {
                ProductCart pc = _mapper.Map <ProductCart>(pcnew);

                var cartIdCheck    = _context.Carts.Where(p => p.CartId == pcnew.cartIndex);
                var productIdCheck = _context.Products.Where(p => p.ProductID == pcnew.productIndex);
                if (cartIdCheck == null)
                {
                    return(NoContent());
                }
                if (productIdCheck == null)
                {
                    return(NoContent());
                }

                _context.ProductCarts.Add(pc);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(418, ex.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <ServiceResponse> GetCartItem(long userId)
        {
            try
            {
                List <ProductCartDto> dto = new List <ProductCartDto>();
                var cartItem = _context.Cart.Where(x => x.UserId == userId).ToList();
                if (cartItem.Count() != 0)
                {
                    foreach (var item in cartItem)
                    {
                        var productData = await _context.ProductMaster.Where(x => x.Id == item.ProductId).FirstOrDefaultAsync();

                        var filename = await _context.ProductsImage.Where(x => x.ProductId == item.ProductId).Select(x => x.ImageName).FirstOrDefaultAsync();

                        // item.Quantity
                        //var res=_mapper.Map<ProductDto>(productData);
                        ProductCartDto cartDto = new ProductCartDto();


                        cartDto.Quantity          = item.Quantity;
                        cartDto.ProductName       = productData.ProductName;
                        cartDto.ProducDescription = productData.ProducDescription;
                        cartDto.Price             = productData.Price;
                        cartDto.FileName          = filename;
                        cartDto.TotalCount        = cartDto.Price * cartDto.Quantity;
                        cartDto.ProductId         = productData.Id;
                        cartDto.Id = item.Id;



                        dto.Add(cartDto);
                    }



                    return(new ServiceResponse {
                        status = 1, isSuccess = true, message = "cart data", jsonObj = dto, totalCount = cartItem.Count()
                    });
                }
                else
                {
                    return(new ServiceResponse {
                        status = 0, isSuccess = true, message = "Cart is empty"
                    });
                }
            }
            catch (Exception e)
            {
                return(new ServiceResponse {
                    status = -1, isSuccess = false, message = CommonMessages.SomethingWrong
                });
            }
        }
Ejemplo n.º 4
0
        public IActionResult EditCartItemQuantity([FromBody] ProductCartDto productCartModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (CartRepository.SaveProductToCart(productCartModel.ProductId, UserId, productCartModel.Quantity))
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }