public void DeleteManager(int managerId)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblManager managerToDelete = (from u in context.tblManagers
                                                  where u.ManagerID == managerId
                                                  select u).First();

                    tblUser userToDelete = (from u in context.tblUsers
                                            where u.UserID == managerToDelete.UserID
                                            select u).First();

                    context.tblManagers.Remove(managerToDelete);
                    context.tblUsers.Remove(userToDelete);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
Beispiel #2
0
        public tblEmployee AddEmployee(tblEmployee employee)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblEmployee newEmployee = new tblEmployee();
                    newEmployee.EmployeeID     = employee.EmployeeID;
                    newEmployee.YearsOfService = employee.YearsOfService;
                    newEmployee.UserID         = employee.UserID;
                    newEmployee.SectorID       = employee.SectorID;
                    newEmployee.PositionID     = employee.PositionID;


                    newEmployee.ProfessionalQualifications = employee.ProfessionalQualifications;
                    newEmployee.ManagerID = employee.ManagerID;


                    context.tblEmployees.Add(newEmployee);
                    context.SaveChanges();

                    return(newEmployee);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #3
0
        public tblRequestForChange AddRequest(tblRequestForChange request)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    //newRequest.OldEmployeeID = employeeOld.EmployeeID;
                    //newRequest.NewEmployeeID = employeeNew.EmployeeID;
                    //newRequest.CreationDate = DateTime.Today;

                    context.tblRequestForChanges.Add(request);
                    context.SaveChanges();

                    return(request);

                    //tblRequestForChange req = (from x in context.tblRequestForChanges
                    //                        where x.ID == 1
                    //                        select x).First();

                    //MessageBox.Show(req.ID.ToString());
                    //return null;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #4
0
        public tblUser AddUser(tblUser user)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblUser newUser = new tblUser();
                    newUser.FirstName     = user.FirstName;
                    newUser.LastName      = user.LastName;
                    newUser.JMBG          = user.JMBG;
                    newUser.Gender        = user.Gender;
                    newUser.Residence     = user.Residence;
                    newUser.MaritalStatus = user.MaritalStatus;
                    newUser.Username      = user.Username;
                    newUser.Password      = user.Password;

                    context.tblUsers.Add(newUser);
                    context.SaveChanges();

                    return(newUser);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public vwManager SetResponsibility(vwManager manager)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblManager managerToEdit = (from u in context.tblManagers
                                                where u.ManagerID == manager.ManagerID
                                                select u).First();


                    managerToEdit.ResponsibilityLevel = manager.ResponsibilityLevel;


                    context.SaveChanges();


                    return(manager);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public tblManager AddManager(tblManager manager)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblManager newManager = new tblManager();
                    newManager.UserID                     = manager.UserID;
                    newManager.Email                      = manager.Email;
                    newManager.ReservePassword            = manager.ReservePassword;
                    newManager.NumberOfSuccesfullProjects = manager.NumberOfSuccesfullProjects;
                    newManager.OfficeNumber               = manager.OfficeNumber;

                    context.tblManagers.Add(newManager);
                    context.SaveChanges();

                    return(newManager);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #7
0
        public void EditUser(tblUser user)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblUser userToEdit = (from u in context.tblUsers
                                          where u.UserID == user.UserID
                                          select u).First();

                    userToEdit.FirstName     = user.FirstName;
                    userToEdit.LastName      = user.LastName;
                    userToEdit.JMBG          = user.JMBG;
                    userToEdit.Gender        = user.Gender;
                    userToEdit.Residence     = user.Residence;
                    userToEdit.MaritalStatus = user.MaritalStatus;
                    userToEdit.Username      = user.Username;
                    userToEdit.Password      = user.Password;


                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
