예제 #1
0
        private static void ClearDb()
        {
            StudentsContext studentContext = new StudentsContext();

            DbSet <Mark> marks       = studentContext.Set <Mark>();
            List <Mark>  marksAsList = marks.ToList();

            foreach (Mark mark in marksAsList)
            {
                marks.Remove(mark);
            }

            DbSet <Student> students       = studentContext.Set <Student>();
            List <Student>  studentsAsList = studentContext.Set <Student>().ToList();

            foreach (Student student in studentsAsList)
            {
                students.Remove(student);
            }

            DbSet <School> schools       = studentContext.Set <School>();
            List <School>  schoolsAsList = schools.ToList();


            foreach (School school in schoolsAsList)
            {
                schools.Remove(school);
            }

            studentContext.SaveChanges();
        }
예제 #2
0
        public void UpdateStudent_EditElementStudentInXML()
        {
            //Arrange
            StudentsContext context = new StudentsContext();

            Student student = new Student()
            {
                Id        = 9,
                FirstName = "Smit",
                Last      = "Robenson",
                Age       = "32",
                Gender    = "0"
            };

            //act
            context.UpdateStudent(student);

            //Assert
            var element = context.xDoc.Root.Elements("Student").Select(s => s).Where(s => (int)s.Attribute("Id") == 9)
                          .First();

            Assert.IsTrue(element.Element("FirstName").Value == student.FirstName);
            Assert.IsTrue(element.Element("Last").Value == student.Last);
            Assert.IsTrue(element.Element("Age").Value == student.Age);
            Assert.IsTrue(element.Element("Gender").Value == student.Gender);
        }
