示例#1
0
 /// <summary>
 /// Delete employee with given ID
 /// </summary>
 /// <param name="employeeID"></param>
 public static void DeleteEmployee(int employeeID)
 {
     try
     {
         using (EmployeeEntities context = new EmployeeEntities())
         {
             tblEmployee employeeToDelete = (from u in context.tblEmployees where u.employeeId == employeeID select u).First();
             context.tblEmployees.Remove(employeeToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
示例#2
0
 /// <summary>
 /// Get all managers when editing some employee. Do not allow employee to be himself an manager.
 /// </summary>
 public static List <tblEmployee> GetAllManagers(int empId)
 {
     try
     {
         using (EmployeeEntities context = new EmployeeEntities())
         {
             tblEmployee        employeeToDelete = (from u in context.tblEmployees where u.employeeId == empId select u).First();
             List <tblEmployee> list             = new List <tblEmployee>();
             list = (from x in context.tblEmployees select x).ToList();
             list.Remove(employeeToDelete);
             return(list);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
示例#3
0
        /// <summary>
        /// Edit or Add new employee
        /// </summary>
        /// <param name="employee">added or edited employee</param>
        /// <returns></returns>
        public static vwEmployee AddNewEmployee(vwEmployee employee)
        {
            try
            {
                using (EmployeeEntities context = new EmployeeEntities())
                {
                    //update
                    if (employee.employeeId != 0)
                    {
                        tblEmployee employeeToEdit = (from c in context.tblEmployees where c.employeeId == employee.employeeId select c).First();
                        employeeToEdit.fullname           = employee.fullname;
                        employeeToEdit.dateOfBirth        = employee.dateOfBirth;
                        employeeToEdit.genderId           = employee.getTblGender.genderId;
                        employeeToEdit.IdentityCardNumber = employee.IdentityCardNumber;
                        employeeToEdit.jmbg       = employee.jmbg;
                        employeeToEdit.phone      = employee.phone;
                        employeeToEdit.locationId = employee.getTblLocation.locationId;
                        if (employee.getTblManager != null)
                        {
                            employeeToEdit.managerId = employee.getTblManager.employeeId;
                        }
                        else
                        {
                            employeeToEdit.managerId = null;
                        }
                        //check existance of sector name. Add new one if sectorName do not exist
                        tblSector s = AddNewSector(employee.sectorName);
                        employeeToEdit.sectorId = s.sectorId;
                        context.SaveChanges();
                        return(employee);
                    }
                    //add new
                    else
                    {
                        tblEmployee newEmployee = new tblEmployee();
                        newEmployee.fullname    = employee.fullname;
                        newEmployee.dateOfBirth = employee.dateOfBirth;
                        newEmployee.genderId    = employee.getTblGender.genderId;

                        newEmployee.IdentityCardNumber = employee.IdentityCardNumber;
                        newEmployee.jmbg       = employee.jmbg;
                        newEmployee.phone      = employee.phone;
                        newEmployee.locationId = employee.getTblLocation.locationId;
                        if (employee.getTblManager != null)
                        {
                            newEmployee.managerId = employee.getTblManager.employeeId;
                        }
                        else
                        {
                            newEmployee.managerId = null;
                        }
                        //check existance of sector name. Add new one if sectorName do not exist
                        tblSector s = AddNewSector(employee.sectorName);
                        newEmployee.sectorId = s.sectorId;
                        context.tblEmployees.Add(newEmployee);
                        context.SaveChanges();
                        employee.employeeId = newEmployee.employeeId;
                        return(employee);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }