Ejemplo n.º 1
0
        public int AddOrder(Models.User user, List <Models.Movie> movies)
        {
            MovieManager movieManager = new MovieManager();

            Data.User userFind = db.Users.FirstOrDefault(x => x.Id == user.Id);

            Data.Order newOrder = new Data.Order();
            newOrder.OrderDate      = DateTime.UtcNow;
            newOrder.PaymentReceipt = true;
            newOrder.ShipDate       = DateTime.UtcNow;
            newOrder.User           = userFind;

            db.Orders.Add(newOrder);
            db.SaveChanges();
            int orderId = newOrder.Id;

            foreach (var item in movies)
            {
                Data.Movie movie = db.Movies.SingleOrDefault(d => d.Id == item.Id);

                Data.OrderItem newOrderItem = new Data.OrderItem();
                newOrderItem.Order    = newOrder;
                newOrderItem.Movie    = movie;
                newOrderItem.Quantity = 1;
                db.OrderItems.Add(newOrderItem);
            }

            db.SaveChanges();

            return(orderId);
        }
Ejemplo n.º 2
0
 public static OrderItem Map(Data.OrderItem orderItem)
 {
     if (orderItem == null)
     {
         return(null);
     }
     return(new OrderItem(Map(orderItem.Item), orderItem.Quantity, orderItem.Msg));
 }
Ejemplo n.º 3
0
        //pay
        public async Task <IActionResult> OnPostChargeAsync(string stripeEmail, string stripeToken, long amount)
        {
            var customers = new CustomerService();
            var charges   = new ChargeService();
            var customer  = customers.Create(new CustomerCreateOptions {
                Email = stripeEmail, SourceToken = stripeToken
            });
            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount      = amount,
                Description = "J41564 Food Order Charge",
                Currency    = "gbp",
                CustomerId  = customer.Id
            });

            var currentOrder = _db.OrderHistories.FromSql("SELECT * From OrderHistories").OrderByDescending(b => b.OrderNo).FirstOrDefault();

            if (currentOrder == null)
            {
                Order.OrderNo = 1;
            }
            else
            {
                Order.OrderNo = currentOrder.OrderNo + 1;
            }

            var user = await _UserManager.GetUserAsync(User);

            Order.Email = user.Email;
            _db.OrderHistories.Add(Order);
            CheckoutCustomer checkoutCustomer = await _db.CheckoutCustomers.FindAsync(user.Email);

            var basketItems = _db.BasketItems.FromSql("SELECT * FROM BasketItems WHERE BasketID = {0}", checkoutCustomer.BasketID).ToList();

            foreach (var item in basketItems)
            {
                MenuItem = await _db.MenuItems.FindAsync(item.MenuID);

                MenuItem.Stock -= item.Quantity;
                await _db.SaveChangesAsync();

                Data.OrderItem orderItem = new Data.OrderItem
                {
                    OrderNo  = Order.OrderNo,
                    MenuID   = item.MenuID,
                    Quantity = item.Quantity
                };
                _db.OrderItems.Add(orderItem);
                _db.BasketItems.Remove(item);
            }

            await _db.SaveChangesAsync();

            return(RedirectToPage("/Index", "Payment"));
        }
        void IOrder.AddOrderLine(OrderItems OrderItemLineList)
        {
            Data.OrderItem orderline = new  Data.OrderItem()
            {
                Orderid   = OrderItemLineList.Orderid,
                Productid = OrderItemLineList.Productid,
                Quantity  = (int)OrderItemLineList.Quantity
            };



            _context.Add(orderline);
            _context.SaveChanges();
        }
Ejemplo n.º 5
0
        public void TestDataOrderItem()
        {
            Data.OrderItem item = new Data.OrderItem()
            {
                Item = new Data.MenuItem()
                {
                    DestinationId = 4,
                    ItemName      = "Taco",
                    Cost          = 1
                },
                Quantity = 1,
                Msg      = ""
            };
            var expected = Mapper.Map(item);

            Assert.NotNull(expected);
        }
        public async Task <IActionResult> OnPostBuyAsync(int itemID)
        {
            var currentOrder = _db.OrderHistories.FromSql("SELECT * From OrderHistories").OrderByDescending(b => b.OrderNo).FirstOrDefault();

            if (currentOrder == null)
            {
                Order.OrderNo = 1;
            }
            else
            {
                Order.OrderNo = currentOrder.OrderNo + 1;
            }

            var user = await _UserManager.GetUserAsync(User);

            Order.Email = user.Email;
            _db.OrderHistories.Add(Order);

            CheckoutCustomer customer = await _db
                                        .CheckoutCustomers
                                        .FindAsync(user.Email);

            var basketItems =
                _db.BasketItems
                .FromSql("SELECT * From BasketItems " +
                         "WHERE BasketID = {0}", customer.BasketID)
                .ToList();

            Total = 0;

            foreach (var item in basketItems)
            {
                Data.OrderItem oi = new Data.OrderItem
                {
                    OrderNo  = Order.OrderNo,
                    StockID  = item.StockID,
                    Quantity = item.Quantity
                };

                _db.OrderItems.Add(oi);
            }

            await _db.SaveChangesAsync();

            return(RedirectToPage("/Index"));
        }
Ejemplo n.º 7
0
        public static Data.OrderItem MapActive(OrderItem orderItem, int orderId)
        {
            if (orderItem == null)
            {
                return(null);
            }
            var i = new Data.OrderItem
            {
                Msg      = orderItem.Message,
                Quantity = orderItem.Quantity
            };

            if (orderItem.Item.Id > -1)
            {
                i.ItemId = orderItem.Item.Id;
            }
            if (orderId > -1)
            {
                i.OrderId = orderId;
            }
            return(i);
        }