Exemplo n.º 1
0
        public static void Main()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways <StudentSystemDbContext>());

            var data = new StudentsSystemData();

            var courses = data.Courses.All();

            var students = data.Students.All();

            var courseNames = new string[] { "js apps", "js ui and dom", "csharp oop", "databases" };

            foreach (var name in courseNames)
            {
                data.Courses.Add(new Course()
                {
                    Description = "kopon",
                    Name        = name
                });
            }

            data.SaveChanges();

            foreach (var course in courses)
            {
                Console.WriteLine(course.Name);
            }

            var courseServices = new CourseServices(data.Courses);

            Console.WriteLine(string.Join(", ", courseServices.GetJavascriptCourses().Select(c => c.Name)));

            var student = new Student()
            {
                FirstName             = "pencho",
                LastName              = "genchov",
                Level                 = 99,
                AdditionalInformation = new StudentInfo()
                {
                    Address = "ul. gorno nanadolnishte", Email = "*****@*****.**"
                }
            };

            data.Students.Add(student);
            courseServices.AddStudentToCourse(student, "js apps");

            data.SaveChanges();

            var pencho = data.Students.All().FirstOrDefault(s => s.FirstName == "pencho");

            Console.WriteLine("pencho is in the " + pencho.Courses.FirstOrDefault().Name + " course");
        }
Exemplo n.º 2
0
        public IHttpActionResult Post(Student stud)
        {
            data.Students.Add(stud);
            data.SaveChanges();
            var student = data.Students.SearchFor(st => st.FirstName == stud.FirstName).FirstOrDefault();

            if (student != null)
            {
                return(this.Ok(string.Format("Student {0} {1} successfuly added.", student.FirstName, student.LastName)));
            }

            return(this.InternalServerError());
        }
Exemplo n.º 3
0
        public static void Main()
        {
            var data = new StudentsSystemData();

            var courses = data.Courses.All();

            foreach (var course in courses)
            {
                Console.WriteLine(course.Name);
            }

            data.Courses.Add(new Course
            {
                Name        = "Repo Pattern",
                Description = "Cool"
            });

            data.SaveChanges();

            var students = data.Students.All();

            Console.WriteLine(students.Count());
        }
Exemplo n.º 4
0
        public static void Main()
        {
            var data = new StudentsSystemData();

            var courses = data.Courses.All();

            foreach (var course in courses)
            {
                Console.WriteLine(course.Name);
            }

            data.Courses.Add(new Course
            {
                Name        = "Repo Pattern",
                Description = "Cool"
            });

            data.SaveChanges();

            var students = data.Students.All();

            Console.WriteLine(students.Count());

            //var masters = data.Students.Where(st => st.Level > 1);
            //PrintStudents(masters);

            //var ivaylos = data.Students.Where(st => st.FirstName == "Ivaylo");
            //PrintStudents(ivaylos);

            //var firstMaster = data.Students.FirstOrDefault(st => st.Level == -5);
            //if (firstMaster == null)
            //{
            //    Console.WriteLine("NULL");
            //}

            //var levels = data.Students.Select(st => new
            //    {
            //        Level = st.Level,
            //        LastName = st.LastName
            //    });

            //foreach (var level in levels)
            //{
            //    Console.WriteLine(level.LastName);
            //}

            //var orderedStudents = data.Students
            //    .OrderBy(st => st.LastName)
            //    .ThenBy(st => st.Level);

            //PrintStudents(orderedStudents);

            //var someQuery = data.Students
            //    .Where(st => st.Level > 0)
            //    .OrderBy(st => st.LastName)
            //    .Select(st => new
            //    {
            //        FirstName = st.FirstName
            //    });

            //var maxLevel = data.Students.Max(st => st.Level);

            //Console.WriteLine(maxLevel);

            //Console.WriteLine(data.Students.Find(2).LastName);

            //data.Courses.Add(new Course
            //{
            //    Name = "Entity Framework",
            //    Description = "Code First"
            //});

            //data.SaveChanges();

            //var entityFrCourse = data.Courses.FirstOrDefault(c => c.Name == "Entity Framework");

            //foreach (var master in masters)
            //{
            //    // entityFrCourse.Students.Add(master);
            //}

            //data.SaveChanges();

            //var activeCourses = data.Courses.Where(c => c.Students.Count() > 0);

            //foreach (var course in activeCourses)
            //{
            //    course.Description = "Code First Is Cool";
            //    Console.WriteLine(course.Name);
            //}

            //data.SaveChanges();

            //var courses = data.Courses.ToList();

            //foreach (var course in courses)
            //{
            //    if (course.Students.Count() == 0)
            //    {
            //        data.Courses.Remove(course);
            //    }
            //}

            //var coursesWithStudents = data.Courses.Include(x => x.Students);

            //data.SaveChanges();

            //var someQuery = data.Students
            //    .Where(st => st.Level > 0)
            //    .OrderBy(st => st.LastName)
            //    .Select(st => new
            //    {
            //        FirstName = st.FirstName
            //    })
            //    .ToList();

            //var courseFirst = data.Courses.FirstOrDefault();

            //var courseEntry = data.Entry(courseFirst);
            //courseEntry.State = EntityState.Detached;

            //data.Courses.Attach(courseFirst);

            //courseFirst.Name = "Entity Framework";

            //data.SaveChanges();
        }
