Beispiel #1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new Music_Store.Models.MovieContext())
     {
         try
         {
             int             CartItemCount = CartItemUpdates.Count();
             List <CartItem> myCart        = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 // Iterate through all rows within shopping cart list
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.Movie.MovieID == CartItemUpdates[i].ProductId)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.MovieID);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.MovieID, CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Beispiel #2
0
        public IQueryable <Genre> GetGenres()
        {
            var _db = new Music_Store.Models.MovieContext();
            IQueryable <Genre> query = _db.Genres;

            return(query);
        }
Beispiel #3
0
        public IQueryable <Movie> GetMovies([QueryString("id")] int?genreId)
        {
            var _db = new Music_Store.Models.MovieContext();
            IQueryable <Movie> query = _db.Movies;

            if (genreId.HasValue && genreId > 0)
            {
                query = query.Where(p => p.GenreID == genreId);
            }
            return(query);
        }
Beispiel #4
0
        public IQueryable <Movie> GetMovies([QueryString("movieId")] int?movieId)
        {
            var _db = new Music_Store.Models.MovieContext();
            IQueryable <Movie> query = _db.Movies;

            if (movieId.HasValue && movieId > 0)
            {
                query = query.Where(p => p.MovieID == movieId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
Beispiel #5
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new Music_Store.Models.MovieContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Movie.MovieID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.Quantity = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Beispiel #6
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new Music_Store.Models.MovieContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Movie.MovieID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }