using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace mvc4WebApplication.Models
{
///
/// Author: Dr Derek Peacock
/// Course: DMU HND Computing
/// Module: SD Project
/// Started: 18th March 2013
/// Modified: 18th March 2013
///
/// This class re-seeds the database with sample data after
/// it has been dropped and re-created due to a change in
/// the model classes
///
public class ProjectInitializer : DropCreateDatabaseIfModelChanges
{
protected override void Seed(TalkIsCheapDBContext context)
{
var Customers = new List
{
new Customer {
CustomerId = 1,
FullName = "Derek",
Email = "derek@y.com",
HouseNo = "123",
PostCode="LE7 9SD",
CardNo ="12345678",
ExpiryMonth=1,
ExpiryYear=2015,
PaymentCard="Credit"},
new Customer {
CustomerId = 2,
FullName = "Veena",
Email = "veena@y.com",
HouseNo = "23",
PostCode="LE6 5TY",
CardNo ="12345678",
ExpiryMonth=5,
ExpiryYear=2014,
PaymentCard="Credit"}
};
Customers.ForEach(p => context.Customers.Add(p));
context.SaveChanges();
var Phones = new List
{
new Phone
{
PhoneID = 1,
Make= "Samsung",
Model = "Galaxy S4",
OperatingSystem = "Android 4.2",
InternalMemory = 16.0F,
ScreenSize = 5.2F,
PurchasePrice = 480.00M,
MonthlyPayment = 35.00M
},
new Phone
{
PhoneID = 2,
Make= "HTC",
Model = "Desire X",
OperatingSystem = "Android 4.0",
InternalMemory = 4.0F,
ScreenSize = 4.0F,
PurchasePrice = 400.00M,
MonthlyPayment = 30.00M
},
new Phone
{
PhoneID = 3,
Make= "Nokia",
Model = "Lumia 620",
OperatingSystem = "Windows",
InternalMemory = 8.0F,
ScreenSize = 3.8F,
PurchasePrice = 350.00M,
MonthlyPayment = 28.00M
},
new Phone
{
PhoneID = 4,
Make= "LG",
Model = "Nexus 4",
OperatingSystem = "Android 4.2",
InternalMemory = 16.0F,
ScreenSize = 4.7F,
PurchasePrice = 420.00M,
MonthlyPayment = 32.00M
}
};
Phones.ForEach(p => context.Phones.Add(p));
context.SaveChanges();
base.Seed(context);
}
}
}