Exemplo n.º 5
0
        public static void Main()
        {
            var data = new StudentsSystemData();

            var courses = data.Courses.All();

            foreach (var course in courses)
            {
                Console.WriteLine(course.Name);
            }

            data.Courses.Add(new Course
            {
                Name        = "Repo Pattern",
                Description = "Cool"
            });

            data.SaveChanges();

            var students = data.Students.All();

            Console.WriteLine(students.Count());

            var masters = data.Students
                          .SearchFor(st => st.Level > 1);

            PrintStudents(masters);

            var ivaylos = data.Students.SearchFor(st => st.FirstName == "Ivaylo");

            PrintStudents(ivaylos);

            var firstMaster = data.Students.SearchFor(st => st.Level == -5);

            if (firstMaster == null)
            {
                Console.WriteLine("NULL");
            }

            var levels = data.Students.All().Select(st => new
            {
                Level    = st.Level,
                LastName = st.LastName
            });

            foreach (var level in levels)
            {
                Console.WriteLine(level.LastName);
            }

            var orderedStudents = data.Students
                                  .All()
                                  .OrderBy(st => st.LastName)
                                  .ThenBy(st => st.Level);

            PrintStudents(orderedStudents);

            var someQuery = data.Students
                            .All()
                            .Where(st => st.Level > 0)
                            .OrderBy(st => st.LastName)
                            .Select(st => new
            {
                FirstName = st.FirstName
            });

            var maxLevel = data.Students.All().Max(st => st.Level);

            Console.WriteLine(maxLevel);

            data.Courses.Add(new Course
            {
                Name        = "Entity Framework",
                Description = "Code First"
            });

            data.SaveChanges();

            var entityFrCourse = data.Courses.SearchFor(c => c.Name == "Entity Framework").FirstOrDefault();

            foreach (var master in masters)
            {
                entityFrCourse.Students.Add(master);
            }

            data.SaveChanges();

            var activeCourses = data.Courses.SearchFor(c => c.Students.Count() > 0);

            foreach (var course in activeCourses)
            {
                course.Description = "Code First Is Cool";
                Console.WriteLine(course.Name);
            }

            data.SaveChanges();
        }
