You are on page 1of 2

namespace

using
using
using
using
using

PSIProject.Migrations {
System;
System.Data.Entity;
System.Data.Entity.Migrations;
System.Linq;
System.Collections.Generic;

using PSIProject.Models.Locations;
using PSIProject.Models.Users;
using PSIProject.Models.Auctions;
internal sealed class Configuration : DbMigrationsConfiguration<PSIProject.D
AL.AuctionsContext> {
public Configuration() {
AutomaticMigrationsEnabled = false;
}
protected override void Seed(PSIProject.DAL.AuctionsContext context) {
//adicionar distritos
var district = new List<District> {
new District{
Name="Aveiro",
Counties = new List<County>{
new County{
Name="Agueda",
Locality= new List<Locality> {
new Locality {
Name = "Agueda",
PostalCodes = new List<PostalCode> {
new PostalCode {ZipCode="3750-111"},
},
}
}
}
}
}
};
//district.ForEach(s => context.District.AddOrUpdate(p => p.Name, s)
);
district.ForEach(x => context.District.Add(x));
/*
//adicionar concelhos
var county = new List<County>
{
new County{Name="Aveiro", DistrictID = district.Single(s => s.N
ame == "Aveiro").ID},
new County{Name="Agueda", DistrictID = district.Single(s => s.N
ame == "Aveiro").ID},
new County{Name="Espinho", DistrictID = district.Single(s => s.
Name == "Aveiro").ID}
};
county.ForEach(s => context.County.AddOrUpdate(p => p.Name, s));
//adicionar localidades
var locality = new List<Locality>
{
new Locality { Name = "Agueda", CountyID = county.Single(s => s.
Name == "Agueda").ID},
new Locality { Name = "Oronhe", CountyID = county.Single(s => s.
Name == "Agueda").ID},
new Locality { Name = "Borralha", CountyID = county.Single(s =>

s.Name == "Agueda").ID}
};
locality.ForEach(s => context.Locality.AddOrUpdate(p => p.Name, s));
//adicionar codigos postais
var postalCode = new List<PostalCode>
{
new PostalCode {ZipCode="3750-111", LocalityID = locality.Single
(s => s.Name == "Agueda").ID},
new PostalCode {ZipCode="3750-222", LocalityID = locality.Single
(s => s.Name == "Agueda").ID},
new PostalCode {ZipCode="3750-333", LocalityID = locality.Single
(s => s.Name == "Agueda").ID}
};
postalCode.ForEach(s => context.PostalCode.AddOrUpdate(p => p.ZipCod
e, s));
*/
//adicionar utilizador
/*context.ApplicationUser.AddOrUpdate(
new ApplicationUser {
Id = "1",
Name = "Admin",
Photo = "no-photo.jpg",
PostalCodeID = 1,
Email = "admin@mail.com",
EmailConfirmed = true,
PasswordHash = "123",
PhoneNumber = "123456789",
PhoneNumberConfirmed = true,
TwoFactorEnabled = false,
LockoutEndDateUtc = DateTime.Now,
LockoutEnabled = false,
AccessFailedCount = 0,
UserName = "Admin"
}
);*/
//adicionar categorias
context.Category.AddOrUpdate(
new Category { CategoryName = "Tecnologia"},
new Category { CategoryName = "Imoveis" },
new Category { CategoryName = "Albuns" }
);
// This method will be called after migrating to the latest version
.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
//
context.People.AddOrUpdate(
//
p => p.FullName,
//
new Person { FullName = "Andrew Peters" },
//
new Person { FullName = "Brice Lambson" },
//
new Person { FullName = "Rowan Miller" }
//
);
//
}
}
}

You might also like