void IService1.DeleteEmployee(int employeeID) // DeleteEmployee { try { using (VinylRecordsShopEntities context = new VinylRecordsShopEntities()) { tblEmployee employeeToDelete = (from r in context.tblEmployees where r.EmployeeID == employeeID select r).First(); context.tblEmployees.Remove(employeeToDelete); context.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }
// ADD , EDIT I DELETE ZA EMPLOYEE vwEmployee IService1.AddEmployee(vwEmployee employee) // AddEmployee { try { using (VinylRecordsShopEntities context = new VinylRecordsShopEntities()) { if (employee.EmployeeID == 0) { // ZA ADD tblEmployee newEmployee = new tblEmployee(); newEmployee.BossID = employee.BossID; newEmployee.EmployeeName = employee.EmployeeName; newEmployee.EmployeeLastName = employee.EmployeeLastName; newEmployee.BirthDate = employee.BirthDate; newEmployee.Address = employee.Address; newEmployee.City = employee.City; newEmployee.Mobile = employee.Mobile; newEmployee.JobDescription = employee.JobDescription; context.tblEmployees.Add(newEmployee); context.SaveChanges(); employee.EmployeeID = newEmployee.EmployeeID; return(employee); } else { // ZA EDIT tblEmployee employeeToEdit = (from r in context.tblEmployees where r.EmployeeID == employee.EmployeeID select r).First(); employeeToEdit.BossID = employee.BossID; employeeToEdit.EmployeeName = employee.EmployeeName; employeeToEdit.EmployeeLastName = employee.EmployeeLastName; employeeToEdit.BirthDate = employee.BirthDate; employeeToEdit.Address = employee.Address; employeeToEdit.City = employee.City; employeeToEdit.Mobile = employee.Mobile; employeeToEdit.JobDescription = employee.JobDescription; //employeeToEdit.EmployeeID = employee.EmployeeID; context.Entry(employeeToEdit).State = EntityState.Modified; context.SaveChanges(); return(employee); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }