public static void GetJson(EquipmentHandler equipRepo, OwnerHandler ownerRepo) { List <Mac> Macs = new List <Mac>(); List <Owner> Owners = new List <Owner>(); List <Equipment> Equip = new List <Equipment>(); string json = File.ReadAllText(@"C:\Users\peter\source\repos\MDMScrape\MDMScrape\bin\Debug\netcoreapp2.1\Macs.json"); Macs = JsonConvert.DeserializeObject <List <Mac> >(json); for (int i = 0; i < Macs.Count; i++) { Equip.Add(Macs[i]); Equip[Equip.Count - 1].EquipType = Equipment.EquipmentType.Mac; Owners.Add(Macs[i].Owner); } var eqpTasks = new List <Task>(); var ownerTasks = new List <Task>(); var owner = Owners.Distinct().ToList(); for (int i = 0; i < Equip.Count; i++) { equipRepo.Insert(Equip[i], false); if (i % 20 == 0) { equipRepo.Save(); } } for (int i = 0; i < owner.Count; i++) { ownerRepo.Insert(owner[i], false); if (i % 20 == 0) { ownerRepo.Save(); } } }
public static void GetRandomTest(EquipmentHandler equipRepo, OwnerHandler ownerRepo) { var usersToAdd = 500; var equipmentToAdd = 500; const string chars = "abcdefghijklmnopqrstuvxyzw"; const string numbers = "123456789"; var random = new Random(); var owners = new List <Owner>(); var equipment = new List <Equipment>(); for (int i = 0; i < usersToAdd; i++) { var owner = new Owner(); owner.FirstName = new string(Enumerable.Repeat(chars, 10) .Select(s => s[random.Next(s.Length)]).ToArray()); owner.LastName = new string(Enumerable.Repeat(chars, 10) .Select(s => s[random.Next(s.Length)]).ToArray()); owner.LastEdited = DateTime.Now; owners.Add(owner); } for (int i = 0; i < equipmentToAdd; i++) { var eqp = new Equipment(); eqp.Serial = new string(Enumerable.Repeat(numbers, 15) .Select(s => s[random.Next(s.Length)]).ToArray()); eqp.Model = new string(new string(Enumerable.Repeat(chars, 10) .Select(s => s[random.Next(s.Length)]).ToArray()) + new string(Enumerable.Repeat(numbers, 8) .Select(s => s[random.Next(s.Length)]).ToArray())); eqp.LastEdited = DateTime.Now; eqp.EquipType = Equipment.EquipmentType.Laptop; equipment.Add(eqp); } for (int i = 0; i < equipment.Count; i++) { equipRepo.Insert(equipment[i], false); if (i % 20 == 0) { equipRepo.Save(); } } for (int i = 0; i < owners.Count; i++) { ownerRepo.Insert(owners[i], false); if (i % 20 == 0) { ownerRepo.Save(); } } }