コード例 #1
0
        public ActionResult Payment(Order order)
        {
            if (order != null)
            {
                _context.Orders.Add(order);
                _context.SaveChanges();
                var o = _context.Orders.ToList().LastOrDefault();

                foreach (var movie in (List <Movie>)Session["CartMovies"])
                {
                    OrderRows orderRows = new OrderRows
                    {
                        MovieId = movie.Id,
                        OrderId = o.Id,
                        Price   = movie.Price
                    };

                    _context.OrderRows.Add(orderRows);
                    _context.SaveChanges();
                }
            }

            Session["CartMovies"] = null;
            TempData["Message"]   = "Your order has been placed!";
            return(RedirectToAction("Orders", "Customer"));
        }
コード例 #2
0
        public void CreateOrder(HomeCheckoutVM model, ClaimsPrincipal user)
        {
            string currentUserAspId;
            Users  currentUser;

            if (user.Identity.IsAuthenticated)
            {
                currentUserAspId = userManager.GetUserId(user);
                currentUser      = context.Users.Single(u => u.AspNetId == currentUserAspId);
            }
            else
            {
                currentUser = new Users {
                    Id = -1
                }
            };

            var    cart  = ShoppingCart.GetCart();
            Orders order = new Orders
            {
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Email       = model.Email,
                PhoneNumber = model.PhoneNumber,
                Address     = model.Address,
                City        = model.City,
                PostalCode  = model.PostalCode.Value,
                Status      = 1,
                OrderDate   = DateTime.Now
            };

            if (user.Identity.IsAuthenticated)
            {
                order.UserId = currentUser.Id;
            }

            context.Orders.Add(order);
            foreach (var item in cart)
            {
                OrderRows orderRow = new OrderRows
                {
                    BoxId = item.Id,
                    Order = order
                };
                ItemIsBought(item);
                context.OrderRows.Add(orderRow);
            }
            context.SaveChanges();
            cart.Clear();
        }
コード例 #3
0
        public async Task <IActionResult> MyList(int status = 0, int page = 1)
        {
            int[] s     = { 1, 10, 99 };
            var   query = _context.OrderRecords
                          .Where(o => s.Contains(o.Status));

            if (status != 0)
            {
                query = query.Where(o => o.Status == status);
            }

            query = query.OrderByDescending(o => o.OrderDate);

            var orderList = await query.Skip((page - 1) * 10).Take(10).ToListAsync();

            var orderIds = orderList.Select(o => o.Id).ToArray();

            var orderDetailList = await _context.OrderRecordDetails
                                  .Where(o => orderIds.Contains(o.OrderId))
                                  .ToListAsync();

            List <OrderRows> list = new List <OrderRows>();

            foreach (var item in orderList)
            {
                var row = new OrderRows();
                row.OrderRecord           = item;
                row.OrderRecordDetailList = orderDetailList.Where(o => o.OrderId == item.Id).ToList();
                list.Add(row);
            }

            var res = new ResultModel()
            {
                Code = 100,
                Data = list
            };

            return(Json(res));
        }
コード例 #4
0
 public override CreateOrderBuilder AddOrderRow(OrderRowBuilder itemOrderRow)
 {
     OrderRows.Add(itemOrderRow);
     return(this);
 }
コード例 #5
0
 public override CreateOrderBuilder AddOrderRows(IEnumerable <OrderRowBuilder> itemOrderRow)
 {
     OrderRows.AddRange(itemOrderRow);
     return(this);
 }