public ActionResult CreateHumanType(HumanTypeViewModel humanTypeViewModel) { if (!ModelState.IsValid) { return(View(humanTypeViewModel)); } else { HumanType humanType = new HumanType(); var humanLikings = new List <HumanTypeLiking>(); humanType.HumanTypeName = humanTypeViewModel.HumanTypeName; humanType.color = humanTypeViewModel.color; humanType.numberOfLocations = humanTypeViewModel.NumberOfLocations; string[] likings = humanTypeViewModel.HumanLikings.Split(' '); int[] probabilities = humanTypeViewModel.probabilities.Split(' ').Select(int.Parse).ToArray(); if (likings.Length == probabilities.Length) { for (int i = 0; i < likings.Length; i++) { humanLikings.Add(new HumanTypeLiking { humanTypeLikingName = likings[i], probability = probabilities[i] }); } humanType.humanLikings = humanLikings; context.humanTypes.AddOrUpdate(humanType); context.SaveChanges(); } else { return(View(humanTypeViewModel)); } } return(RedirectToAction("Index")); }
public void AddPayments(object sender, FileSystemEventArgs e) { if (IsTargetExtension(Path.GetExtension(e.FullPath))) { var payments = new XMLDeserializator <List <Payment> >(); var table = payments.Load(e.FullPath); var comparer = new PaymentsCompare(); if (table?.Any() == true) { using (var context = new GeneratorContext()) { using (var transaction = context.Database.BeginTransaction()) { context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] ON"); var clientPayments = context.Payments.ToList(); var difPayments = table.Except(clientPayments, comparer); context.AddRange(difPayments); context.SaveChanges(); context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] OFF"); transaction.Commit(); } } } } }
public DatabaseFixture() { Context = new GeneratorContext(new DbContextOptionsBuilder <GeneratorContext>() .UseInMemoryDatabase(databaseName: "UnitTests") .Options); PictureIdA = Guid.NewGuid(); PictureIdB = Guid.NewGuid(); var pictureA = new Picture(PictureIdA, "image1"); var pictureB = new Picture(PictureIdB, "image2"); Context.Pictures.Add(pictureA); Context.Pictures.Add(pictureB); Context.SaveChanges(); }
private CharacterNameRepository CreateInMemoryRepo(CharacterAncestryDto[] ancestries) { var options = new DbContextOptionsBuilder <GeneratorContext>() .UseSqlite("DataSource=:memory:") .Options; var context = new GeneratorContext(options); context.Database.OpenConnection(); context.Database.EnsureCreated(); context.AddRange(ancestries); context.SaveChanges(); return(new CharacterNameRepository(context)); }
public async Task Execute(IJobExecutionContext context) { await Task.Run(() => { var people = new XMLDeserializator <List <Person> >(); var payments = new XMLDeserializator <List <Payment> >(); var tablePeople = people.Load(ConfigurationManager.AppSettings["BaseOfNames"]); var tablePayments = payments.Load(ConfigurationManager.AppSettings["BaseOfPayments"]); var peopleComparer = new PeopleCompare(); var paymentsComparer = new PaymentsCompare(); if (tablePeople?.Any() == true) { using (var dbContext = new GeneratorContext()) { using (var transaction = dbContext.Database.BeginTransaction()) { dbContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[People] ON"); var clients = dbContext.People.ToList(); var difClients = tablePeople.Except(clients, peopleComparer); dbContext.AddRange(difClients); dbContext.SaveChanges(); dbContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[People] OFF"); transaction.Commit(); } } } if (tablePayments?.Any() == true) { using (var context = new GeneratorContext()) { using (var transaction = context.Database.BeginTransaction()) { context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] ON"); var clientPayments = context.Payments.ToList(); var difPayments = tablePayments.Except(clientPayments, paymentsComparer); context.AddRange(difPayments); context.SaveChanges(); context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] OFF"); transaction.Commit(); } } } }); }
private string GetLocationId(GeneratorContext context, string objectiveType) { Random random = new Random(); string objectiveId; Location[] objective = context.Locations.Where(g => g.type == objectiveType).ToArray(); if (objective == null) { objective = context.Locations.ToArray(); } int index = random.Next(objective.Length - 1); string o = objectiveType; objective[index].visitCount++; objectiveId = objective[index].LocationId; context.Locations.AddOrUpdate(objective[index]); context.SaveChanges(); return(objectiveId); }
public string generateRandomObjective(GeneratorContext context, string type) { string objectiveType; Random random = new Random(); string objectiveId; if (type == "student") { int randomUpodobanie = random.Next(1, 100); if (randomUpodobanie <= 2) { objectiveType = UpodobaniaStudenta[0]; } else if (randomUpodobanie <= 52) { objectiveType = UpodobaniaStudenta[1]; } else if (randomUpodobanie <= 62) { objectiveType = UpodobaniaStudenta[2]; } else if (randomUpodobanie <= 72) { objectiveType = UpodobaniaStudenta[3]; } else if (randomUpodobanie <= 95) { objectiveType = UpodobaniaStudenta[4]; } else { objectiveType = UpodobaniaStudenta[5]; } List <Miejsce> objective = context.Locations.Where(g => g.type == objectiveType).ToList(); int index = random.Next(objective.Count); objective[index].visitCount++; objectiveId = objective[index].MiejsceId; context.Locations.AddOrUpdate(objective[index]); context.SaveChanges(); } else if (type == "zwykłyturysta") { int randomUpodobanie = random.Next(1, 100); if (randomUpodobanie <= 2) { objectiveType = Upodobaniaturysty[0]; } else if (randomUpodobanie <= 30) { objectiveType = Upodobaniaturysty[1]; } else if (randomUpodobanie <= 40) { objectiveType = Upodobaniaturysty[2]; } else if (randomUpodobanie <= 60) { objectiveType = Upodobaniaturysty[3]; } else if (randomUpodobanie <= 80) { objectiveType = Upodobaniaturysty[4]; } else { objectiveType = Upodobaniaturysty[5]; } List <Miejsce> objective = context.Locations.Where(g => g.type == objectiveType).ToList(); int index = random.Next(objective.Count); objective[index].visitCount++; objectiveId = objective[index].MiejsceId; context.Locations.AddOrUpdate(objective[index]); context.SaveChanges(); } else if (type == "kulinarnyturysta") { int randomUpodobanie = random.Next(1, 100); if (randomUpodobanie <= 2) { objectiveType = UpodobaniaKulinarnegoTurysty[0]; } else if (randomUpodobanie <= 40) { objectiveType = UpodobaniaKulinarnegoTurysty[1]; } else if (randomUpodobanie <= 70) { objectiveType = UpodobaniaKulinarnegoTurysty[2]; } else if (randomUpodobanie <= 85) { objectiveType = UpodobaniaKulinarnegoTurysty[3]; } else { objectiveType = UpodobaniaKulinarnegoTurysty[4]; } List <Miejsce> objective = context.Locations.Where(g => g.type == objectiveType).ToList(); int index = random.Next(objective.Count); objective[index].visitCount++; objectiveId = objective[index].MiejsceId; context.Locations.AddOrUpdate(objective[index]); context.SaveChanges(); } else { int randomUpodobanie = random.Next(1, 100); if (randomUpodobanie <= 2) { objectiveType = UpodobaniaReligijnegoTurysty[0]; } else if (randomUpodobanie <= 40) { objectiveType = UpodobaniaReligijnegoTurysty[1]; } else if (randomUpodobanie <= 80) { objectiveType = UpodobaniaReligijnegoTurysty[2]; } else { objectiveType = UpodobaniaReligijnegoTurysty[3]; } List <Miejsce> objective = context.Locations.Where(g => g.type == objectiveType).ToList(); int index = random.Next(objective.Count); objective[index].visitCount++; objectiveId = objective[index].MiejsceId; context.Locations.AddOrUpdate(objective[index]); context.SaveChanges(); } return(objectiveId); }