Exemplo n.º 1
0
        public async Task AddViewCount(int productId)
        {
            var product = await _context.Products.FindAsync(productId);

            product.ViewCount += 1;
            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
 public async Task AddUser(User user)
 {
     if (user == null)
     {
         throw new ArgumentNullException();
     }
     _context.Users.Add(user);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 3
0
 public async Task AddProduct(Product product)
 {
     if (product == null)
     {
         throw new ArgumentNullException();
     }
     _context.Products.Add(product);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 4
0
 public async Task AddOrder(Order order)
 {
     if (order == null)
     {
         throw new ArgumentNullException();
     }
     _context.Orders.Add(order);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 5
0
        public async Task AddCartItem(string email, int productId, int quantity)
        {
            var shoppingCart = await GetExistingOrCreateNewShoppingCart(email);

            var product = _context.Products.Where(x => x.ProductId == productId).FirstOrDefault();

            shoppingCart.AddItem(productId, quantity, product.Price);
            await _context.SaveChangesAsync();

            await CalculateTotalPrice(shoppingCart);
        }
Exemplo n.º 6
0
        public async Task <int> Create(CheckoutRequest request)
        {
            var orderDetails = new List <OrderDetail>();

            foreach (var item in request.OrderDetailViewModel)
            {
                orderDetails.Add(new OrderDetail()
                {
                    ProductId = item.ProductId,
                    Quantity  = item.Quantity,
                    Price     = item.Price
                });
            }

            var order = new Order()
            {
                UserId          = request.UserId != null ? request.UserId: Guid.NewGuid(),
                ShipName        = request.Name,
                ShipAddress     = request.Address,
                ShipEmail       = request.Email,
                ShipPhoneNumber = request.PhoneNumber,
                OrderDate       = DateTime.Now,
                Status          = request.UserId != null? OrderStatus.InProgress : OrderStatus.Pending, //
                OrderDetails    = orderDetails
            };

            _context.Orders.Add(order);
            await _context.SaveChangesAsync();

            return(order.Id);
        }
        public async Task <int> Create(ProductCreateRequest request)
        {
            var product = new Product()
            {
                Price = request.Price,
            };

            _context.Products.Add(product);
            return(await _context.SaveChangesAsync());
        }
Exemplo n.º 8
0
        public async Task <int> AddImage(int productId, ProductImageCreateRequest request)
        {
            var productImage = new ProductImage()
            {
                Caption     = request.Caption,
                DateCreated = DateTime.Now,
                IsDefault   = request.IsDefault,
                ProductId   = productId,
                SortOrder   = request.SortOrder
            };

            if (request.ImageFile != null)
            {
                productImage.ImagePath = await this.SaveFile(request.ImageFile);

                productImage.FileSize = request.ImageFile.Length;
            }
            _context.ProductImages.Add(productImage);
            await _context.SaveChangesAsync();

            return(productImage.Id);
        }