public void UpdateEmployee(Employee emp) { Model.ER1Entities context = new Model.ER1Entities(); //Query the database var query = from employee in context.Employees where employee.Id == emp.Id select employee; //Change the values foreach (Model.Employee e in query) { e.Name = emp.Name; e.StartDate = emp.StartDate; if (e.GetType() == typeof(Model.FullTimeEmployee)) { ((Model.FullTimeEmployee)e).Salary = ((Shared.Entities.FullTimeEmployee)emp).Salary; } else { ((Model.PartTimeEmployee)e).HourlyRate = ((Shared.Entities.PartTimeEmployee)emp).HourlyRate; } } // Submit the changes to the database. try { context.SaveChanges(); }catch (Exception e) { Console.WriteLine(e); } }
public void AddEmployee(Employee emp) { //throw new NotImplementedException(); Model.ER1Entities context = new Model.ER1Entities(); if (emp.GetType() == typeof(FullTimeEmployee)) { Model.FullTimeEmployee result = new Model.FullTimeEmployee() { }; result.Id = GetAllEmployees().Count; result.Name = emp.Name; result.Salary = ((FullTimeEmployee)emp).Salary; result.StartDate = emp.StartDate; context.Employees.Add(result); } else { Model.PartTimeEmployee result = new Model.PartTimeEmployee() { }; result.Id = GetAllEmployees().Count; result.Name = emp.Name; result.HourlyRate = ((PartTimeEmployee)emp).HourlyRate; result.StartDate = emp.StartDate; context.Employees.Add(result); } // Submit the changes to the database. try { context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } }
public void DeleteEmployee(int id) { //throw new NotImplementedException(); Model.ER1Entities context = new Model.ER1Entities(); //Query the database var query = from employee in context.Employees where employee.Id == id select employee; //Delete on submit foreach (Model.Employee e in query) { context.Employees.Remove(e); } // Submit the changes to the database. try { context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } }