Exemplo n.º 1
1
        internal static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());

            using (var db = new StudentSystemContext())
            {
                var material = new Material
                {
                    Content = "za sega njama"
                };
                db.Materials.Add(material);

                var course = new Course
                {
                    Name = "Algorihms",
                    Description = "gadno"
                };
                course.Materials.Add(material);
                db.Courses.Add(course);

                var student = new Student
                {
                    Name = "Pesho",
                    Number = 10000
                };
                student.Cources.Add(course);
                db.Students.Add(student);

                db.SaveChanges();
            }
        }
        private static void Main(string[] args)
        {
            var db = new StudentSystemContext();
            using (db)
            {
                db.Courses.Add(
                    new Course
                        {
                            Description = "C# course",
                            Students = new List<Student>() { new Student { Name = "Pencho", Number = 13 } }
                        });
                db.SaveChanges();

                var students = db.Students.Select(x => new
                {
                    x.Name,
                    x.Courses
                });
                foreach (var student in students)
                {
                    Console.WriteLine(student.Name + " participates in " + string.Join(",", student.Courses.Select(x => x.Description)));
                }
            }

            
        }
Exemplo n.º 3
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());
            var db = new StudentSystemContext();

            using (db)
            {
                var homework = new Homework();
                var student = new Student();
                var course = new Course();

                student.FirstName = "Gancho";
                student.LastName = "Minchev";
                student.StudentNumber = 12345;

                course.Name = "Animals";
                course.Students.Add(student);
                course.Homeworks.Add(homework);
                course.Materials = "Books";
                course.Students.Add(student);

                homework.Content = "African Animals";
                homework.Course = course;
                student.Homeworks.Add(homework);

                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());

            var db = new StudentSystemContext();
            db.SaveChanges();
        }
Exemplo n.º 5
0
        static void Main()
        {
            //Database.SetInitializer(new DropCreateDatabaseAlways<StudentSystemContext>());
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());

            StudentSystemContext dbContext = new StudentSystemContext();

            var student = new Student()
            {
                Name = "Gosho",
                Number = "15",
                Courses = new HashSet<Course>()
                {
                    new Course()
                    {
                        Name = "Entity Framework",
                        Description = "Entity Framework Entity Framework Entity Framework Entity Framework ",
                        Material = "Data base miracles Data base miracles Data base miracles",
                    }
                },
            };

            dbContext.Students.Add(student);
            Console.WriteLine("Student added.");

            //var students = dbContext.Students.Where(s => s.Name == "Pesho");
            //Console.WriteLine(student.Name);

            dbContext.SaveChanges();
        }
Exemplo n.º 6
0
        /* 02. Write a console application that uses the data.*/
        /// <summary>
        /// Mains this instanse.
        /// </summary>
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());
            using (var db = new StudentSystemContext())
            {
                var pesho = new Student { Name = "Pesho", Number = 666 };
                db.Students.Add(pesho);
                db.SaveChanges();

                var dbCourse = new Course
                {
                    Name = "Database Course",
                    Description = "Basic Database operations",
                    Materials = "http://telerikacademy.com/Courses/Courses/Details/98"
                };
                db.Courses.Add(dbCourse);
                db.SaveChanges();

                var course = db.Courses.First(c => c.Name == dbCourse.Name);
                var student = db.Students.First(s => s.Number == pesho.Number);

                var hw = new Homework
                {
                    Content = "Empty Homework",
                    TimeSent = DateTime.Now,
                    CourseId = course.CourseId,
                    StudentId = student.StudentID
                };
                db.Homeworks.Add(hw);
                db.SaveChanges();
            }

            ListStudents();
        }
Exemplo n.º 7
0
 private static void PrintStudents(StudentSystemContext studentSystemContext)
 {
     Console.WriteLine("Students: ");
     foreach (var students in studentSystemContext.Students.Include("Courses"))
     {
         Console.WriteLine(" - {0} -> present in {1} course(s).", students.Name, students.Courses.Count());
     }
 }
Exemplo n.º 8
0
 private static void PrintCourses(StudentSystemContext studentSystemContext)
 {
     Console.WriteLine("\nCourses: ");
     foreach (var course in studentSystemContext.Courses.Include("Homeworks"))
     {
         Console.WriteLine(" - {0} -> has {1} homework(s).", course.Description, course.Homeworks.Count());
     }
 }
Exemplo n.º 9
0
 static void Main()
 {
     Database.SetInitializer(
         new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());
     var db = new StudentSystemContext();
     db.Students.Add(new Student { Name = "gosho", Number = "123456" });
     db.SaveChanges();
 }
Exemplo n.º 10
0
        private static void Main()
        {
            var studentSystemContext = new StudentSystemContext();
            studentSystemContext.Database.Initialize(true);

            PrintStudents(studentSystemContext);

            PrintCourses(studentSystemContext);
        }
Exemplo n.º 11
0
        static void Main()
        {
            var context = new StudentSystemContext();

            //This is to create the data base Problem01

            int count = context.Students.;
            Console.WriteLine(count);

            //Fill created database Problem 02

            //var student = new Student()
            //{
            //    Id = 1,
            //    Name = "Dimitar Stoyanov",
            //    PhoneNumber = "+359 123 231 491",
            //    RegstrationDate = DateTime.Now,
            //};

            //var resource = new Resource()
            //{
            //    Name = "C# Data Structures - Liner Data",
            //    ResourceType = ResourceType.Video,
            //    URL = "https://softuni.bg/trainings/1147/Data-Structures-June-2015"
            //};

            //var homework = new Homework()
            //{
            //    Content = "Linear Data Structures – Stacks and Queues",
            //    ContentType = ContentType.zip,
            //    SubmissionDate = new DateTime(2016, 01, 12)
            //};

            //var course = new Course()
            //{
            //    Name = "Maths",
            //    Description = "Algebra",
            //    StartDate = new DateTime(2015, 7, 12),
            //    EndDate = new DateTime(2015, 8, 15),
            //    Price = 200
            //};

            //course.Students.Add(student);
            //course.Homeworks.Add(homework);
            //course.Resources.Add(resource);

            //student.Courses.Add(course);
            //student.Homeworks.Add(homework);

            //context.Resources.Add(resource);
            //context.Homeworks.Add(homework);
            //context.Courses.Add(course);
            //context.Students.Add(student);

            //context.SaveChanges();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion<StudentSystemContext,
                    Data.Migrations.Configuration>());

            StudentSystemContext context = new StudentSystemContext();
            context.Students.Add(new Student() {FirstName = "Test",LastName = "Student"});
            context.SaveChanges();
        }
Exemplo n.º 13
0
 private static void ListAllStudents(StudentSystemContext context)
 {
     foreach (var student in context.Students.Include("Courses"))
     {
         Console.WriteLine(
             "Student: {0}; FacultyNumber: {1}; Courses: {2}",
             student.Name,
             student.FacultyNumber,
             string.Join(", ", student.Courses.Select(x => x.Name)));
     }
 }
Exemplo n.º 14
0
 private static void ListAllCourses(StudentSystemContext context)
 {
     foreach (var course in context.Courses.Include("Students"))
     {
         Console.WriteLine(
             "Course: {0}; Description: {1}; Courses: {2}",
             course.Name,
             course.Description,
             string.Join(", ", course.Students.Select(x => x.Name)));
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// List all students.
        /// </summary>
        private static void ListStudents()
        {
            using (var db = new StudentSystemContext())
            {
                var students = db.Students;

                foreach (var student in students)
                {
                    Console.WriteLine("Name: {0}, Number: {1}", student.Name, student.Number);
                }
            }
        }
Exemplo n.º 16
0
 public static void thirdQuery()
 {
     var context = new StudentSystemContext();
     var courses = context.Courses
         .Where(c => c.Resources.Count > 6)
         .OrderByDescending(c => c.Resources.Count)
         .ThenByDescending(c => c.StartDate)
         .Select(c => new
         {
             c.Name,
             c.Resources.Count
         });
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            var dataBase = new StudentSystemContext();

            var course = new Courses { Parent = null, Name = "Database course", Description = "A course that all junior develepers need to pass", Materials  = "Google.com"};
            dataBase.Courses.Add(course);

            var studentOnDataBaseCourse = new Students { Name = "Bill Gates", Number = 1 };

            var homeWorkForDataBases = new Homework { Content = "Introduction in SQL" };

            dataBase.SaveChanges();
        }
Exemplo n.º 18
0
        public static void Main()
        {
            // IMPORTANT: Change connection string in "StudentSystem.Data/ConnectionStrings.settings"

            Console.Write("Loading...");

            var forumSystemContext = new StudentSystemContext();
            forumSystemContext.Database.Initialize(true);

            PrintStudents(forumSystemContext);
            PrintCourses(forumSystemContext);
            PrintHomeworks(forumSystemContext);
        }
Exemplo n.º 19
0
 public static void secondQuery()
 {
     var context = new StudentSystemContext();
     var courses = context.Courses
         .OrderBy(c => c.StartDate)
         .ThenByDescending(c => c.EndDate)
         .Select(c => new
         {
             c.Name,
             c.Description,
             c.Resources
         });
 }
Exemplo n.º 20
0
 public static void firstQuery()
 {
     var context = new StudentSystemContext();
     var students = context.Students.Select(s => new
     {
         s.Name,
         Homeworks = s.Homeworks.Select(h => new
         {
             h.Content,
             h.HomeworkContentType
         })
     });
 }
Exemplo n.º 21
0
        static void Main()
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());

            using (StudentSystemContext dbContext = new StudentSystemContext())
            {
                foreach (Student student in dbContext.Students)
                {
                    Console.WriteLine("{0} {1} - {2}",
                        student.FirstName, student.LastName, student.FacultyNumber);
                }
            }
        }