Exemplo n.º 6
0
        public static void Main()
        {
            var data = new StudentsSystemData();

            var courses = data.Courses.All();

            foreach (var course in courses)
            {
                Console.WriteLine(course.Name);
            }

            data.Courses.Add(new Course
            {
                Name = "Repo Pattern",
                Description = "Cool"
            });

            data.SaveChanges();

            var students = data.Students.All();

            Console.WriteLine(students.Count());

            var masters = data.Students.SearchFor(st => st.Level > 1);
            PrintStudents(masters);

            var ivaylos = data.Students.SearchFor(st => st.FirstName == "Ivaylo");
            PrintStudents(ivaylos);

            var firstMaster = data.Students.SearchFor(st => st.Level == -5).FirstOrDefault();
            if (firstMaster == null)
            {
                Console.WriteLine("NULL");
            }

            var levels = data.Students.All().Select(st => new
                {
                    Level = st.Level,
                    LastName = st.LastName
                });

            foreach (var level in levels)
            {
                Console.WriteLine(level.LastName);
            }

            var orderedStudents = data.Students
                .All()
                .OrderBy(st => st.LastName)
                .ThenBy(st => st.Level);

            PrintStudents(orderedStudents);

            var someQuery = data.Students
                .All()
                .Where(st => st.Level > 0)
                .OrderBy(st => st.LastName)
                .Select(st => new
                {
                    FirstName = st.FirstName
                });

            var maxLevel = data.Students.All().Max(st => st.Level);

            Console.WriteLine(maxLevel);

            data.Courses.Add(new Course
            {
                Name = "Entity Framework",
                Description = "Code First"
            });

            data.SaveChanges();

            var entityFrCourse = data.Courses.SearchFor(c => c.Name == "Entity Framework").FirstOrDefault();

            foreach (var master in masters)
            {
                 entityFrCourse.Students.Add(master);
            }

            data.SaveChanges();

            var activeCourses = data.Courses.SearchFor(c => c.Students.Count() > 0);

            foreach (var course in activeCourses)
            {
                course.Description = "Code First Is Cool";
                Console.WriteLine(course.Name);
            }

            data.SaveChanges();
        }
Exemplo n.º 7
0
        public static void Main()
        {
            var data = new StudentsSystemData();

            var courses = data.Courses.All();

            foreach (var course in courses)
            {
                Console.WriteLine(course.Name);
            }

            data.Courses.Add(new Course
            {
                Name = "Repo Pattern",
                Description = "Cool"
            });

            data.SaveChanges();

            var students = data.Students.All();

            Console.WriteLine(students.Count());

            // var masters = data.Students.Where(st => st.Level > 1);
            // PrintStudents(masters);

            // var ivaylos = data.Students.Where(st => st.FirstName == "Ivaylo");
            // PrintStudents(ivaylos);

            // var firstMaster = data.Students.FirstOrDefault(st => st.Level == -5);
            // if (firstMaster == null)
            // {
            //    Console.WriteLine("NULL");
            // }

            // var levels = data.Students.Select(st => new
            //    {
            //        Level = st.Level,
            //        LastName = st.LastName
            //    });

            // foreach (var level in levels)
            // {
            //    Console.WriteLine(level.LastName);
            // }

            // var orderedStudents = data.Students
            //    .OrderBy(st => st.LastName)
            //    .ThenBy(st => st.Level);

            // PrintStudents(orderedStudents);

            // var someQuery = data.Students
            //    .Where(st => st.Level > 0)
            //    .OrderBy(st => st.LastName)
            //    .Select(st => new
            //    {
            //        FirstName = st.FirstName
            //    });

            // var maxLevel = data.Students.Max(st => st.Level);

            // Console.WriteLine(maxLevel);

            // Console.WriteLine(data.Students.Find(2).LastName);

            // data.Courses.Add(new Course
            // {
            //    Name = "Entity Framework",
            //    Description = "Code First"
            // });

            // data.SaveChanges();

            // var entityFrCourse = data.Courses.FirstOrDefault(c => c.Name == "Entity Framework");

            // foreach (var master in masters)
            // {
            //    // entityFrCourse.Students.Add(master);
            // }

            // data.SaveChanges();

            // var activeCourses = data.Courses.Where(c => c.Students.Count() > 0);

            // foreach (var course in activeCourses)
            // {
            //    course.Description = "Code First Is Cool";
            //    Console.WriteLine(course.Name);
            // }

            // data.SaveChanges();

            // var courses = data.Courses.ToList();

            // foreach (var course in courses)
            // {
            //    if (course.Students.Count() == 0)
            //    {
            //        data.Courses.Remove(course);
            //    }
            // }

            // var coursesWithStudents = data.Courses.Include(x => x.Students);

            // data.SaveChanges();

            // var someQuery = data.Students
            //    .Where(st => st.Level > 0)
            //    .OrderBy(st => st.LastName)
            //    .Select(st => new
            //    {
            //        FirstName = st.FirstName
            //    })
            //    .ToList();

            // var courseFirst = data.Courses.FirstOrDefault();

            // var courseEntry = data.Entry(courseFirst);
            // courseEntry.State = EntityState.Detached;

            // data.Courses.Attach(courseFirst);

            // courseFirst.Name = "Entity Framework";

            // data.SaveChanges();
        }