Esempio 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);
        }
Esempio n. 2
0
 public void Remove(int id)
 {
     using (manager = new MovieManager())
     {
         var movie = manager.GetById(id);
         if (movie != null)
         {
             Cart.Items.RemoveAll(x => x.Id == id);
         }
     }
 }
Esempio n. 3
0
 public void Add(int id)
 {
     using (manager = new MovieManager())
     {
         var movie = manager.GetById(id);
         if (movie != null)
         {
             Cart.Items.Add(movie);
         }
     }
 }