Exemplo n.º 1
0
        public void CreateOrder(Order order, StoreUser user)
        {
            //var transaction = _wormDbContext.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       = user;
            order.OrderTotal = _shoppingCart.GetShoppingCartTotal();
            order.Condidtion = "Created";
            _wormDbContext.Add(order);

            var shoppingCartItems = _shoppingCart.ShoppingCartItems;

            foreach (var item in shoppingCartItems)
            {
                var orderItem = new OrderItem()
                {
                    ProductId = item.Product.Id,
                    OrderId   = order.Id,
                    Price     = item.Product.Price * item.Amount,
                    Amount    = item.Amount
                };
                //    var itemStorage = _wormDbContext.Store.FirstOrDefault(s => s.ProductId == item.Product.Id);
                //    itemStorage.Amount = itemStorage.Amount - orderItem.Amount;
                //    _wormDbContext.Store.Update(itemStorage);

                _wormDbContext.OrderItems.Add(orderItem);
            }
            _wormDbContext.SaveChanges();
            //    transaction.Commit();
            //}
            //catch (Exception e)
            //{
            //    transaction.Rollback();
            //}
        }
Exemplo n.º 2
0
 public Product CreateProduct(Product product)
 {
     _wormDbContext.Add(product);
     _wormDbContext.SaveChanges();
     return(product);
 }
Exemplo n.º 3
0
 public Artist CreateArtist(Artist artist)
 {
     _wormDbContext.Add(artist);
     _wormDbContext.SaveChanges();
     return(artist);
 }