Exemplo n.º 22
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());
         
            var dbContext = new StudentSystemContext();
            // Force Initialization.
            dbContext.Database.Initialize(true);

            Console.WriteLine("All Students:");
            ListAllStudents(dbContext);

            Console.WriteLine("All Courses:");
            ListAllCourses(dbContext);
        }
Exemplo n.º 23
0
        private static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());

            using (var studentSystem = new StudentSystemContext())
            {
                studentSystem.Students.Add(new Student()
                {
                    Name = "Svetlin Nakov",
                    Number = 5000981
                });

                studentSystem.SaveChanges();
            }
        }
Exemplo n.º 24
0
 public static void fifthQuery()
 {
     var context = new StudentSystemContext();
     var students = context.Students
         .OrderByDescending(s => s.Courseses.Sum(c => c.Price))
         .ThenByDescending(s => s.Courseses.Count)
         .ThenBy(s => s.Name)
         .Select(s => new
         {
             s.Name,
             s.Courseses.Count,
             Price = s.Courseses.Sum(c => c.Price),
             AveragePrice = s.Courseses.Average(c => c.Price)
         });
 }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            var context = new StudentSystemContext();
            //var count = context.Courses.Count();
            //Console.WriteLine(count);
            
            //var migrationStrategy = new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>();
            //migrationStrategy.InitializeDatabase(context);

           

            
            


        }
Exemplo n.º 26
0
        private static void PrintHomeworks(StudentSystemContext forumSystemContext)
        {
            Console.WriteLine("\nHomeworks: ");
            foreach (var homework in forumSystemContext.Homeworks.Include("Materials").Where(h => !h.StudentId.HasValue))
            {
                Console.WriteLine(" - {0} ({1}) -> has {2} material(s).",
                    homework.Content, homework.Course.Description, homework.Materials.Count());

                foreach (var material in homework.Materials)
                {
                    Console.WriteLine("    - {0} ({2}) - {1}", material.Type, material.DownloadUrl, material.Homework.Content);
                }

                Console.WriteLine();
            }
        }
Exemplo n.º 27
0
 public static void fourthQuery()
 {
     var context = new StudentSystemContext();
     var courseDate = new DateTime(2011, 06, 12);
     var courses = context.Courses
         .Where(c => c.StartDate <= courseDate &&
                     c.EndDate >= courseDate)
         .OrderByDescending(c => c.Students.Count)
         .ThenByDescending(c => (c.EndDate - c.StartDate).Days)
         .Select(c => new
         {
             c.Name,
             c.StartDate,
             c.EndDate,
             CourseDuration = (c.EndDate - c.StartDate).Days,
             c.Students.Count
         });
 }
 public object GetService(Type serviceType)
 {
     if (serviceType == typeof(StudentsController))
     {
         DbContext context = new StudentSystemContext();
         var studentRepository = new EfRepository<Student>(context);
         var schoolRepository = new EfRepository<School>(context);
         var markRepository = new EfRepository<Mark>(context);
         return new StudentsController(studentRepository, schoolRepository, markRepository);
     }
     else if (serviceType == typeof(SchoolsController))
     {
         DbContext context = new StudentSystemContext();
         var schoolRepository = new EfRepository<School>(context);
         var studentRepository = new EfRepository<Student>(context);
         return new SchoolsController(schoolRepository, studentRepository);
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 29
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion
                <StudentSystemContext, Configuration>());

            var context = new StudentSystemContext();
            var course = new Course { Name = "Database" };
            var student = new Student { StudentNumber = 31150 };
            student.Name = "Pesho Petrov";
            course.Students.Add(student);
            student.Courses.Add(course);
            var homework = new Homework { SendDate = DateTime.Now, CourseId = 1, StudentId = 1 };
            var lecture = new Material { CourseId = 1 };
            student.Homeworks.Add(homework);
            course.Materials.Add(lecture);
            course.Homeworks.Add(homework);
            context.Courses.Add(course);
            context.Students.Add(student);
            context.Homeworks.Add(homework);
            context.Materials.Add(lecture);
            context.SaveChanges();
        }
Exemplo n.º 30
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());

            Random randomGen = new Random();

            using (var dbContext = new StudentSystemContext())
            {
                for (int i = 0; i < 20; i++)
                {
                    Student student1 = new Student()
                    {
                        Name = "Ivan" + i,
                        StudentNumber = randomGen.Next(100000, 999999)
                    };

                    dbContext.Students.Add(student1);
                }

                dbContext.SaveChanges();
            }
        }
Exemplo n.º 31
0
 public DetailsModel(StudentSystem.Data.StudentSystemContext context)
 {
     _context = context;
 }
Exemplo n.º 32
0
 public DeleteModel(StudentSystem.Data.StudentSystemContext context)
 {
     _context = context;
 }