a5fcb46e04
Transaction updates
290 lines
9.1 KiB
C#
290 lines
9.1 KiB
C#
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<User>(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 r = new Random(1);
|
|
var inventoryTypes = context.InventoryTypes.ToList();
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
var inventoryType = inventoryTypes.ElementAt(r.Next(0, context.InventoryTypes.Count()));
|
|
var addedDate = DateTime.Today.AddMonths(-r.Next(1, 24));
|
|
var expiration = addedDate.AddMonths(r.Next(12, 48));
|
|
var memo = "New " + inventoryType.Name;
|
|
var quantity = r.Next(5, 112);
|
|
|
|
var previousTransaction = new Transaction
|
|
{
|
|
AddedQuantity = quantity, Memo = "Arrival", CurrentQuantity = quantity, TransactionDate = addedDate, Timestamp = addedDate
|
|
};
|
|
var inventory = new Inventory
|
|
{
|
|
InventoryType = inventoryType,
|
|
ExpirationDate = expiration,
|
|
AddedDate = addedDate,
|
|
Memo = memo,
|
|
Quantity = quantity,
|
|
Transactions = new List<Transaction> { previousTransaction}
|
|
};
|
|
context.Inventories.Add(inventory);
|
|
|
|
for (int j = 0; j < 5 && previousTransaction.CurrentQuantity > 0; j++)
|
|
{
|
|
var transactionDate = previousTransaction.TransactionDate.AddDays(r.Next(1, 100));
|
|
if (transactionDate >= DateTime.Today)
|
|
break;
|
|
|
|
var quantityRemoved = r.Next(1, 100);
|
|
if (quantityRemoved > previousTransaction.CurrentQuantity)
|
|
quantityRemoved = previousTransaction.CurrentQuantity;
|
|
|
|
var transaction = new Transaction
|
|
{
|
|
RemovedQuantity = quantityRemoved,
|
|
CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved,
|
|
Inventory = inventory,
|
|
Memo = "Distributed",
|
|
TransactionDate = transactionDate,
|
|
Timestamp = transactionDate
|
|
};
|
|
|
|
inventory.Quantity = transaction.CurrentQuantity;
|
|
|
|
inventory.Transactions.Add(transaction);
|
|
|
|
previousTransaction = transaction;
|
|
}
|
|
}
|
|
}
|
|
|
|
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<Risk>()
|
|
{
|
|
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<Opportunity>
|
|
{
|
|
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<Risk>
|
|
{
|
|
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<Opportunity>
|
|
{
|
|
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."}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
} |