コード例 #1
0
        /// <summary>
        /// Преобразует корзину в заказ и сохраняет его в бд
        /// </summary>
        /// <param name="shoppingCart"></param>
        /// <param name="customerId"></param>
        /// <returns></returns>
        private async Task <long> CreateNewOrder(List <Pizza> shoppingCart, string customerId)
        {
            Order newOrder = new()
            {
                CustomerId  = long.Parse(customerId),
                DateCreated = DateTime.Now.ToString()
            };

            _context.Add(newOrder);

            await _context.SaveChangesAsync();

            await _context.Entry(newOrder).GetDatabaseValuesAsync();

            foreach (var pizza in shoppingCart)
            {
                OrderPizza orderPizza = new() { PizzaId = pizza.Id, OrderId = newOrder.Id };

                _context.Add(orderPizza);

                newOrder.OrderPizzas.Add(orderPizza);
            }

            await _context.SaveChangesAsync();

            return(newOrder.Id);
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,DateCreated,Amount,CustomerId")] Payment payment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(payment);
                await _context.SaveChangesAsync();

                await _context.Entry(payment).GetDatabaseValuesAsync();

                return(RedirectToAction("ThankYou", "Payments", new { paymentId = payment.Id }));
            }
            return(View(payment));
        }