Exemplo n.º 1
0
 private static void Main()
 {
     using (var context = new StudentsDbContext())
     {
         Console.WriteLine(context.Marks.Count());
     }
 }
Exemplo n.º 2
0
 public async Task <IActionResult> GetStudent([FromQuery] int id)
 {
     using (var context = new StudentsDbContext())
     {
         return(Ok(await context.Students.FirstOrDefaultAsync(x => x.Id == id)));
     }
 }
 public StudentsController()
 {
     this.db        = new StudentsDbContext();
     this.students  = new EfGenericRepository <Student>(this.db);
     this.homeworks = new EfGenericRepository <Homework>(this.db);
     this.courses   = new EfGenericRepository <Course>(this.db);
 }
Exemplo n.º 4
0
        public static void Main()
        {
            using (var db = new StudentsDbContext())
            {
                db.Database.Migrate();
            }

            var stopwatch = Stopwatch.StartNew();

            using (var db = new StudentsDbContext())
            {
                SameQuery(db);
            }

            Console.WriteLine(stopwatch.Elapsed);

            stopwatch = Stopwatch.StartNew();

            using (var db = new StudentsDbContext())
            {
                SameQuery(db);
            }

            Console.WriteLine(stopwatch.Elapsed);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetCourses([FromQuery] int idStudent)
        {
            try
            {
                await parallelism.WaitAsync();

                using (var context = new StudentsDbContext())
                {
                    List <Reservation> prenotazioni = await context.Reservations.ToListAsync();

                    List <Course> listaCorsi = new List <Course>();
                    foreach (var prenotazione in prenotazioni)
                    {
                        if (prenotazione.IdStudent == idStudent)
                        {
                            listaCorsi.Add(await context.Courses.FirstOrDefaultAsync(x => x.Id == prenotazione.IdCouse));
                        }
                    }

                    return(Ok(listaCorsi));
                }
            }
            finally
            {
                parallelism.Release();
            }
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentsDbContext, Configuration>());

            var dbContext = new StudentsDbContext();

            var studentNames = dbContext.Students.Select(s => s.Name).ToList();
        }
        public static void Initialize()
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion<StudentsDbContext, DataLink.Migrations.Configuration>());

            using (var context = new StudentsDbContext())
            {
                context.Students.FirstOrDefault();
            }
        }
