public ActionResult Create([Bind(Include = "Id,Model,Make,Price")] Cars cars)
        {
            if (ModelState.IsValid)
            {
                db.Cars.Add(cars);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cars));
        }
Esempio n. 2
0
        protected override void Add(TestContext ctx, Parent parent, int count)
        {
            var childrenAdded = new List <Child>(count);

            for (var i = 0; i < count; i++)
            {
                var child = new Child
                {
                    Name = Guid.NewGuid().ToString("N")
                };
                childrenAdded.Add(child);

                ctx.ChildSet.Add(child);
            }
            Timer.CheckPoint($"Added {count}");

            ctx.SaveChanges();
            Timer.CheckPoint("Saved");

            using (var ctx2 = new Test2Context())
            {
                foreach (var child in childrenAdded)
                {
                    ctx2.ParentChildRel2Set.Add(new ParentChildSimpleRel
                    {
                        ParentId = parent.Id,
                        ChildId  = child.Id
                    });
                }
                Timer.CheckPoint($"Added rel {count}");

                ctx2.SaveChanges();
                Timer.CheckPoint("Saved rel");
            }
        }
Esempio n. 3
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new Test2Context(
                serviceProvider.GetRequiredService <
                    DbContextOptions <Test2Context> >()))
     {
         // Look for any movies.
         if (context.Users.Any())
         {
             return;   // DB has been seeded
         }
         context.Users.AddRange(
             new CreateUser {
             NomeR = "raimundo",
             NomeU = "n sei oq e isso",
             Email = "galã[email protected]",
             senha = "NiguemNuncaVaiAcertarIsso"
         },
             new CreateUser {
             NomeR = "maria",
             NomeU = "a estrela",
             Email = "*****@*****.**",
             senha = "senha"
         },
             new CreateUser {
             NomeR = "tiago",
             NomeU = "o matador de porco",
             Email = "*****@*****.**",
             senha = "porco"
         }
             );
         context.SaveChanges();
     }
 }
Esempio n. 4
0
        protected override void Add(TestContext ctx, Parent parent, int count)
        {
            var childBatch = new ChildBatch
            {
                DateTime = DateTime.Now,
                Children = new List <Child>()
            };

            ctx.SessionSet.Add(childBatch);
            ctx.SaveChanges();

            for (var i = 0; i < count; i++)
            {
                var child = new Child
                {
                    Name    = Guid.NewGuid().ToString("N"),
                    BatchId = childBatch.Id
                };
                childBatch.Children.Add(child);
            }
            Timer.CheckPoint($"Added {count}");

            ctx.SaveChanges();
            Timer.CheckPoint("Saved");

            using (var ctx2 = new Test2Context())
            {
                var relBatch = new ParentChildBatch
                {
                    DateTime = DateTime.Now,
                    ParentChildSimpleRels = new List <ParentChildSimpleRel>()
                };
                ctx2.ParentChildBatchSet.Add(relBatch);

                foreach (var child in childBatch.Children)
                {
                    //ctx2.ParentChildRel2Set.Add(new ParentChildSimpleRel
                    relBatch.ParentChildSimpleRels.Add(new ParentChildSimpleRel
                    {
                        ParentId = parent.Id,
                        ChildId  = child.Id
                    });
                }
                Timer.CheckPoint($"Added rel {count}");

                ctx2.SaveChanges();
                Timer.CheckPoint("Saved rel");
            }
        }