Beispiel #1
0
        /// <summary>
        /// Get list of all locations from db
        /// </summary>
        /// <returns></returns>
        public static List <tblLocation> GetAllLocations()
        {
            try
            {
                using (EmployeeEntities context = new EmployeeEntities())
                {
                    List <tblLocation> list = new List <tblLocation>();
                    list = (from x in context.tblLocations select x).ToList();

                    //return sorted list of location by fullLocation
                    return(list.OrderBy(o => o.fullLocation).ToList());
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #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);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Check if given string exists as jmbg in tblEmployee
        /// </summary>
        /// <param name="jmbg">string</param>
        /// <returns>existence of jmbg in db</returns>
        public static bool IsEmployeeJmbg(string jmbg)
        {
            try
            {
                using (EmployeeEntities context = new EmployeeEntities())
                {
                    string result = (from x in context.tblEmployees where x.jmbg == jmbg select x.jmbg).FirstOrDefault();

                    if (result != null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString());
                return(false);
            }
        }
Beispiel #4
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);
            }
        }