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(); } } }
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); } } }
public Genre GetGenreByName(string name) { using (var session = NHibernateBase.OpentSession()) { var queryOver = GetQueryForGenre(name); return(queryOver.GetExecutableQueryOver(session).SingleOrDefault()); } }
public IList <Album> GetAlbumsByGenre(string genre) { using (var session = NHibernateBase.OpentSession()) { var queryOver = GetQueryOverByArtistOrGenre(genre); return(queryOver.GetExecutableQueryOver(session).List()); } }
public Album GetAlbumWithGenreById(int id) { var queryOver = GetQueryOverByArtistOrGenre("", "", id); using (var session = NHibernateBase.OpentSession()) { return(queryOver.GetExecutableQueryOver(session).SingleOrDefault()); } }
public IList <Album> GetAllAlbums() { var queryOver = GetQueryOverByArtistOrGenre(); using (var session = NHibernateBase.OpentSession()) { return(queryOver.GetExecutableQueryOver(session).List()); } }
public Cart GetUniqueCartWithAlbumByCartId(int id) { var query = GetQueryOverByCartId("", id); using (var session = NHibernateBase.OpentSession()) { return(query.GetExecutableQueryOver(session).SingleOrDefault()); } }
public IList <Cart> GetCartItems(string shoppingCartId) { var queryOver = GetQueryOverByCartId(shoppingCartId); using (var session = NHibernateBase.OpentSession()) { return(queryOver.GetExecutableQueryOver(session).List()); } }
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()); } }
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); } }
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); } }
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); } } }
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); } }
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); } } } }
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); } }