Beispiel #1
0
        public async Task <int> AddAsync(OrderDetail orderDetail)
        {
            _dbContext.OrderDetails.Add(orderDetail);
            await _dbContext.SaveChangesAsync();

            return(orderDetail.OrderDetailID);
        }
        public async Task <int> AddAsync(ShipAddress address)
        {
            _dbContext.ShipAddress.Add(address);
            await _dbContext.SaveChangesAsync();

            return(address.AddressID);
        }
 /// <summary>
 /// 添加商品图像
 /// </summary>
 /// <param name="productImage">商品图像</param>
 /// <returns></returns>
 public async Task <int> AddAsync(ProductImage productImage)
 {
     if (null == productImage)
     {
         return(-1);
     }
     _dbContext.ProductImages.Add(productImage);
     return(await _dbContext.SaveChangesAsync());
 }
        /// <summary>
        /// 添加生产商
        /// </summary>
        /// <param name="brand">生产商</param>
        /// <returns></returns>
        public async Task <int> AddAsync(Brand brand)
        {
            if (null == brand)
            {
                return(-1);
            }
            _dbContext.Brands.Add(brand);
            await _dbContext.SaveChangesAsync();

            return(brand.BrandID);
        }
        public async Task <int> AddAsync(Category category)
        {
            if (null == category)
            {
                return(-1);
            }
            _dbContext.Categories.Add(category);
            await _dbContext.SaveChangesAsync();

            return(category.CategoryID);
        }
Beispiel #6
0
        public async Task <Guid> AddAsync(Product product)
        {
            if (null == product)
            {
                return(Guid.Empty);
            }
            _dbContext.Products.Add(product);
            await _dbContext.SaveChangesAsync();

            return(product.ProductID);
        }
Beispiel #7
0
        public async Task <IActionResult> Create(Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Categories.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
Beispiel #8
0
        public async Task <Guid> AddAsync(Order order)
        {
            if (null == order)
            {
                return(Guid.Empty);
            }
            _dbContext.Orders.Add(order);
            await _dbContext.SaveChangesAsync();

            return(order.OrderID);
        }
        public async Task <int> AddAsync(CartItem cartItem)
        {
            if (cartItem.UserID == "anonymous")
            {
                if (_dbContext.CartItems.Count(c => c.SessionID == cartItem.SessionID) > _MaxCartItemCount)
                {
                    return(0);
                }
            }
            else
            {
                if (_dbContext.CartItems.Count(c => c.UserID == cartItem.UserID) > _MaxCartItemCount)
                {
                    return(0);
                }
            }
            CartItem existedCartItem = null;

            if (cartItem.UserID == "anonymous")
            {
                existedCartItem = await _dbContext.CartItems.FirstOrDefaultAsync(
                    c => c.SessionID == cartItem.SessionID && c.ProductID == cartItem.ProductID);
            }
            else
            {
                existedCartItem = await _dbContext.CartItems.FirstOrDefaultAsync(
                    c => c.UserID == cartItem.UserID && c.ProductID == cartItem.ProductID);
            }
            if (null != existedCartItem)
            {
                existedCartItem.Quantity      += cartItem.Quantity;
                existedCartItem.ProductName    = cartItem.ProductName;
                existedCartItem.ThumbImagePath = cartItem.ThumbImagePath;
                existedCartItem.UnitPrice      = cartItem.UnitPrice;
                existedCartItem.SubTotal       = existedCartItem.Quantity * existedCartItem.UnitPrice;
                _dbContext.CartItems.Update(existedCartItem);
            }
            else
            {
                _dbContext.CartItems.Add(cartItem);
            }
            return(await _dbContext.SaveChangesAsync());
        }