public async Task<ActionResult> AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }

                order.Username = User.Identity.Name;
                order.OrderDate = DateTime.UtcNow;

                await _databaseHelper.SaveOrderAsync(order);
                await _databaseHelper.CreateOrderAsync(order, _cartId);

                return RedirectToAction("Complete", new { id = order.Id });
            }
            catch (Exception)
            {
                return View(order);
            }
        }
Beispiel #2
0
 public async Task SaveOrderAsync(Order order)
 {
     _context.Orders.Add(order);
     await _context.SaveChangesAsync();
 }
Beispiel #3
0
        public async Task<int> CreateOrderAsync(Order order, string shoppingCartId)
        {
            var orderTotal = 0m
                ;

            var cartItems = await GetCartItemsAsync(shoppingCartId);
            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail()
                {
                    AlbumId = item.AlbumId,
                    OrderId = order.Id,
                    UnitPrice = item.Album.Price,
                    Quantity = item.Count
                };

                orderTotal += (item.Count*item.Album.Price);
                _context.OrderDetails.Add(orderDetail);
            }

            order.Total = orderTotal;

            await _context.SaveChangesAsync();
            await EmptyCartAsync(shoppingCartId);
            return order.Id; 
        }