public CFOTest() { _db = new PurchaseReqContext(); DbInitializer.ClearData(_db); DbInitializer.SeedData(_db); }
public static void SeedData(PurchaseReqContext context) { context.Database.EnsureCreated(); if (!context.Campuses.Any()) { context.Campuses.AddRange(SampleData.GetCampuses); context.SaveChanges(); } if (!context.Rooms.Any()) { context.Rooms.AddRange(SampleData.GetRooms); context.SaveChanges(); } if (!context.Employees.Any()) { context.Employees.AddRange(SampleData.GetEmployees(context.Rooms.ToList())); context.SaveChanges(); } if (!context.Divisions.Any()) { context.Divisions.AddRange(SampleData.GetDivisions(context.Employees.ToList())); context.SaveChanges(); } if (!context.Departments.Any()) { context.Departments.AddRange(SampleData.GetDepartments(context.Divisions.ToList())); context.SaveChanges(); context.Employees.UpdateRange(SampleData.SetEmployeesDepartment(context.Employees.OrderBy(x => x.FirstName).ToList())); context.SaveChanges(); } if (!context.BudgetCodes.Any()) { context.BudgetCodes.AddRange(SampleData.GetBudgetCodes); context.SaveChanges(); } if (!context.EmployeesBudgetCodes.Any()) { context.EmployeesBudgetCodes.AddRange(SampleData.GetEmployeeBudgetCodes(context.Employees.ToList(), context.BudgetCodes.ToList())); context.Employees.UpdateRange(SampleData.SetPasswords(context.Employees.ToList())); context.SaveChanges(); } if (!context.Vendors.Any()) { context.Vendors.AddRange(SampleData.GetVendors); context.SaveChanges(); } if (!context.Statuses.Any()) { context.Statuses.AddRange(SampleData.GetStatuses); context.SaveChanges(); } if (!context.Categories.Any()) { context.Categories.AddRange(SampleData.GetCategories); context.SaveChanges(); } if (!context.Orders.Any()) { context.Orders.AddRange(SampleData.GetOrders(context.Employees.ToList())); context.SaveChanges(); } if (!context.Items.Any()) { context.Items.AddRange(SampleData.GetItems); context.SaveChanges(); } if (!context.Requests.Any()) { context.Requests.AddRange(SampleData.GetRequests); context.SaveChanges(); } if (!context.Approval.Any()) { context.Approval.AddRange(SampleData.GetApprovals); context.SaveChanges(); } if (!context.Roles.Any()) { context.Roles.AddRange(SampleData.GetRoles); context.SaveChanges(); } if (!context.UserRoles.Any()) { context.UserRoles.AddRange(SampleData.GetUserWithRole(context.Employees.ToList(), context.Roles.ToList())); context.SaveChanges(); } if (!context.SupervisorApprovals.Any()) { context.SupervisorApprovals.AddRange(SampleData.GetSupervisorApprovals(context.Employees.ToList(), context.Roles.ToList())); context.SaveChanges(); } context.SaveChanges(); }
private static void SetEmployeesToNull(PurchaseReqContext appDbContext) { appDbContext.Database.ExecuteSqlCommand("Update [dbo].[AspNetUsers] Set DepartmentId = NULL"); }
private static void ExecuteDeleteSQL(PurchaseReqContext appDbContext, string schema, string tableName) { appDbContext.Database.ExecuteSqlCommand("Delete from [" + schema + "].[" + tableName + "]"); }
public static void InitializeData(PurchaseReqContext context) { context.Database.Migrate(); ClearData(context); SeedData(context); }