예제 #3
0
 public IEnumerable <Students> GetInfoAboutStud()
 {
     using (var context = new StudentsContext())
     {
         return(context.Students.ToList());
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            var ctx = new StudentsContext("adress connect");

            var studs = ctx.Students.Where(x => x.Name.Length <= 7).ToList();

            foreach (var stud in studs)
            {
                Console.WriteLine($"Name : {stud.Name} {stud.ID}");

                foreach (var book in stud.Books)
                {
                    Console.WriteLine($"Book id {book.Id} name: {book.Name}");
                }
            }

            studs[0].Books.Add(new Book {
                Name = "Book1"
            });
            studs[0].Books.First().Name = "New Name";  ////good

            //  new Book { Name = "Name" }; //EntFrame ничего не знает о книгах в данній момент

            ctx.SaveChanges();


            var allStuds = GetAll();

            foreach (var stud in allStuds)
            {
                stud.Name = "Updated";
            }
            ctx.SaveChanges(); // ничего не происходит без него
        }
예제 #5
0
        //GET: Student
        public ActionResult Details1(int ID)
        {
            StudentsContext studentcontext = new StudentsContext();
            Student         std            = studentcontext.Students.Single(std1 => std1.ID == ID);

            return(View(std));
        }
예제 #6
0
        public IEnumerable <Students> Insert()
        {
            var context  = new StudentsContext();
            var students = new List <Students>()
            {
                new Students()
                {
                    ID        = 5,
                    FirstName = "Julia",
                    LastName  = "Koval",
                    Email     = "*****@*****.**",
                    Phone     = "762859"
                },
                new Students()
                {
                }
            };
            var university = new University()
            {
                Name = "Politeh", Id = 3
            };
            var graduateSupervisor = new GraduateSupervisor()
            {
                LName = "kOVALCHYK", FName = "Boris", Id = 5
            };

            context.Students.AddRange(students);
            context.GraduateSupervisor.Add(graduateSupervisor);
            context.University.Add(university);

            context.SaveChanges();

            return(context.Students.ToList());
        }
예제 #7
0
        public static void GetAllDepartments()
        {
            using StudentsContext context = new StudentsContext();
            List <Department> result = context.Departments.ToList();

            result.ForEach(d => Console.WriteLine(d));
        }
예제 #8
0
        public static void GetAllDepartmentsWhere()
        {
            using StudentsContext context = new StudentsContext();
            List <Department> result = context.Departments.Where(d => d.Name.Contains("SI")).ToList();

            result.ForEach(d => Console.WriteLine(d));
        }
예제 #9
0
        public ActionResult Index()
        {
            StudentsContext studentcontext = new StudentsContext();
            List <Student>  students       = studentcontext.Students.ToList();

            return(View(students));
        }
예제 #10
0
        public ActionResult Details2(int ID)
        {
            StudentsContext studentcontext = new StudentsContext();
            List <Student>  std            = studentcontext.Students.Where(std1 => std1.DepartmentId == ID).ToList();

            return(View(std));
        }
예제 #11
0
        //public ActionResult StdList(int Id)
        //{

        //    StudentsContext studentcontext = new StudentsContext();
        //    List<Student> Students = studentcontext.Students.Where(std1 => std1.DepartmentId == Id).ToList();
        //   // List<Student> Students = studentcontext.Students.ToList();

        //    return View(Students);

        //}
        public ActionResult Dept()
        {
            StudentsContext   studentcontext = new StudentsContext();
            List <Departmnet> dept           = studentcontext.Departmnets.ToList();

            return(View(dept));
        }
        private static void AddGrades(StudentsContext db)
        {
            var students = db.Students.ToList();
            var courses  = db.Courses.ToList();

            var random = new Random();

            foreach (var student in students)
            {
                foreach (var course in courses)
                {
                    db.Grades.Add(new Grade()
                    {
                        Id = Guid.NewGuid(), Mark = random.Next(3, 11), StudentId = student.Id, CourseId = course.Id
                    });

                    db.Grades.Add(new Grade()
                    {
                        Id = Guid.NewGuid(), Mark = random.Next(3, 11), StudentId = student.Id, CourseId = course.Id
                    });

                    db.Grades.Add(new Grade()
                    {
                        Id = Guid.NewGuid(), Mark = random.Next(3, 11), StudentId = student.Id, CourseId = course.Id
                    });
                }
            }

            db.SaveChanges();
        }
예제 #13
0
 public StudentsUnitOfWork(StudentsContext context)
 {
     this.context = context;
     Department   = new RepositoryDepartment(context);
     Student      = new RepositoryStudent(context);
     Subject      = new RepositorySubject(context);
 }
        public void AddGrade(Grade grade)
        {
            using var db = new StudentsContext();

            db.Grades.Add(grade);
            db.SaveChanges();
        }
예제 #15
0
        public CalendarController(StudentsContext context)
        {
            db = context;
            DateTime a = new DateTime(),
                     b = new DateTime(1, 1, 2);

            oneDay = b.Subtract(a).Ticks;
        }
        public List <Student> GetStudents()
        {
            var students = new List <Student>();

            using var db = new StudentsContext();
            students     = db.Students.ToList();
            return(students);
        }
예제 #17
0
        public void TestInit()
        {
            tran = new TransactionScope();
            DbContext         context         = new StudentsContext();
            DbAllRepositories allRepositories = new DbAllRepositories(context);

            this.httpServer = new InMemoryHttpServer("http://localhost/", allRepositories);
            ClearDb();
        }
예제 #18
0
        public App()
        {
            var optionsBuilder = new DbContextOptionsBuilder <StudentsContext>();

            var options = optionsBuilder
                          .UseSqlServer(@"Server=localhost\MSSQLSERVER01;Database=University;Trusted_Connection=True;")
                          .Options;

            _db = new StudentsContext(options);
        }
예제 #19
0
        public void GetStudentListCommand_PopulatesStudentsPropertyWithExpectedCollectionFromXML()
        {
            var context = new StudentsContext();

            var viewModel = new MainViewModel(context);

            viewModel.GetStudentListCommand.Execute(null);

            Assert.IsTrue(viewModel.Students.Count == 10);
        }
예제 #20
0
 public IEnumerable <Students> DeleteStudentsById(int id)
 {
     using (var context = new StudentsContext())
     {
         var students = context.Students.Where(o => o.ID == id).FirstOrDefault();
         context.Students.Remove(students);
         context.SaveChanges();
         return(context.Students.ToList());
     }
 }
예제 #21
0
        public Student GetStudentDetails(Guid id)
        {
            using var db = new StudentsContext();
            var student = db.Students
                          .Include(s => s.Grades)
                          .ThenInclude(g => g.Course)
                          .FirstOrDefault(s => s.Id == id);

            return(student);
        }
예제 #22
0
        public static void UpdateSubjectWithDepartmentNoTracking()
        {
            List <Subject> subjectsWithDepartment = context.Subjects.Include(s => s.Department).ToList();

            using StudentsContext newcontext = new StudentsContext();
            Subject s = subjectsWithDepartment[0];

            s.Department.Name = "Department Update No Tracking";
            newcontext.Update(s);
            newcontext.SaveChanges();
        }
        public ActionResult RecommendCourses(int id)
        {
            StudentsContext       dbCourses = new StudentsContext();
            CrousesDBContext      db1       = new CrousesDBContext();
            TakenCoursesDBContext db2       = new TakenCoursesDBContext();
            Student student = dbCourses.Students.Find(id);

            student.SetStudentCourses(db2, db1);

            return(View(student.SetCoursePriority(db1)));
        }
예제 #24
0
        public static void AddSubjectItemToSubjectNoTracking()
        {
            Subject s = context.Subjects.First();

            s.Items.Add(new SubjectItem {
                Name = "Vezbe 10"
            });
            using StudentsContext newcontext = new StudentsContext();
            newcontext.Update(s);                                                                  //posto slab objekat ima slozen kljuc, on nije generisan i onda je za njega state modified
            newcontext.Entry(s.Items.Single(i => i.Name == "Vezbe 10")).State = EntityState.Added; //moramo da promenimo state na update
            newcontext.SaveChanges();
        }
예제 #25
0
        public StudentsController(StudentsContext context)
        {
            db = context;

            if (!db.GetStudents.Any())
            {
                db.GetStudents.Add(new Student {
                    Name = "A", Surname = "B", IndexNumber = "s1236"
                });
                db.SaveChanges();
            }
        }
예제 #26
0
        private static void UploadStudents(SearchServiceClient serviceClient)
        {
            if (serviceClient.Indexes.Exists("studentsidx"))
            {
                _studentsIdxClient = serviceClient.Indexes.GetClient("studentsidx");

                StudentsContext db       = new StudentsContext();
                var             students = db.Students.ToList().Select(el => new StudentEx(el));

                Upload(_studentsIdxClient, students);
            }
        }
예제 #27
0
        public MeetingRoomsController(StudentsContext context)
        {
            db = context;

            if (db.MeetingRooms.Count() == 0)
            {
                db.MeetingRooms.Add(new MeetingRoom {
                });
                db.MeetingRooms.Add(new MeetingRoom {
                });
                db.SaveChanges();
            }
        }
예제 #28
0
        public static void UpdateOnlyDepartmentNoTracking()
        {
            List <Subject> subjectsWithDepartment = context.Subjects.Include(s => s.Department).ToList();

            using StudentsContext newcontext = new StudentsContext();
            Subject s = subjectsWithDepartment[0];

            s.Department.Name = "Department Update No Tracking";

            newcontext.Attach(s);
            newcontext.Entry(s.Department).State = EntityState.Modified;
            newcontext.SaveChanges();
        }
예제 #29
0
        public void GetStudentsList_ReturnsListOfStudentEntities()
        {
            //Arrange
            StudentsContext studentsContext = new StudentsContext();

            //Act
            var list = studentsContext.GetStudents();

            int countExpected = list.Count();

            //Assert
            Assert.IsTrue(countExpected == 8);
        }
        public void DeleteStudent(Guid id)
        {
            using var db = new StudentsContext();

            var grades = db.Grades.Where(g => g.StudentId == id).ToList();

            db.Grades.RemoveRange(grades);

            var student = db.Students.First(s => s.Id == id);

            db.Students.Remove(student);
            db.SaveChanges();
        }
예제 #31
0
        public static void Main()
        {
            Console.WriteLine("THE NAME OF THE DATABASE IS StudentsDb");

            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentsContext, Configuration>());

            var db = new StudentsContext();

            CreateSampleHomeworks(db);

            var studentNames = db.Students.Select(s => new { s.Name, Homeworks = s.Homeworks.Select(x => x.Content).ToList() }).ToList();

            foreach (var s in studentNames)
            {
                Console.WriteLine(s.Name);
                Console.WriteLine(string.Join(", ", s.Homeworks));
            }
        }
예제 #32
0
        public static void CreateSampleHomeworks(StudentsContext db)
        {
            var homework1 = new Homework
            {
                Content = "Study this",
                Student = db.Students.FirstOrDefault(x => x.Name == "Harry Potter"),
                Course = db.Courses.FirstOrDefault(x => x.Name == "Alchemy")

            };

            var homework2 = new Homework
            {
                Content = "Very easy",
                Student = db.Students.FirstOrDefault(x => x.Name == "Hermione"),
                Course = db.Courses.FirstOrDefault(x => x.Name == "Dark arts")
            };

            db.Homeworks.Add(homework1);
            db.Homeworks.Add(homework2);
            db.SaveChanges();
        }