コード例 #1
0
        public void AddToCart(Album album, string shoppingCartId)
        {
            using (var session = NHibernateBase.OpentSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    Cart cartItem = session.QueryOver <Cart>()
                                    .Where(c => c.CartId == shoppingCartId)
                                    .And(c => c.Album.Id == album.Id)
                                    .SingleOrDefault();

                    if (cartItem == null)
                    {
                        cartItem = new Cart
                        {
                            Album       = album,
                            CartId      = shoppingCartId,
                            Count       = 1,
                            DateCreated = DateTime.Now
                        };
                        session.Save(cartItem);
                    }

                    else
                    {
                        cartItem.Count++;
                        session.Update(cartItem);
                    }

                    tx.Commit();
                }
            }
        }
コード例 #2
0
        public int RemoveFromCart(int id, string shoppingCartId)
        {
            using (var session = NHibernateBase.OpentSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    var cartItem = session.QueryOver <Cart>()
                                   .Where(c => c.Id == id && c.CartId == shoppingCartId)
                                   .JoinQueryOver(c => c.Album)
                                   .SingleOrDefault();

                    int itemCount = 0;

                    if (cartItem != null)
                    {
                        if (cartItem.Count > 1)
                        {
                            cartItem.Count--;
                            itemCount = cartItem.Count;
                            session.Update(cartItem);
                        }
                        else
                        {
                            session.Delete(cartItem);
                        }

                        tx.Commit();
                    }

                    return(itemCount);
                }
            }
        }
コード例 #3
0
 public Genre GetGenreByName(string name)
 {
     using (var session = NHibernateBase.OpentSession())
     {
         var queryOver = GetQueryForGenre(name);
         return(queryOver.GetExecutableQueryOver(session).SingleOrDefault());
     }
 }
コード例 #4
0
 public IList <Album> GetAlbumsByGenre(string genre)
 {
     using (var session = NHibernateBase.OpentSession())
     {
         var queryOver = GetQueryOverByArtistOrGenre(genre);
         return(queryOver.GetExecutableQueryOver(session).List());
     }
 }
コード例 #5
0
        public Album GetAlbumWithGenreById(int id)
        {
            var queryOver = GetQueryOverByArtistOrGenre("", "", id);

            using (var session = NHibernateBase.OpentSession())
            {
                return(queryOver.GetExecutableQueryOver(session).SingleOrDefault());
            }
        }
コード例 #6
0
        public IList <Album> GetAllAlbums()
        {
            var queryOver = GetQueryOverByArtistOrGenre();

            using (var session = NHibernateBase.OpentSession())
            {
                return(queryOver.GetExecutableQueryOver(session).List());
            }
        }
コード例 #7
0
        public Cart GetUniqueCartWithAlbumByCartId(int id)
        {
            var query = GetQueryOverByCartId("", id);

            using (var session = NHibernateBase.OpentSession())
            {
                return(query.GetExecutableQueryOver(session).SingleOrDefault());
            }
        }
コード例 #8
0
        public IList <Cart> GetCartItems(string shoppingCartId)
        {
            var queryOver = GetQueryOverByCartId(shoppingCartId);

            using (var session = NHibernateBase.OpentSession())
            {
                return(queryOver.GetExecutableQueryOver(session).List());
            }
        }
コード例 #9
0
 public IList <Album> GetNewestAlbums()
 {
     using (var session = NHibernateBase.OpentSession())
     {
         var queryOver = GetQueryOverByArtistOrGenre();
         return(queryOver.OrderBy(album => album.DateCreated).Asc()
                .Take(Settings.Default.AlbumCount)
                .GetExecutableQueryOver(session)
                .List());
     }
 }
コード例 #10
0
        public bool CheckIfUserHasOrders(int orderId, string username)
        {
            using (var session = NHibernateBase.OpentSession())
            {
                Order order = session.QueryOver <Order>()
                              .Where(o => o.Id == orderId)
                              .And(o => o.Username == username)
                              .SingleOrDefault();

                return(order != null);
            }
        }
コード例 #11
0
 public int GetCount(string shoppingCartId)
 {
     using (var session = NHibernateBase.OpentSession())
     {
         int?count = session.QueryOver <Cart>()
                     .Where(c => c.CartId == shoppingCartId)
                     .SelectList(list => list
                                 .SelectSum(c => c.Count))
                     .SingleOrDefault <int>();
         return((int)count);
     }
 }
コード例 #12
0
        public void MigrateCart(string username, string shoppingCartId)
        {
            using (var session = NHibernateBase.OpentSession())
            {
                var shoppingCart = session.QueryOver <Cart>().Where(c => c.CartId == shoppingCartId).List();

                foreach (Cart cart in shoppingCart)
                {
                    cart.CartId = username;
                    session.Update(cart);
                }
            }
        }
コード例 #13
0
        public decimal GetTotal(string shoppingCartId)
        {
            using (var session = NHibernateBase.OpentSession())
            {
                IQuery query = session.CreateQuery(
                    "select Sum(album.Price * cart.Count)" +
                    "from Cart as cart inner join cart.Album as album where cart.CartId = :cartId");

                query.SetParameter("cartId", shoppingCartId);

                var total = query.UniqueResult <decimal>();
                return(total);
            }
        }
コード例 #14
0
        public void EmptyCart(string shoppingCartId)
        {
            using (var session = NHibernateBase.OpentSession())
            {
                using (session.BeginTransaction())
                {
                    var cartItems = session.QueryOver <Cart>().Where(c => c.CartId == shoppingCartId).List();

                    foreach (var cartItem in cartItems)
                    {
                        session.Delete(cartItem);
                    }
                }
            }
        }
コード例 #15
0
        public IList GetGenreandAlbums()
        {
            using (var session = NHibernateBase.OpentSession())
            {
                IList result;
                using (var tx = session.BeginTransaction())
                {
                    IQuery query = session.CreateQuery(
                        "from Genre as genre " +
                        "inner join genre.Albums as album");

                    result = query.List();
                    tx.Commit();
                }

                return(result);
            }
        }