Beispiel #8
0
 public List <tblPosition> GetPositions()
 {
     try
     {
         using (MyCompanyDBEntities context = new MyCompanyDBEntities())
         {
             List <tblPosition> list = new List <tblPosition>();
             list = (from x in context.tblPositions select x).ToList();
             return(list);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Beispiel #9
0
        public List <tblSector> GetSectors()
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    List <tblSector> list = new List <tblSector>();
                    list = (from x in context.tblSectors select x).ToList();

                    list.RemoveAll(x => x.SectorName == "default");
                    return(list);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #10
0
        public vwEmployee2 GetvwEmployeeByEmployeeId(int employeeId)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    vwEmployee2 employee = (from x in context.vwEmployee2
                                            where x.EmployeeID == employeeId
                                            select x).First();

                    return(employee);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public tblManager GetManagerByUserId(int userId)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblManager manager = (from x in context.tblManagers
                                          where x.UserID == userId
                                          select x).First();

                    return(manager);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
 public List <vwEmployee2> GetEmployeesOfManager(int managerID)
 {
     try
     {
         using (MyCompanyDBEntities context = new MyCompanyDBEntities())
         {
             List <vwEmployee2> list = new List <vwEmployee2>();
             list = (from x in context.vwEmployee2
                     where x.ManagerID == managerID
                     select x).ToList();
             return(list);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Beispiel #13
0
        public tblUser GetUserByUserNameAndPassword(string username, string password)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblUser user = (from x in context.tblUsers
                                    where x.Username.Equals(username) &&
                                    x.Password.Equals(password)
                                    select x).First();

                    return(user);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #14
0
        public tblSector GetSectorByName(string sectorName)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblSector user = (from x in context.tblSectors
                                      where x.SectorName.Equals(sectorName)

                                      select x).First();

                    return(user);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #15
0
        public tblUser GetUserByJMBG(string JMBG)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblUser user = (from x in context.tblUsers
                                    where x.JMBG.Equals(JMBG)

                                    select x).First();

                    return(user);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #16
0
        public void DeletePosition(int positionId)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblPosition positionToDelete = (from u in context.tblPositions
                                                    where u.PositionID == positionId
                                                    select u).First();


                    context.tblPositions.Remove(positionToDelete);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
Beispiel #17
0
        public void DeleteEmployee(int employeeId)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    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());
            }
        }
Beispiel #18
0
        public void DeleteSector(int sectorId)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblSector sectorToDelete = (from u in context.tblSectors
                                                where u.SectorID == sectorId
                                                select u).First();


                    context.tblSectors.Remove(sectorToDelete);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
Beispiel #19
0
        public tblPosition AddPosition(tblPosition position)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblPosition newPositon = new tblPosition();
                    newPositon.PositionName        = position.PositionName;
                    newPositon.PositionDescription = position.PositionDescription;

                    context.tblPositions.Add(newPositon);
                    context.SaveChanges();

                    return(newPositon);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #20
0
        public tblSector AddSector(tblSector sector)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblSector newSector = new tblSector();
                    newSector.SectorName        = sector.SectorName;
                    newSector.SectorDescription = sector.SectorDescription;

                    context.tblSectors.Add(newSector);
                    context.SaveChanges();

                    return(newSector);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public tblAdmin AddAdmin(tblAdmin admin)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblAdmin newAdmin = new tblAdmin();
                    newAdmin.UserID            = admin.UserID;
                    newAdmin.ExpiryDate        = admin.ExpiryDate;
                    newAdmin.AdministratorType = admin.AdministratorType;

                    context.tblAdmins.Add(newAdmin);
                    context.SaveChanges();

                    return(newAdmin);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public tblRequestForChange AddRequest(tblEmployee employeeOld, tblEmployee employeeNew)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblRequestForChange newRequest = new tblRequestForChange();
                    newRequest.OldEmployeeID = employeeOld.EmployeeID;
                    newRequest.NewEmployeeID = employeeNew.EmployeeID;
                    newRequest.CreationDate  = DateTime.Today;

                    context.tblRequestForChanges.Add(newRequest);
                    context.SaveChanges();

                    return(newRequest);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public void EditManager(tblManager manager)
        {
            try
            {
                using (MyCompanyDBEntities context = new MyCompanyDBEntities())
                {
                    tblManager managerToEdit = (from u in context.tblManagers
                                                where u.ManagerID == manager.ManagerID
                                                select u).First();

                    managerToEdit.Email           = manager.Email;
                    managerToEdit.ReservePassword = manager.ReservePassword;
                    managerToEdit.OfficeNumber    = manager.OfficeNumber;


                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }