예제 #1
0
        public async Task <IActionResult> OnPostDelAsync(int purchase)
        {
            Models.Book book = _context.Book.Find(_context.Purchase.Find(purchase).BookId);

            if (_context.Purchase.Find(purchase).PurStatus == 1)
            {
                _context.Purchase.Remove(_context.Purchase.Find(purchase));
                _context.SaveChanges();
                Console.WriteLine("已完成,不修改数据库" + book.Quantity);
            }
            else if (_context.Purchase.Find(purchase).PurStatus == 0)
            {
                Console.WriteLine("修改前" + book.Quantity);

                book.Quantity += _context.Purchase.Find(purchase).PurQuan;

                _context.Book.Update(book);
                _context.Purchase.Remove(_context.Purchase.Find(purchase));

                _context.SaveChanges();
                Console.WriteLine("修改后" + book.Quantity);
            }

            return(RedirectToPage());
        }
예제 #2
0
 /// <summary>
 /// 对订单加书目购物车信息
 /// </summary>
 /// <param name="order"></param>
 /// <param name="purchase"></param>
 /// <returns></returns>
 public Task <bool> Add(int order, Purchase purchase)
 {
     return(Task.Run(function: () =>
     {
         _purchases.Add(purchase);
         _context.Purchase.Add(purchase);
         _context.Order.Where(x => x.OrderNo == order).FirstOrDefault().OrderPrice += purchase.PurQuan * purchase.PurPrice;
         _context.SaveChanges();
         return true;
     }));
 }
예제 #3
0
 public Task <bool> Add(Order order)
 {
     return(Task.Run(function: () =>
     {
         _order.Add(order);
         _context.Order.Add(order);
         _context.SaveChanges();
         return true;
     }));
 }
예제 #4
0
        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public Task <bool> Add(User user)
        {
            return(Task.Run(function: () =>
            {
                if (ExistUser(user.UserName).Result)
                {
                    return false;
                }

                _users.Add(user);
                _context.User.Add(user);
                _context.SaveChanges();
                return true;
            }));
        }
예제 #5
0
        public async Task <bool> SaleOut(string bookName, int bookCount)
        {
            Book?aBook = await GetByBookName(bookName);

            //找不到书籍
            if (aBook == null)
            {
                return(false);
            }

            //数量不足
            int i = aBook.Quantity - bookCount;

            if (i < 0)
            {
                return(false);
            }

            //成功修改
            aBook.Quantity = aBook.Quantity - bookCount;
            _context.SaveChanges();
            return(true);
        }