Skip to content

Instantly share code, notes, and snippets.

View kmckelvin's full-sized avatar

Kevin McKelvin kmckelvin

View GitHub Profile
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Mvc Music Store" namespace="MvcMusicStore.Models">
<class name="Album">
<id name="AlbumId">
<generator class="identity" />
</id>
<many-to-one name="Genre" column="GenreId" />
<many-to-one name="Artist" column="ArtistId" />
<property name="Title" />
<property name="Price" />
public class MusicStoreNinjectModule : NinjectModule
{
public override void Load()
{
Bind<AccountController>().ToSelf();
Bind<CheckoutController>().ToSelf();
Bind<HomeController>().ToSelf();
Bind<ShoppingCartController>().ToSelf();
Bind<StoreController>().ToSelf();
Bind<StoreManagerController>().ToSelf();
public static IMusicStoreContext GetCurrentRequestContext()
{
// get the ISession bound to the current request
var currentSession = SessionFactory.GetCurrentSession();
// build a context object to wrap it
var context = new MusicStoreContext(currentSession);
return context;
}
public class MusicStoreContext : IMusicStoreContext
{
private readonly ISession _currentSession;
public MusicStoreContext(ISession currentSession)
{
_currentSession = currentSession;
}
public ISession Session
private static ISessionFactory SessionFactory = CreateSessionFactory();
private static ISessionFactory CreateSessionFactory()
{
var config = new Configuration();
config.DataBaseIntegration(
db =>
{
db.ConnectionStringName = "MusicStoreConnection",
public int CreateOrder(Order order)
{
using (var tx = storeDB.Session.BeginTransaction())
{
var cartItems = GetCartItems();
//Iterate the items in the cart, adding Order Details for each
foreach (var cartItem in cartItems)
{
var orderDetail = new OrderDetail
public class Album
{
public virtual int AlbumId { get; set;}
public virtual Genre Genre { get; set;}
public virtual Artist Artist { get; set; }
public virtual string Title { get; set; }
public virtual decimal Price { get; set; }
public virtual string AlbumArtUrl { get; set; }
}
namespace MvcMusicStore.Models
{
public interface IMusicStoreContext
{
ISession Session { get; }
IQueryable<Album> Albums { get; }
IQueryable<Artist> Artists { get; }
IQueryable<Cart> Carts { get; }
IQueryable<Genre> Genres { get; }
IQueryable<Order> Orders { get; }
public bool Validate(XmlSchema schema, string filePath)
{
bool isValid = true;
XmlReaderSettings settings = new XmlReaderSettings();
try
{
settings.Schemas.Add(schema);
settings.ValidationType = ValidationType.Schema;