Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Nationality,FeedBack")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Nom,Prenom,Email,MotPass")] User user)
        {
            if (ModelState.IsValid)
            {
                db.users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Exemplo n.º 3
0
        public static BdContext CreateInMemoryContext(string dbName)
        {
            var options = new DbContextOptionsBuilder <BdContext>().UseInMemoryDatabase(databaseName: dbName).Options;
            var context = new BdContext(options);

            context.AddRange(TestUtils.LoadDb <Alive>(@"DbMocks/DuplicatedDocuments.json"));

            context.SaveChanges();

            return(context);
        }
Exemplo n.º 4
0
        public void CreateDbWithDuplicateContraint()
        {
            var options = new DbContextOptionsBuilder <BdContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var context = new BdContext(options);

            context.AddRange(TestUtils.LoadDb <Alive>(@"DbMocks/DuplicatedDocuments.json"));

            context.SaveChanges();
            //Db inicia já com documento duplicado.
            context.Alive.Count(a => a.Document == 12345).Should().Be(2);
        }
 public ActionResult Registo(Utilizador utilizador)
 {
     if (ModelState.IsValid)
     {
         using (BdContext bd = new BdContext())
         {
             bd.ContaUtilizador.Add(utilizador);
             bd.SaveChanges();
         }
         ModelState.Clear();
         return(RedirectToAction("Login"));
     }
     return(View());
 }
Exemplo n.º 6
0
        public static BdContext CreateSqliteContext(string dbName)
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            var options = new DbContextOptionsBuilder <BdContext>().UseSqlite(connection).Options;


            var context = new BdContext(options);

            context.Database.EnsureCreated();

            context.AddRange(TestUtils.LoadDb <Alive>(@"DbMocks/Alive.json"));
            context.SaveChanges();

            return(context);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            using (var context = new BdContext("flibusta_online_fb2Entities"))
            {
                context.Autors.Load();
            }
            return;

            for (int i = 0; i < threadCount; i++)
            {
                manualEvents[i] = new ManualResetEvent(false);
            }
            using (libraryEntities context = new libraryEntities())
            {
                var  tmp      = context.libavtornames.OrderBy(x => x.AvtorId).ToList();
                int  counter  = 0;
                long allCount = context.libavtornames.Count();

                while (counter < allCount)
                {
                    for (int i = 0; i < threadCount; i++)
                    {
                        manualEvents[i].Reset();
                        new Thread(AddAvtors).Start(new MyStruct()
                        {
                            Avtor = tmp.Skip(counter).Take(entiresCount).ToList(),
                            Event = manualEvents[i]
                        });
                        counter += entiresCount;
                        //Thread.Sleep(1000);
                    }
                    WaitHandle.WaitAll(manualEvents);
                    Console.WriteLine(counter);
                }
                using (BdContext cont = new BdContext("ConnectionStringName"))
                {
                    foreach (var autor in listAutor)
                    {
                        cont.Autors.Add(autor);
                    }
                    cont.SaveChanges();
                }
            }
            //}
        }
Exemplo n.º 8
0
        public void CreateDbWithConstraintViolationTest()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            var options = new DbContextOptionsBuilder <BdContext>().UseSqlite(connection).Options;

            using (var context = new BdContext(options))
            {
                context.Database.EnsureCreated();

                context.AddRange(TestUtils.LoadDb <Alive>(@"DbMocks/DuplicatedDocuments.json"));
                Action saveContext = () => context.SaveChanges();

                saveContext.Should().Throw <DbUpdateException>()
                .WithInnerException <SqliteException>();
            }
        }
Exemplo n.º 9
0
        public ActionResult CreateUserProfile([FromBody] IEnumerable <Answer> result)
        {
            try
            {
                foreach (Answer eAnswer in result)
                {
                    _context.Answers.Add(eAnswer);
                }

                _context.SaveChanges();

                return(Ok()); //Created()
            }
            catch
            {
                return(BadRequest());
            }
        }
Exemplo n.º 10
0
 public void Save()
 {
     _bdContex.SaveChanges();
 }
Exemplo n.º 11
0
 public void Add(Inscription inscription)
 {
     dal.Inscription.Add(inscription);
     dal.SaveChanges();
 }