add code to test relations graph

This commit is contained in:
Andreas Zweili 2018-08-07 22:51:02 +02:00
parent 19d48555f8
commit ef85e3b63c
3 changed files with 58 additions and 3 deletions

View File

@ -4,6 +4,7 @@ using System.Data.Entity;
using Server.Helper;
using Server.Models;
using Server.DB;
using System.Linq;
namespace Server
{
@ -17,6 +18,38 @@ namespace Server
ICollection<Salutation> salutationList = new List<Salutation>();
salutationList = salutations.GetAllSalutations();
// End of workaround
Context ctx = new Context();
var test = ctx.PatientAtFoodPlaces.FirstOrDefault(c => c.PatientAtFoodPlaceID == 1);
if (test == null)
{
CreateRelations();
}
}
public void CreateRelations()
{
List<PatientAtFoodPlace> relations = new List<PatientAtFoodPlace>();
PersonDB dataccess = new PersonDB();
FoodPlaceDB fooddb = new FoodPlaceDB();
PatientAtFoodPlaceDB db = new PatientAtFoodPlaceDB();
Random Rnd = new Random();
ICollection<Person> patients = dataccess.GetAllPersons();
List<FoodPlace> foodplaces = new List<FoodPlace>(fooddb.GetAllFoodPlaces());
foreach (var patient in patients)
{
FoodPlace foodplace = foodplaces[Rnd.Next(0, 50)];
relations.Add(new PatientAtFoodPlace()
{
FoodPlaceID = foodplace.FoodPlaceID,
PatientID = patient.PersonID,
FoodPlace = foodplace,
VistingDate = DateTime.Now,
Patient = patient
});
}
foreach (var item in relations)
{
db.CreateRelation(item);
}
}
}
}
}

View File

@ -12,6 +12,7 @@ namespace Server.Helper
var countries = GenerateData.CreateCountries();
var cities = GenerateData.CreateCities();
var doctors = GenerateData.CreateDoctors();
var foodplaces = GenerateData.CreateFoodPlaces();
foreach (var s in salutations)
{
@ -33,6 +34,10 @@ namespace Server.Helper
{
context.Doctors.Add(d);
}
foreach (var f in foodplaces)
{
context.FoodPlaces.Add(f);
}
context.SaveChanges();
}

View File

@ -12,6 +12,8 @@ namespace Server.Helper
private static List<Doctor> Doctors = new List<Doctor>();
private static List<Country> Countries = new List<Country>();
private static List<City> Cities = new List<City>();
private static List<FoodPlace> foodPlaces = new List<FoodPlace>();
private static List<PatientAtFoodPlace> relations = new List<PatientAtFoodPlace>();
private static Random Rnd = new Random();
private static List<string> SalutationList = new List<string>(new string[]
@ -119,5 +121,20 @@ namespace Server.Helper
}
return Doctors;
}
}
}
public static List<FoodPlace> CreateFoodPlaces()
{
for (int i = 0; i < 50; i++)
{
foodPlaces.Add(new FoodPlace()
{
Name = "FoodPlace" + i,
Description = "b" + i,
City = Cities[i],
Streetname = "Musterstrase",
Streetnumber = i.ToString()
});
}
return foodPlaces;
}
}
}