Example #1
0
        static void Delete(UniversityEntities context)
        {
            Console.WriteLine("===>> Enter name to delete");
            string name = Console.ReadLine();

            context.Student.Remove(context.Student.FirstOrDefault(x => x.Name == name));
            context.SaveChanges();
        }
Example #2
0
        static void Update(UniversityEntities context)
        {
            Console.WriteLine("===>> Enter ID group for update :");
            string  group = Console.ReadLine();
            Student st    = context.Student.FirstOrDefault(x => x.Name == "Alina");

            st.Groups.Name = group;
            context.SaveChanges();
        }
Example #3
0
        private static void Add(UniversityEntities context)
        {
            Student st = new Student {
                Name = "Olia", Surname = "Olia", Groups = context.Groups.First()
            };

            //Student st = new Student { Name = "Olia", Surname = "Olia", Groups = new Groups { Name = "Step" } };
            context.Student.Add(st);
            context.SaveChanges();
        }
Example #4
0
        private static void ChangeSurname(UniversityEntities context)
        {
            var minMark = context.Achievement.Where(x => x.Subject.Name == "C#").Min(x => x.Mark);

            int?studID = context.Achievement.Where(x => x.Mark == minMark && x.Subject.Name == "C#").Select(x => x.IdStudent).SingleOrDefault();

            foreach (var item in context.Student.Where(x => x.Id == studID))
            {
                Console.WriteLine($"{item.Name} {item.Surname}");
            }

            Console.WriteLine("===>> Enter Surname to update :");
            string  surname = Console.ReadLine();
            Student st      = context.Student.Where(x => x.Id == studID).FirstOrDefault();

            st.Surname = surname;
            context.SaveChanges();

            Print(context);
        }