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(); }
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); }
public IEnumerable <Students> GetInfoAboutStud() { using (var context = new StudentsContext()) { return(context.Students.ToList()); } }
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(); // ничего не происходит без него }
//GET: Student public ActionResult Details1(int ID) { StudentsContext studentcontext = new StudentsContext(); Student std = studentcontext.Students.Single(std1 => std1.ID == ID); return(View(std)); }
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()); }
public static void GetAllDepartments() { using StudentsContext context = new StudentsContext(); List <Department> result = context.Departments.ToList(); result.ForEach(d => Console.WriteLine(d)); }
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)); }
public ActionResult Index() { StudentsContext studentcontext = new StudentsContext(); List <Student> students = studentcontext.Students.ToList(); return(View(students)); }
public ActionResult Details2(int ID) { StudentsContext studentcontext = new StudentsContext(); List <Student> std = studentcontext.Students.Where(std1 => std1.DepartmentId == ID).ToList(); return(View(std)); }
//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(); }
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(); }
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); }
public void TestInit() { tran = new TransactionScope(); DbContext context = new StudentsContext(); DbAllRepositories allRepositories = new DbAllRepositories(context); this.httpServer = new InMemoryHttpServer("http://localhost/", allRepositories); ClearDb(); }
public App() { var optionsBuilder = new DbContextOptionsBuilder <StudentsContext>(); var options = optionsBuilder .UseSqlServer(@"Server=localhost\MSSQLSERVER01;Database=University;Trusted_Connection=True;") .Options; _db = new StudentsContext(options); }
public void GetStudentListCommand_PopulatesStudentsPropertyWithExpectedCollectionFromXML() { var context = new StudentsContext(); var viewModel = new MainViewModel(context); viewModel.GetStudentListCommand.Execute(null); Assert.IsTrue(viewModel.Students.Count == 10); }
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()); } }
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); }
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))); }
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(); }
public StudentsController(StudentsContext context) { db = context; if (!db.GetStudents.Any()) { db.GetStudents.Add(new Student { Name = "A", Surname = "B", IndexNumber = "s1236" }); db.SaveChanges(); } }
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); } }
public MeetingRoomsController(StudentsContext context) { db = context; if (db.MeetingRooms.Count() == 0) { db.MeetingRooms.Add(new MeetingRoom { }); db.MeetingRooms.Add(new MeetingRoom { }); db.SaveChanges(); } }
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(); }
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(); }
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)); } }
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(); }