コード例 #1
0
        public static void InsertEmployee()
        {
            Console.WriteLine("enter firstname,lastname,gender,salary and department of of an employee");
            Employee e = new Employee();

            e.FirstName    = Console.ReadLine();
            e.LastName     = Console.ReadLine();
            e.Gender       = Console.ReadLine();
            e.Salary       = int.Parse(Console.ReadLine());
            e.DepartmentID = int.Parse(Console.ReadLine());

            DBfirstDemoEntities db = new DBfirstDemoEntities();

            db.Employees.Add(e);
            db.SaveChanges();
        }
コード例 #2
0
        public static void DeleteEmployee()
        {
            DBfirstDemoEntities db = new DBfirstDemoEntities();

            try
            {
                Console.WriteLine("enter the id to update");
                int      identity = int.Parse(Console.ReadLine());
                Employee emp      = db.Employees.First(x => x.ID == identity);
                db.Employees.Remove(emp);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("error:" + e.Message);
            }
        }
コード例 #3
0
        public static void UpdateEmployee()
        {
            DBfirstDemoEntities db = new DBfirstDemoEntities();

            try
            {
                Console.WriteLine("enter the id to update");
                int      identity = int.Parse(Console.ReadLine());
                Employee emp      = db.Employees.First(x => x.ID == identity);
                Console.WriteLine("enter firstname,lastname,gender,salary,department id");
                emp.FirstName    = Console.ReadLine();
                emp.LastName     = Console.ReadLine();
                emp.Gender       = Console.ReadLine();
                emp.Salary       = int.Parse(Console.ReadLine());
                emp.DepartmentID = int.Parse(Console.ReadLine());
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("error:" + e.Message);
            }
        }