Пример #1
0
        public void AddToCart(NHAlbum album)
        {
            // Get the matching cart and album instances
            var cartItem = _session.QueryOver <NHCart>().Where(
                c => c.CartId == ShoppingCartId &&
                c.AlbumId == album.Id).SingleOrDefault();

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new NHCart
                {
                    AlbumId     = album.Id,
                    CartId      = ShoppingCartId,
                    Count       = 1,
                    DateCreated = DateTime.Now
                };
            }
            else
            {
                // If the item does exist in the cart, then add one to the quantity
                cartItem.Count++;
            }

            // Save changes
            _session.SaveOrUpdate(cartItem);
        }
        public void AddToCart(NHAlbum album)
        {
            // Get the matching cart and album instances
            var cartItem = _session.QueryOver<NHCart>().Where(
                c => c.CartId == ShoppingCartId
                && c.AlbumId == album.Id).SingleOrDefault();

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new NHCart
                {
                    AlbumId = album.Id,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };
            }
            else
            {
                // If the item does exist in the cart, then add one to the quantity
                cartItem.Count++;
            }

            // Save changes
            _session.SaveOrUpdate(cartItem);
        }
        public ActionResult Create(NHAlbum album)
        {
            if (ModelState.IsValid)
            {
                _session.Save(album);
                return RedirectToAction("Index");
            }

            ViewBag.GenreId = new SelectList(_session.Query<NHGenre>().AsEnumerable(), "Id", "Name");
            ViewBag.ArtistId = new SelectList(_session.Query<NHArtist>().AsEnumerable(), "Id", "Name");
            return View(album);
        }