示例#1
0
 public Employee GetEmployee(int id)
 {
     using (var entities = new EmployeesDBEntities())
     {
         return(entities.Employees.FirstOrDefault(x => x.ID == id));
     }
 }
 public static bool Login(string username, string password)
 {
     using (var entities = new EmployeesDBEntities())
     {
         return(entities.Users.Any(x => x.Username == username && x.Password == password));
     }
 }
示例#3
0
 public Employee Get(int id)
 {
     using (EmployeesDBEntities entities = new EmployeesDBEntities())
     {
         return(entities.Employees.FirstOrDefault(e => e.ID == id));
     }
 }
示例#4
0
 public IEnumerable <Employee> Get()
 {
     using (EmployeesDBEntities entities = new EmployeesDBEntities())
     {
         return(entities.Employees.Take(20).ToList());
     }
 }
示例#5
0
        public IEnumerable <Employee> LoadEmployees()
        {
            string username = Thread.CurrentPrincipal.Identity.Name;

            using (var entities = new EmployeesDBEntities())
            {
                return(entities.Employees.ToList());
            }
        }
示例#6
0
        public static void DeleteEmployee()
        {
            EmployeesDBEntities context = new EmployeesDBEntities();
            var employees = context.Employees;
            var employee  = new Employee {
                EmpID = 4
            };

            employees.Attach(employee);
            employees.Remove(employee);
            context.SaveChanges();
        }
示例#7
0
        public static void LinqToEntity()
        {
            EmployeesDBEntities context = new EmployeesDBEntities();
            var employee = context.Employees;
            var empList  = from emp in employee
                           orderby emp.Salary
                           select emp;

            foreach (var emp in empList)
            {
                Console.WriteLine("EmpID: {0}, Name: {1}, Salary: {2}, SSN: {3}", emp.EmpID, emp.Name, emp.Salary, emp.SSN);
            }
        }
示例#8
0
        public static void ModifyEmployee()
        {
            EmployeesDBEntities context = new EmployeesDBEntities();
            var employee = context.Employees;
            var empList  = from emp in employee
                           orderby emp.Salary
                           select emp;

            foreach (var emp in empList)
            {
                if (emp.EmpID == 1)
                {
                    emp.Name = "mathew mcdonald";
                }
            }
            context.SaveChanges();
        }
示例#9
0
        static void Main(string[] args)
        {
            EmployeesDBEntities context = new EmployeesDBEntities();


            //var employee = new Employee()
            //{
            //    EmpID = 1,
            //    Name = "Andrew",
            //    Salary = 35000,
            //    SSN = 234567,
            //    DeptID = 3
            //};

            //context.Employees.Add(employee);
            //context.SaveChanges();

            //LinqToEntity();
            //ModifyEmployee();
            DeleteEmployee();

            //    var employee2 = new Employee()
            //    {
            //        EmpID = 2,
            //        Name = "Jaffrey",
            //        Salary = 35000,
            //        SSN = 785877,
            //        DeptID = 3
            //    };


            //    context.Employees.Add(employee2);

            //    var employee3 = new Employee()
            //    {
            //        EmpID = 3,
            //        Name = "Ritchie",
            //        Salary = 35000,
            //        SSN = 684907,
            //        DeptID = 3
            //    };


            //    context.Employees.Add(employee3);
            //    context.SaveChanges();
        }
示例#10
0
        public HttpResponseMessage Post([FromBody] Employee employee)
        {
            try
            {
                using (var entities = new EmployeesDBEntities())
                {
                    entities.Employees.Add(employee);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, employee);
                    message.Headers.Location = new Uri(Request.RequestUri +
                                                       employee.ID.ToString());

                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }