Esempio n. 1
0
        public static void InsertData()
        {
            Console.WriteLine("Add new Student");
            Console.Write("StudnetID: ");
            int studentID = Int32.Parse(Console.ReadLine());

            Console.Write("Student name: ");
            string studentName = Console.ReadLine();

            Console.Write("Student gender: ");
            string studentGender = Console.ReadLine();

            Console.Write("Address: ");
            string address = Console.ReadLine();

            var student = new Student(studentID, studentName, studentGender, address);

            using (var db = new StudentDemoEntities())
            {
                db.Students.Add(student);
                db.SaveChanges();
            }
            Console.WriteLine("Created!!!");
            Console.ReadLine();
        }
Esempio n. 2
0
        public static void UpdateData()
        {
            Console.Write("Select student id that you want update information: ");
            int studentId = Int32.Parse(Console.ReadLine());

            Console.WriteLine("--------------------------------------");
            Console.WriteLine("Select information student need update");
            Console.WriteLine("1. Update name");
            Console.WriteLine("2. Update gender");
            Console.WriteLine("3. Update address");
            string choice = Console.ReadLine();

            switch (choice)
            {
            case "1":
                Console.Write("New Student Name: ");
                string StudentNameNew = Console.ReadLine();
                using (var db = new StudentDemoEntities())
                {
                    var updateName = (from u in db.Students where u.StudentID == studentId select u).Single();
                    updateName.StudentName = StudentNameNew;
                    db.SaveChanges();
                }
                Console.WriteLine("Update Success!!!");
                break;

            case "2":
                Console.Write("New Student Gender: ");
                string StudentGenderNew = Console.ReadLine();
                using (var db = new StudentDemoEntities())
                {
                    var updateName = (from u in db.Students where u.StudentID == studentId select u).Single();
                    updateName.StudentGender = StudentGenderNew;
                    db.SaveChanges();
                }
                Console.WriteLine("Update Success!!!");
                break;

            case "3":
                Console.Write("New Student Address: ");
                string StudentAddressNew = Console.ReadLine();
                using (var db = new StudentDemoEntities())
                {
                    var updateName = (from u in db.Students where u.StudentID == studentId select u).Single();
                    updateName.Address = StudentAddressNew;
                    db.SaveChanges();
                }
                Console.WriteLine("Update Success!!!");
                break;

            default:
                Console.WriteLine("Input from 1 to 3");
                Console.ReadLine();
                break;
            }
        }
Esempio n. 3
0
        public static void DeleteData()
        {
            Console.Write("Input a StudnetID that you want delete: ");
            int studentID = Int32.Parse(Console.ReadLine());

            using (var db = new StudentDemoEntities())
            {
                var delete = (from d in db.Students where d.StudentID == studentID select d).Single();
                db.Students.Remove(delete);
                db.SaveChanges();
            }
            Console.WriteLine("Deleted!!!");
            Console.ReadLine();
        }
Esempio n. 4
0
 public static void ViewData()
 {
     using (var db = new StudentDemoEntities())
     {
         var select = from s in db.Students select s;
         foreach (var data in select)
         {
             Console.WriteLine("ID: {0}", data.StudentID);
             Console.WriteLine("Student name: {0}", data.StudentName);
             Console.WriteLine("Student gender: {0}", data.StudentGender);
             Console.WriteLine("Address: {0}", data.Address);
         }
     }
     Console.ReadLine();
 }