コード例 #1
0
 public void AddLocations()
 {
     try
     {
         string[]      lines = File.ReadAllLines(@"../../Location.txt");
         List <string> list  = new List <string>();
         for (int i = 0; i < lines.Length; i++)
         {
             tblLocation location = new tblLocation();
             list            = lines[i].Split(',').ToList();
             location.Adress = list[0];
             location.Place  = list[1];
             location.States = list[2];
             using (DAN_LXEntities1 context = new DAN_LXEntities1())
             {
                 if (context.tblLocations.Where(x => x.Adress == location.Adress && x.Place == location.Place && x.States == location.States).ToList().Count == 0)
                 {
                     context.tblLocations.Add(location);
                     context.SaveChanges();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
コード例 #2
0
 /// <summary>
 /// Method for changing employee data
 /// </summary>
 /// <param name="employee"></param>
 /// <returns></returns>
 public bool EditEmployee(vwEmployee employee)
 {
     try
     {
         using (DAN_LXEntities1 context = new DAN_LXEntities1())
         {
             tblEmployee employeeToEdit = context.tblEmployees.Where(x => x.EmployeeID == employee.EmployeeID).FirstOrDefault();
             employeeToEdit.NameandSurname     = employee.NameandSurname;
             employeeToEdit.DateOfBirth        = employee.DateOfBirth;
             employeeToEdit.JMBG               = employee.JMBG;
             employeeToEdit.RegistrationNumber = employee.RegistrationNumber;
             employeeToEdit.Gender             = employee.Gender;
             employeeToEdit.PhoneNumber        = employee.PhoneNumber;
             employeeToEdit.SectorID           = employee.SectorID;
             employeeToEdit.LocationID         = employee.LocationID;
             employeeToEdit.Manager            = employee.Manager;
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
コード例 #3
0
 public bool AddEmployee(vwEmployee employeeToAdd)
 {
     try
     {
         using (DAN_LXEntities1 context = new DAN_LXEntities1())
         {
             tblEmployee employee = new tblEmployee
             {
                 NameandSurname     = employeeToAdd.NameandSurname,
                 DateOfBirth        = employeeToAdd.DateOfBirth,
                 RegistrationNumber = employeeToAdd.RegistrationNumber,
                 JMBG        = employeeToAdd.JMBG,
                 Gender      = employeeToAdd.Gender,
                 PhoneNumber = employeeToAdd.PhoneNumber,
                 SectorID    = employeeToAdd.SectorID,
                 LocationID  = employeeToAdd.LocationID,
                 Manager     = employeeToAdd.Manager
             };
             context.tblEmployees.Add(employee);
             context.SaveChanges();
             employeeToAdd.EmployeeID = employee.EmployeeID;
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
コード例 #4
0
 /// <summary>
 /// This method creates a list of data from view of employees.
 /// </summary>
 /// <returns>List of employees.</returns>
 public List <vwEmployee> GetAllEmployees()
 {
     try
     {
         using (DAN_LXEntities1 context = new DAN_LXEntities1())
         {
             List <vwEmployee> employees = new List <vwEmployee>();
             employees = (from x in context.vwEmployees select x).ToList();
             return(employees);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #5
0
 public List <vwSector> GetAllSectors()
 {
     try
     {
         using (DAN_LXEntities1 context = new DAN_LXEntities1())
         {
             List <vwSector> sectors = new List <vwSector>();
             sectors = (from x in context.vwSectors select x).ToList();
             return(sectors);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #6
0
 /// <summary>
 /// List of all employees who are managers
 /// </summary>
 /// <param name="employee"></param>
 /// <returns></returns>
 public List <vwEmployee> GetAllManagers(vwEmployee employee)
 {
     try
     {
         using (DAN_LXEntities1 context = new DAN_LXEntities1())
         {
             List <vwEmployee> employees = new List <vwEmployee>();
             employees = context.vwEmployees.Where(x => x.JMBG != employee.JMBG).ToList();
             return(employees);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #7
0
        public List <vwLocation> GetAllLocations()
        {
            try
            {
                using (DAN_LXEntities1 context = new DAN_LXEntities1())
                {
                    List <vwLocation> locations = new List <vwLocation>();

                    locations = (from x in context.vwLocations select x).OrderBy(x => x.Adress).ToList();
                    return(locations);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
コード例 #8
0
 public void AddSector(string sectorToAdd)
 {
     try
     {
         using (DAN_LXEntities1 context = new DAN_LXEntities1())
         {
             tblSector sector = new tblSector
             {
                 SectorName = sectorToAdd
             };
             context.tblSectors.Add(sector);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
コード例 #9
0
        /// <summary>
        /// Method for deleting employee data
        /// </summary>
        /// <param name="employeeID"></param>
        /// <returns></returns>
        public bool DeleteEmployee(int employeeID)
        {
            try
            {
                using (DAN_LXEntities1 context = new DAN_LXEntities1())
                {
                    var employeeOfThisManager = context.tblEmployees.Where(x => x.Manager == employeeID).ToList();

                    if (employeeOfThisManager.Count() > 0)
                    {
                        foreach (var employee in employeeOfThisManager)
                        {
                            employee.Manager = null;
                        }
                    }

                    tblEmployee employeeToDelete = context.tblEmployees.Where(x => x.EmployeeID == employeeID).FirstOrDefault();

                    var peopleInSector = context.tblEmployees.Where(x => x.SectorID == employeeToDelete.SectorID).ToList();
                    if (peopleInSector.Count() == 1)
                    {
                        var sector = context.tblSectors.Where(x => x.SectorID == employeeToDelete.SectorID).FirstOrDefault();
                        context.tblSectors.Remove(sector);
                        context.SaveChanges();
                    }

                    context.tblEmployees.Remove(employeeToDelete);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(false);
            }
        }