using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using Humanizer; using InventoryTraker.Web.Core; using InventoryTraker.Web.Data; using InventoryTraker.Web.Identity; using InventoryTraker.Web.Utilities; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; namespace InventoryTraker.Web { public static class SeedData { public static void Init() { using (var context = new AppDbContext()) { if (!context.Users.Any()) { var manager = new ApplicationUserManager(new UserStore(context)); manager.Create(new User { Email = "james.kolpack@gmail.com", UserName = "James Kolpack", }, "hgBdFiJTK"); manager.Create(new User { Email = "bbanegas@ethra.org", UserName = "Brandi Banegas", }, "3v9qxe"); manager.Create(new User { Email = "ccecil@ethra.org", UserName = "Cyndie Cecil", }, "95kdsxa"); manager.Create(new User { Email = "knorton@ethra.org", UserName = "Kay Norton", }, "rt9pmz1"); } if (!context.Inventories.Any()) { AddInventoryTypes(context); context.SaveChanges(); AddInventory(context); context.SaveChanges(); } if (!context.Customers.Any()) { AddNewCustomers(context); AddExistingCustomers(context); AddTerminatedCustomers(context); context.SaveChanges(); } } } private static void AddInventoryTypes(AppDbContext context) { var folder = HttpContext.Current.Server.MapPath("~/App_Data"); var inventoryTypeFile = Path.Combine(folder, "InventoryTypeSeedData.xlsx"); var parser = new InventoryTypeParser(new FileInfo(inventoryTypeFile)); foreach (var inventoryType in parser.Parse()) { context.InventoryTypes.Add(inventoryType); } } private static void AddInventory(AppDbContext context) { var pork = context.InventoryTypes.First(it => it.Identifier == "100139"); var beans = context.InventoryTypes.First(it => it.Identifier == "100363"); var pb = context.InventoryTypes.First(it => it.Identifier == "100395"); context.Inventories.Add(new Inventory { InventoryType = pork, ExpirationDate = DateTime.Now.AddYears(1).AtMidnight(), AddedDate = DateTime.Now.AddDays(-1).AtMidnight(), Memo = "Hormel", Quantity = 10, Transactions = new List { new Transaction { AddedQuantity = 10, Memo = "arrival", TransactionDate = DateTime.Now.AddDays(-1).AtMidnight(), Timestamp = DateTime.Now }} }); context.Inventories.Add(new Inventory { InventoryType = beans, ExpirationDate = DateTime.Now.AddMonths(4).AtMidnight(), AddedDate = DateTime.Now.AddMonths(-2).AtMidnight(), Memo = "Cut", Quantity = 15, Transactions = new List { new Transaction { AddedQuantity = 15, Memo = "arrival", TransactionDate = DateTime.Now.AddMonths(-2).AtMidnight(), Timestamp = DateTime.Now }} }); context.Inventories.Add(new Inventory { InventoryType = pb, ExpirationDate = DateTime.Now.AddDays(300).AtMidnight(), AddedDate = DateTime.Now.AddDays(-34).AtMidnight(), Quantity = 700, Transactions = new List { new Transaction { AddedQuantity = 700, Memo = "arrival", TransactionDate = DateTime.Now.AddDays(-34).AtMidnight(), Timestamp = DateTime.Now }} }); } private static void AddTerminatedCustomers(AppDbContext context) { context.Customers.Add(new Customer { Name = "Arlo Seymour", HomeEmail = "Arlo@home.com", WorkEmail = "Arlo@work.com", WorkAddress = "123 Arlo Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Seymour Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(-90), TerminationDate = DateTime.Today.ToStartOfMonth().AddDays(5), }); context.Customers.Add(new Customer { Name = "Porter Jakeman", HomeEmail = "Porter@home.com", WorkEmail = "Porter@work.com", WorkAddress = "123 Porter Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Jakeman Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(-75), TerminationDate = DateTime.Today.ToStartOfMonth().AddDays(10), }); context.Customers.Add(new Customer { Name = "Edwyn Perry", HomeEmail = "Edwyn@home.com", WorkEmail = "Edwyn@work.com", WorkAddress = "123 Edwyn Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Perry Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(-45), TerminationDate = DateTime.Today.ToStartOfMonth().AddDays(15), }); } private static void AddExistingCustomers(AppDbContext context) { context.Customers.Add(new Customer { Name = "Gosse Greene", HomeEmail = "Gosse@home.com", WorkEmail = "Gosse@work.com", WorkAddress = "123 Gosse Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Greene Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(-20), Risks = new List() { new Risk{Title = "Considering vendor switch", Description = "His contract is expiring next month, and he's evaluating other vendors. He likes the services we provide, but feels he is paying too much."} } }); context.Customers.Add(new Customer { Name = "Warwick Rye", HomeEmail = "Warwick@home.com", WorkEmail = "Warwick@work.com", WorkAddress = "123 Warwick Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Rye Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(-15), Opportunities = new List { new Opportunity{Title = "Expanding business", Description = "Warwick's business is booming. He's considering acquiring a competitor. If that happens, he'll need a *lot* of custom development to integrate the two systems."} } }); context.Customers.Add(new Customer { Name = "Odell Dennel", HomeEmail = "Odell@home.com", WorkEmail = "Odell@work.com", WorkAddress = "123 Odell Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Dennel Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(-10), Risks = new List { new Risk{Title = "Customer may not pay", Description = "Odell is not pleased with the solution we developed. He has threatened to stop all future payments, including outstanding invoices for work that has already been performed."} } }); } private static void AddNewCustomers(AppDbContext context) { context.Customers.Add(new Customer { Name = "John Doe", HomeEmail = "john@home.com", WorkEmail = "john@work.com", WorkAddress = "123 Main Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Second Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth() }); context.Customers.Add(new Customer { Name = "Roy Irvine", HomeEmail = "roy@home.com", WorkEmail = "roy@work.com", WorkAddress = "123 Roy Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Irvine Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(5), }); context.Customers.Add(new Customer { Name = "Vere Rowland", HomeEmail = "vere@home.com", WorkEmail = "vere@work.com", WorkAddress = "123 Vere Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Roland Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(10), }); context.Customers.Add(new Customer { Name = "Zack Beasley", HomeEmail = "zack@home.com", WorkEmail = "zack@work.com", WorkAddress = "123 Zack Street\r\nSuite B\r\nNew York, NY 55555", HomeAddress = "321 Beasley Street\r\nApt 1205\r\nNew York, NY 55555", HomePhone = "(555) 123-4555", WorkPhone = "(555) 321-5444", CreateDate = DateTime.Today.ToStartOfMonth().AddDays(15), Opportunities = new List { new Opportunity{Title = "Interested in on-site support", Description = "Zack likes the solution we developed for his business. He's interested in our on-site support services, too."} } }); } } }