Exemplo n.º 8
0
        public async Task <IActionResult> UpdateReservation([FromBody] Reservation reservation)
        {
            using (var context = new StudentsDbContext())
            {
                context.Reservations.Update(reservation);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> UpdateStudent([FromBody] Student student)
        {
            using (var context = new StudentsDbContext())
            {
                context.Students.Update(student);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> UpdateCourse([FromBody] Course course)
        {
            using (var context = new StudentsDbContext())
            {
                context.Courses.Update(course);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> GetCourses([FromQuery] int idStudent, string facolta)
        {
            using (var context = new StudentsDbContext())
            {
                List <Course> listaCorsi = await context.Courses.ToListAsync();

                List <Reservation> prenotazioni = await context.Reservations.ToListAsync();

                List <int>    listaMateriePrenotate = new List <int>();
                List <Course> listaCorsiPrenotabili = new List <Course>();
                bool          verifica;

                foreach (var prenotazione in prenotazioni)
                {
                    if (prenotazione.IdStudent == idStudent)
                    {
                        listaMateriePrenotate.Add(prenotazione.IdCouse);
                    }
                }

                for (int i = 0; i < listaCorsi.Count; i++)
                {
                    if (!listaCorsi[i].faculty.Equals(facolta))
                    {
                        verifica = true;
                    }
                    else
                    {
                        verifica = false;
                    }

                    for (int j = 0; j < listaMateriePrenotate.Count; j++)
                    {
                        if (listaCorsi[i].faculty.Equals(facolta))
                        {
                            if (listaCorsi[i].Id == listaMateriePrenotate[j])
                            {
                                verifica = true;
                            }
                        }
                        else
                        {
                            verifica = true;
                        }
                    }

                    if (verifica == false)
                    {
                        listaCorsiPrenotabili.Add(listaCorsi[i]);
                    }
                }

                return(Ok(listaCorsiPrenotabili));
            }
        }
Exemplo n.º 12
0
 public IActionResult SetupDatabase()
 {
     lock (setupLock)
     {
         using (var context = new StudentsDbContext())
         {
             // Create database
             context.Database.EnsureCreated();
         }
         return(Ok("database created"));
     }
 }
Exemplo n.º 13
0
        public async Task <IActionResult> DeleteStudent([FromQuery] int id)
        {
            using (var context = new StudentsDbContext())
            {
                var student = await context.Students.FirstOrDefaultAsync(x => x.Id == id);

                context.Students.Remove(student);
                await context.SaveChangesAsync();

                return(Ok());
            }
        }
Exemplo n.º 14
0
        public static void Main()
        {
            using var db = new StudentsDbContext();

            db.Database.EnsureCreated();

            db.Students.Add(new Student
            {
                FirstName = "Ivan",
                LastName  = "Petrov",
                Type      = StudentType.Enrolled()
            });
        }
Exemplo n.º 15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, StudentsDbContext studentsDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Api for Students"));
            app.UseMvc();
            // if db doesn't exist, create one
            studentsDbContext.Database.EnsureCreated();
        }
Exemplo n.º 16
0
        private static void SameQuery(StudentsDbContext db)
        {
            var student = db.Students.FirstOrDefault().FullName;
            var courses = db.Courses
                          .Select(x => new
            {
                x.Name,
                TotalStudents = x.Students.Where(y => y.Course.Homeworks.Average(z => z.Score) > 2).Count(),
                Students      = x.Students.Select(y => new { FullName = y.Student.FirstName + " " + y.Student.LastName, Score = y.Student.Homeworks.Average(z => z.Score) })
            }).ToList();

            Console.WriteLine(courses.Count);
        }
Exemplo n.º 17
0
        public static void Main()
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion<StudentsDbContext, Configuration>());

            var db = new StudentsDbContext();
            var generator = new DataGenerator();

            generator.GenerateCourses(db, 20);
            generator.GenerateStudents(db, 100);
            db.SaveChanges();
            generator.GenerateHomeworks(db, 250);
            db.SaveChanges();
        }
Exemplo n.º 18
0
        public static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentsDbContext, Configuration>());

            var dbContext = new StudentsDbContext();

            SeedData(dbContext);

            var studentNames = dbContext.Students.Select(s => s.Name).ToList();

            foreach (var studentName in studentNames)
            {
                Console.WriteLine(studentName);
            }
        }
Exemplo n.º 19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, StudentsDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                DbSeeder.SeedDb(context);
            }

            app.UseHttpsRedirection();
            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
Exemplo n.º 20
0
        public async Task <IActionResult> GetStudents()
        {
            try
            {
                await parallelism.WaitAsync();

                using (var context = new StudentsDbContext())
                {
                    return(Ok(await context.Students.ToListAsync()));
                }
            }
            finally
            {
                parallelism.Release();
            }
        }
