This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MusicStoreContext : IMusicStoreContext | |
{ | |
private readonly ISession _currentSession; | |
public MusicStoreContext(ISession currentSession) | |
{ | |
_currentSession = currentSession; | |
} | |
public ISession Session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static ISessionFactory SessionFactory = CreateSessionFactory(); | |
private static ISessionFactory CreateSessionFactory() | |
{ | |
var config = new Configuration(); | |
config.DataBaseIntegration( | |
db => | |
{ | |
db.ConnectionStringName = "MusicStoreConnection", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool Validate(XmlSchema schema, string filePath) | |
{ | |
bool isValid = true; | |
XmlReaderSettings settings = new XmlReaderSettings(); | |
try | |
{ | |
settings.Schemas.Add(schema); | |
settings.ValidationType = ValidationType.Schema; |
NewerOlder