Exemplo n.º 1
0
        public async Task <Review> Add(Review entity)
        {
            _bookstoreDbContext.Add(entity);
            await _bookstoreDbContext.SaveChangesAsync();

            return(entity);
        }
Exemplo n.º 2
0
        public void CreateOrder(Order order, StoreUser storeUser)
        {
            // var transaction = _bookstoreDbContext.Database.BeginTransaction();
            // try
            {
                order.OrderDate   = DateTime.Now;
                order.OrderNumber = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()
                                    + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString()
                                    + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
                order.User       = storeUser;
                order.OrderTotal = _shoppingCart.GetShoppingCartTotal();
                order.Condidtion = "Created";
                _bookstoreDbContext.Add(order);
                _bookstoreDbContext.SaveChanges();
                var shoppingCartItems = _shoppingCart.ShoppingCartItems;

                foreach (var item in shoppingCartItems)
                {
                    var orderItem = new OrderItem()
                    {
                        BookId  = item.Book.Id,
                        OrderId = order.Id,
                        Price   = item.Book.Price * item.Amount,
                        Amount  = item.Amount
                    };
                    //var itemStorage = _bookstoreDbContext.Storages.FirstOrDefault(s => s.BookId == item.Book.Id);
                    //itemStorage.Amount = itemStorage.Amount - orderItem.Amount;

                    // _bookstoreDbContext.Storages.Update(itemStorage);
                    _bookstoreDbContext.OrderItems.Add(orderItem);
                }
                _bookstoreDbContext.SaveChanges();

                //     transaction.Commit();
            }
            //catch (Exception e)
            //{
            //    transaction.Rollback();
            //}
        }