public void Handle(IOrderAcceptedEvent message) { MusicStoreEntities storeDB = new MusicStoreEntities(); var order = storeDB.Orders.Single(o => o.OrderId == message.OrderId); var shipNote = new ShippingNote { FirstName = order.FirstName, LastName = order.LastName, Address = order.Address, City = order.City, State = order.State, PostalCode = order.PostalCode }; foreach (var detail in order.OrderDetails) { var inventoryPosition = storeDB.InventoryPositions.Single(p => p.Album.AlbumId == detail.AlbumId); if (inventoryPosition.BalanceOnHand >= detail.Quantity) { inventoryPosition.BalanceOnHand -= detail.Quantity; shipNote.ShippedQuantity += detail.Quantity; } else { shipNote.BackOrderQuantity = detail.Quantity - shipNote.ShippedQuantity; } } storeDB.AddToShippingNotes(shipNote); storeDB.SaveChanges(); }
void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { // TODO: Add your acction filter's tasks here // Log Action Filter Call MusicStoreEntities storeDB = new MusicStoreEntities(); ActionLog log = new ActionLog() { Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, Action = filterContext.ActionDescriptor.ActionName + " (Logged By: Custom Action Filter)", IP = filterContext.HttpContext.Request.UserHostAddress, DateTime = filterContext.HttpContext.Timestamp }; storeDB.ActionLogs.Add(log); storeDB.SaveChanges(); this.OnActionExecuting(filterContext); } }
// GET: StoreManage public ActionResult Index() { SampleData sample = new SampleData(); objMusicStore = sample.Seed(); return(View(objMusicStore)); }
public Task <List <OrderDetail> > GetNotOrderedCDs(MusicStoreEntities _storeContext) { return(_storeContext .OrderDetails .Where(a => a.ShipmentId == null && a.Order.Status == OrderStatus.New) .ToListAsync()); }
protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); MusicStoreEntities storeDB = new MusicStoreEntities(); DomainManager = new MusicStoreDomainManager <GenreDto, Genre>(storeDB, controllerContext.Request); }
private void ReCreateDatabaseForTesting() { Database.SetInitializer(new DatabaseSeedingInitializer()); using (var context = new MusicStoreEntities()) { context.Database.Initialize(true); } }
public ActionResult Details(int id) { Album album = new Album(); SampleData sample = new SampleData(); storeDB = sample.Seed(); album = storeDB.GetAlbums().Find(x => x.AlbumId == id); return(View(album)); }
// GET: Store public ActionResult Index() { SampleData sample = new SampleData(); storeDB = sample.Seed(); var genres = storeDB.GetGenres().ToList(); return(View(genres)); }
private void SetValue(bool toggleValue) { MusicStoreEntities db = new MusicStoreEntities(); var featureToggle = db.FeatureToggles.FindAsync(_id).Result; featureToggle.Enabled = toggleValue; db.Entry(featureToggle).State = EntityState.Modified; db.SaveChangesAsync(); }
private async Task MigrateShoppingCart(string userName) { using (var storeContext = new MusicStoreEntities()) { var cart = ShoppingCart.GetCart(storeContext, this); await cart.MigrateCart(userName); Session[ShoppingCart.CartSessionKey] = userName; } }
public AccountController( SignInManager <ApplicationUser> _signInManager, ILogger <AccountController> _logger, MusicStoreEntities _storeDB ) { signInManager = _signInManager; logger = _logger; storeDB = _storeDB; }
// GET: StoreManage/Details/5 public ActionResult Details(int id) { SampleData sample = new SampleData(); objMusicStore = sample.Seed(); Album AlbumDetails = new Album(); AlbumDetails = objMusicStore.GetAlbums().Find(x => x.AlbumId == id); return(View(AlbumDetails)); }
protected void Session_Start() { // Clean up Logs Table MusicStoreEntities storeDB = new MusicStoreEntities(); foreach (var log in storeDB.ActionLogs.ToList()) { storeDB.ActionLogs.Remove(log); } storeDB.SaveChanges(); }
protected void Application_Start() { MusicStoreEntities db = new MusicStoreEntities(); var genres = db.Genres.ToList(); #region Simple MemberShip Adimlari #endregion AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
private void MigrateShoppingCart(string UserName) { var storeDb = new MusicStoreEntities(); // Associate shopping cart items with logged-in user var cart = ShoppingCart.GetCart(storeDb, this.HttpContext); cart.MigrateCart(UserName); storeDb.SaveChanges(); Session[ShoppingCart.CartSessionKey] = UserName; }
public void ConfigureApp(IAppBuilder app) { using (var context = new MusicStoreEntities()) { context.Database.Delete(); context.Database.Create(); new SampleData().Seed(context); } CreateAdminUser().Wait(); }
private async Task MigrateShoppingCart(string userName) { logger.Debug("Entered into MigrateShoppingCart method"); using (var storeContext = new MusicStoreEntities()) { var cart = ShoppingCart.GetCart(storeContext, this); await cart.MigrateCart(userName); Session[ShoppingCart.CartSessionKey] = userName; } }
// GET: Store public ActionResult Index() { //var genres = new List<Genre> //{ // new Genre { Name = "Disco"}, // new Genre { Name = "Jazz"}, // new Genre { Name = "Rock"} //}; MusicStoreEntities dbStore = new MusicStoreEntities(); var genres = dbStore.Genres.ToList(); return(View(genres)); }
public void Handle(IAddToCartCommand message) { MusicStoreEntities storeDB = new MusicStoreEntities(); // Retrieve the album from the database var addedAlbum = storeDB.Albums .Single(album => album.AlbumId == message.AlbumId); // Add it to the shopping cart var cart = new ShoppingCart(message.CartId); cart.AddToCart(addedAlbum); }
protected void Application_Start() { MusicStoreEntities db = new MusicStoreEntities(); db.Genres.ToList(); AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); //Bundle ı elle ekleme işlemi //Bu işlem için using e web.optimization ekleniyor ve app_start ekleniyor. BundleConfig.RegisterBundles(BundleTable.Bundles); }
public void Handle() { ReCreateDatabaseForTesting(); using (var context = new MusicStoreEntities()) { var handler = new ChangeTaskStatusCommandHandler(new EntityRepository <Task>(context)); var command = _fixture.Create <ChangeTaskStatusCommand>(); handler.Handle(command); } }
public void ConfigureApp(IAppBuilder app) { using (var context = new MusicStoreEntities()) { //This is the original code, works fine on localdb but not a real-world scenario to deploy your db //on every app start //Currently the deployment template creates a db and sources the data from a bacpac so none of this is needed //context.Database.Delete(); //context.Database.Create(); //new SampleData().Seed(context); } //remove this for the demo so no one has unexpected admin access to the test app //uncomment and update web.config if you need to use the admin features, they aren't needed for the demo //CreateAdminUser().Wait(); }
public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node) { using (var storeDB = new MusicStoreEntities()) { // Create a node for each album foreach (var album in storeDB.Albums.Include("Genre")) { DynamicNode dynamicNode = new DynamicNode(); dynamicNode.Title = album.Title; dynamicNode.ParentKey = "Genre_" + album.Genre.Name; dynamicNode.RouteValues.Add("id", album.AlbumId); yield return(dynamicNode); } } }
// // GET: /Store/Browse public ActionResult Browse(string genre) { List <Album> genreModel = new List <Album>(); try { SampleData sample = new SampleData(); storeDB = sample.Seed(); genreModel = storeDB.GetAlbums().FindAll(x => x.Genre.Name == genre); return(View(genreModel)); } catch (Exception ex) { } return(View(genreModel)); }
protected void Application_Start() { MusicStoreEntities db = new MusicStoreEntities(); var genres = db.Genres.ToList(); #region Simple Membership Adimlari //1.WebMatrix.Data ve WebMatrix.WebData 2. verisyonlarini ekleme(copy local=true) //2.Yoksa connection stringi olusturma //3.appsettingse simplemembership olusturma icin gerekli degeri ekleme //4.Membership provideri duzenleme //5.RoleManageri duzenleme(enabled=true) //6.Tablolarin veritabaninda olusturulmasi icin kod ile tetikleme islemi #endregion if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("MusicStoreCon", "UserDetails", "Id", "UserName", autoCreateTables: true); if (!WebSecurity.UserExists(ConfigurationManager.AppSettings["DefaultAdminName"])) { WebSecurity.CreateUserAndAccount(ConfigurationManager.AppSettings["DefaultAdminName"], ConfigurationManager.AppSettings["DefaultAdminPassword"], new { FirstName = ConfigurationManager.AppSettings["DefaultAdminName"], Email = "*****@*****.**", BirthDate = DateTime.Now, Phone = "3534554", IsLocked = false, IsDeleted = false, CreatedDate = DateTime.Now }); if (!Roles.RoleExists("admin")) { Roles.CreateRole("admin"); } Roles.AddUserToRole(ConfigurationManager.AppSettings["DefaultAdminName"], "admin"); } } AreaRegistration.RegisterAllAreas(); ViewEngines.Engines.Add(new MyViewEngine()); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public void ConfigureApp(IAppBuilder app) { using (var context = new MusicStoreEntities()) { context.Database.Delete(); context.Database.Create(); new SampleData().Seed(context); } CreateAdminUser().Wait(); var kernel = new StandardKernel(); kernel.Bind <ILogger>().ToConstant(LogManager.GetCurrentClassLogger()); DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); }
public async Task ConfigureApp(IAppBuilder app) { using (var context = new MusicStoreEntities()) { context.Database.Delete(); context.Database.Create(); new SampleData().Seed(context); } using (var context = new ApplicationDbContext()) { context.Database.Delete(); context.Database.Create(); } await CreateAdminUser(); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { MusicStoreEntities storeDB = new MusicStoreEntities(); ActionLog log = new ActionLog() { Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, Action = filterContext.ActionDescriptor.ActionName, IP = filterContext.HttpContext.Request.UserHostAddress, DateTime = filterContext.HttpContext.Timestamp }; storeDB.ActionLogs.Add(log); storeDB.SaveChanges(); base.OnActionExecuting(filterContext); }
public void ConfigureApp(IAppBuilder app) { var logger = new LoggerConfiguration() .ReadFrom.AppSettings() .CreateLogger(); Log.Logger = logger; using (var context = new MusicStoreEntities()) { context.Database.Delete(); context.Database.Create(); new SampleData().Seed(context); } CreateAdminUser().Wait(); }
public SimpleMembershipInitializer() { Database.SetInitializer(new MigrateDatabaseToLatestVersion <MusicStoreEntities, SampleData>()); try { using (var context = new MusicStoreEntities()) { context.Database.Initialize(true); } WebSecurity.InitializeDatabaseConnection("MusicStoreEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }
public IEnumerable<ISiteMapNodeToParentRelation> GetSiteMapNodes(ISiteMapNodeHelper helper) { // Try the API! Let us know if there is something we can do to make it better. // This is a replacement for all of the DynamicNodeProvider implementations within // the MvcMusicStore demo, to show how this could be done. Note that in a real-world scenario // you would need to remove all of the DynamicNodeProvider declarations in the SemanticSiteMapNodeProvider // because they would be completely unnecessary. // Be sure to try adding nodes yourself to see if you can suggest ways to make this // more intuitive, easier to read, or easier to write. using (var storeDB = new MusicStoreEntities()) { // Create a node for each genre foreach (var genre in storeDB.Genres) { // This is the original dynamic node definition //DynamicNode dynamicNode = new DynamicNode("Genre_" + genre.Name, genre.Name); //dynamicNode.RouteValues.Add("genre", genre.Name); //yield return dynamicNode; // This is the fluent API version. // Note that because there is no inheritance when we do it this way, we are specifying controller and action here, too. yield return helper.RegisterNode() .MatchingRoute(x => x.WithController("Store").WithAction("Browse").AlwaysMatchingKey("browse").WithValue("genre", genre.Name)) .WithDisplayValues(x => x.WithTitle(genre.Name)) .WithKey("Genre_" + genre.Name) .Single(); } // Create a node for each album foreach (var album in storeDB.Albums.Include("Genre")) { // This is the original dynamic node definition //DynamicNode dynamicNode = new DynamicNode(); //dynamicNode.Title = album.Title; //dynamicNode.ParentKey = "Genre_" + album.Genre.Name; //dynamicNode.RouteValues.Add("id", album.AlbumId); //if (album.Title.Contains("Hit") || album.Title.Contains("Best")) //{ // dynamicNode.Attributes.Add("bling", "<span style=\"color: Red;\">hot!</span>"); //} //yield return dynamicNode; // This is the fluent API version. // Note that because there is no inheritance when we do it this way, we are specifying controller and action here, too. var customAttributes = new Dictionary<string, object>(); if (album.Title.Contains("Hit") || album.Title.Contains("Best")) { customAttributes.Add("bling", "<span style=\"color: Red;\">hot!</span>"); } yield return helper.RegisterNode() .MatchingRoute(x => x.WithController("Store").WithAction("Details").WithValue("id", album.AlbumId)) .WithDisplayValues(x => x.WithTitle(album.Title)) .WithParentKey("Genre_" + album.Genre.Name) .WithCustomAttributes(customAttributes) .Single(); } } }