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)); } }
public Employee Get(int id) { using (EmployeesDBEntities entities = new EmployeesDBEntities()) { return(entities.Employees.FirstOrDefault(e => e.ID == id)); } }
public IEnumerable <Employee> Get() { using (EmployeesDBEntities entities = new EmployeesDBEntities()) { return(entities.Employees.Take(20).ToList()); } }
public IEnumerable <Employee> LoadEmployees() { string username = Thread.CurrentPrincipal.Identity.Name; using (var entities = new EmployeesDBEntities()) { return(entities.Employees.ToList()); } }
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(); }
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); } }
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(); }
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(); }
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)); } }