示例#1
0
        /// <summary>
        /// 分发管理员批准分发
        /// </summary>
        /// <param name="orderId"></param>
        public void StartDistribute(int orderId)
        {
            var currentOrder = (from c in DbContext.Orders where c.Id == orderId select c).ToList().First();

            currentOrder.Status = OrderStatus.AwaitingDelivery;
            DbContext.Orders.Attach(currentOrder);
            var orderEntry = DbContext.Entry(currentOrder);

            orderEntry.Property(e => e.Status).IsModified = true;
            DbContext.SaveChanges();
        }
示例#2
0
        public void GenerateOrder(string ISBN, int quantity, string orderOwner)
        {
            var book = (from c in DbContext.Books where c.ISBN == ISBN select c).ToList();

            if (!book.Any())
            {
                throw new Exception("找不到这本书");
            }

            var currentBook    = book.First();
            var relatedOrderId = new Guid().ToString();

            if (quantity > currentBook.Quantity)
            {
                var lackBooks = new T_LackBooks()
                {
                    ISBN           = currentBook.ISBN,
                    Quantity       = quantity - currentBook.Quantity,
                    Status         = LackBooksStatus.Unhandled,
                    RelatedOrderId = relatedOrderId
                };

                DbContext.LackBooks.Add(lackBooks);

                GenerateOutOfStockOrder(ISBN, quantity, orderOwner, relatedOrderId);
                DbContext.SaveChanges();
                throw new Exception($"该书库存不足 ISBN:{ISBN} 书名:{currentBook.Title}");
            }
            else
            {
                //减少库存
                currentBook.Quantity -= quantity;
                DbContext.Books.Attach(currentBook);
                var bookEntry = DbContext.Entry(currentBook);
                bookEntry.Property(e => e.Quantity).IsModified = true;

                //新建一个订单
                var order = new T_Order()
                {
                    OrderOwner = orderOwner,
                    ISBN       = ISBN,
                    Quantity   = quantity,
                    Status     = OrderStatus.Unhandled
                };
                DbContext.Orders.Add(order);


                DbContext.SaveChanges();
            }
        }
示例#3
0
        public void SendNotification(string from, string to, string content, NotificationStatus status)
        {
            var notification = new T_Notification()
            {
                From    = from,
                To      = to,
                Content = content,
                Status  = status
            };

            DbContext.Notifications.Add(notification);
            DbContext.SaveChanges();
        }