Exemplo n.º 21
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentsDbContext, Configuration>());

            var db = new StudentsDbContext();

            var student = new Student()
            {
                Name   = "KOKO",
                Number = 367
            };

            db.Students.Add(student);
            db.SaveChanges();
            Console.WriteLine("Students {0} / Courses {1}", db.Students.Count(), db.Courses.Count());
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentsDbContext, Configuration>());
            using (var dbContext = new StudentsDbContext())
            {
                var student = new Student
                {
                    Name      = "ivan",
                    StudentId = 1,
                    Number    = 10
                };

                dbContext.Students.Add(student);

                //dbContext.Database.CreateIfNotExists();
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            using (var context = new StudentsDbContext())
            {
                // Create database
                context.Database.EnsureCreated();

                Student s = new Student()
                {
                    Name        = "Giovanni",
                    DateOfBirth = new DateTime(2012, 1, 1),
                };
                context.Students.Add(s);
                context.SaveChanges();

                Teacher t = new Teacher()
                {
                    Name        = "Filippo",
                    DateOfBirth = new DateTime(2017, 10, 10),
                };
                context.Teachers.Add(t);
                context.SaveChanges();

                School sc = new School()
                {
                    Name = "Principe Umberto",
                    City = "Catania",
                };
                context.Schools.Add(sc);
                context.SaveChanges();
            }
            //var host = new WebHostBuilder()
            //.UseKestrel()
            //.UseStartup<Startup>()
            //.Build();

            //Task restService = host.RunAsync();

            //System.Diagnostics.Process.Start("chrome.exe", "http://localhost/netcoreapp2.0/corsoing/");
            //System.Diagnostics.Process.Start("cmd", "/C start http://localhost/netcoreapp2.0/corsoing/");
            //restService.Wait();
        }
Exemplo n.º 24
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentsDbContext, Configuration>());

            var db = new StudentsDbContext();

            var student = new Student
            {
                Name = "Nikolay Kostov",
                FacultyNumber = 232435231
            };

            db.Students.Add(student);
            db.SaveChanges();

            

            Console.WriteLine(db.Students.Count());

        }
Exemplo n.º 25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, StudentsDbContext studentsDb)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            studentsDb.Database.EnsureCreated();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemplo n.º 26
0
        public void HttpStatusTest()
        {
            DbContextOptions <StudentsDbContext> options = new DbContextOptionsBuilder <StudentsDbContext>()
                                                           .UseInMemoryDatabase(databaseName: "getStatusCode")
                                                           .Options;

            using (StudentsDbContext context = new StudentsDbContext(options))
            {
                Student student = new Student()
                {
                    FirstName = "Test",
                    LastName  = "McStudent",
                    Phone     = "5",
                    HomeClass = "Lunch",
                };
                context.Students.Add(student);
                context.SaveChanges();
                HomeController controller   = new HomeController(context);
                var            result       = controller.Index();
                ObjectResult   objectResult = (ObjectResult)result;
                Assert.Equal(HttpStatusCode.OK, (HttpStatusCode)objectResult.StatusCode.Value);
            }
        }
Exemplo n.º 27
0
        private static void SeedData(StudentsDbContext dbContext)
        {
            var generator = new DataGenerator();

            var students = generator.GenerateStudents(10);

            var courses = generator.GenerateCourses(10);

            var index = 0;

            foreach (var student in students)
            {
                student.Courses = courses.Skip(index).ToList();
                dbContext.Students.Add(student);
            }

            dbContext.SaveChanges();
            dbContext.Dispose();

            dbContext = new StudentsDbContext();

            var homeworks      = generator.GenerateHomeworks(5);
            var actualStudents = dbContext.Students.ToList();
            var actualCourses  = dbContext.Courses.ToList();

            var studentsToSkip = 0;

            foreach (var homework in homeworks)
            {
                homework.Student = actualStudents.Skip(studentsToSkip).FirstOrDefault();
                homework.Course  = actualCourses.Skip(studentsToSkip).FirstOrDefault();
                dbContext.Homeworks.Add(homework);
            }

            dbContext.SaveChanges();
        }
Exemplo n.º 28
0
 public EnrollmentsController(StudentsDbContext studentsDbContext)
 {
     _studentsDbContext = studentsDbContext;
 }
Exemplo n.º 29
0
 public ZdjeciaController(IItemRepository DbitemRepository, StudentsDbContext studentsDbContext)
 {
     ItemRepository = DbitemRepository;
     _dbContext     = studentsDbContext;
 }
Exemplo n.º 30
0
 public StudentService(StudentsDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 31
0
 public StudentRepository(StudentsDbContext context)
 {
     _context = context;
 }
 public StudentsController(StudentsDbContext context)
 {
     _context = context;
 }
Exemplo n.º 33
0
 public StudentsClassRepository(StudentsDbContext context)
 {
     this.context = context;
 }