/// <summary> /// This method edits employee in DbSet and then saves changes to database. /// </summary> /// <param name="employee">Employee to edit.</param> /// <returns>Edited employee.</returns> public vwEmployee EditEmployee(vwEmployee employee) { try { using (Employee_DataEntities context = new Employee_DataEntities()) { tblEmployee employeeToEdit = context.tblEmployees.Where(x => x.EmployeeID == employee.EmployeeID).FirstOrDefault(); employeeToEdit.Name = employee.Name; employeeToEdit.Surname = employee.Surname; employeeToEdit.DateOfBirth = employee.DateOfBirth; employeeToEdit.NumberOfIdentityCard = employee.NumberOfIdentityCard; employeeToEdit.Gender = employee.Gender; employeeToEdit.PhoneNumber = employee.PhoneNumber; employeeToEdit.Sector = employee.Sector; employeeToEdit.LocationID = employee.LocationID; employeeToEdit.Manager = employee.Manager; context.SaveChanges(); LogAction("Employee with ID " + employeeToEdit.EmployeeID + " updated."); return(employee); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This method adds employee to DbSet and then save changes to database. /// </summary> /// <param name="employeeToAdd">Employee.</param> public void AddEmployee(vwEmployee employeeToAdd) { try { using (Employee_DataEntities context = new Employee_DataEntities()) { tblEmployee employee = new tblEmployee { Name = employeeToAdd.Name, Surname = employeeToAdd.Surname, DateOfBirth = employeeToAdd.DateOfBirth, NumberOfIdentityCard = employeeToAdd.NumberOfIdentityCard, JMBG = employeeToAdd.JMBG, Gender = employeeToAdd.Gender, PhoneNumber = employeeToAdd.PhoneNumber, Sector = employeeToAdd.Sector, LocationID = employeeToAdd.LocationID, Manager = employeeToAdd.Manager }; context.tblEmployees.Add(employee); context.SaveChanges(); employeeToAdd.EmployeeID = employee.EmployeeID; LogAction("Employee " + employeeToAdd.Employee + " created. ID: " + employeeToAdd.EmployeeID + " JMBG: " + employeeToAdd.JMBG); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// This method edits employee in DbSet and then saves changes to database. /// </summary> /// <param name="employee">Employee to edit.</param> /// <returns>Edited employee.</returns> public vwEmployee EditEmployee(vwEmployee employee) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblEmployee employeeToEdit = context.tblEmployees.Where(x => x.EmployeeID == employee.EmployeeID).FirstOrDefault(); employeeToEdit.Name = employee.Name; employeeToEdit.Surname = employee.Surname; employeeToEdit.JMBG = employee.JMBG; employeeToEdit.BankAccountNumber = employee.BankAccountNumber; employeeToEdit.Email = employee.Email; employeeToEdit.Salary = employee.Salary; employeeToEdit.Position = employee.Position; employeeToEdit.Username = employee.Username; employeeToEdit.Password = employee.Password; context.SaveChanges(); return(employee); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This method edits employee in DbSet and then saves changes to database. /// </summary> /// <param name="employee"></param> /// <returns>True if edited, false if not.</returns> public bool EditEmployee(vwEmployee employee) { try { using (Employee_DataEntities context = new Employee_DataEntities()) { tblEmployee employeeToEdit = context.tblEmployees.Where(x => x.EmployeeId == employee.EmployeeId).FirstOrDefault(); employeeToEdit.NameAndSurname = employee.NameAndSurname; employeeToEdit.DateOfBirth = CalculateDateOfBirth.Calculate(employee.JMBG); employeeToEdit.JMBG = employee.JMBG; employeeToEdit.NumberOfIdentityCard = employee.NumberOfIdentityCard; employeeToEdit.Gender = employee.Gender; employeeToEdit.PhoneNumber = employee.PhoneNumber; employeeToEdit.Sector = employee.Sector; employeeToEdit.LocationId = employee.LocationId; employeeToEdit.Manager = employee.Manager; context.SaveChanges(); logger.LogAction("Employee with JMBG " + employeeToEdit.JMBG + " updated."); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This method adds employee to DbSet and then save changes to database. /// </summary> /// <param name="employeeToAdd">Employee.</param> public void AddEmployee(vwEmployee employeeToAdd) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { tblEmployee employee = new tblEmployee { Name = employeeToAdd.Name, Surname = employeeToAdd.Surname, DateOfBirth = employeeToAdd.DateOfBirth, JMBG = employeeToAdd.JMBG, BankAccountNumber = employeeToAdd.BankAccountNumber, Email = employeeToAdd.Email, Salary = employeeToAdd.Salary, Position = employeeToAdd.Position, Username = employeeToAdd.Username, Password = employeeToAdd.Password }; context.tblEmployees.Add(employee); context.SaveChanges(); employeeToAdd.EmployeeID = employee.EmployeeID; } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// This method adds employee to DbSet and then save changes to database. /// </summary> /// <param name="employeeToAdd">Employee to be added.</param> /// <returns>True if added, false if not.</returns> public bool AddEmployee(vwEmployee employeeToAdd) { try { using (Employee_DataEntities context = new Employee_DataEntities()) { tblEmployee employee = new tblEmployee { NameAndSurname = employeeToAdd.NameAndSurname, DateOfBirth = CalculateDateOfBirth.Calculate(employeeToAdd.JMBG), NumberOfIdentityCard = employeeToAdd.NumberOfIdentityCard, JMBG = employeeToAdd.JMBG, Gender = employeeToAdd.Gender, PhoneNumber = employeeToAdd.PhoneNumber, Sector = employeeToAdd.Sector, LocationId = employeeToAdd.LocationId, Manager = employeeToAdd.Manager }; context.tblEmployees.Add(employee); context.SaveChanges(); employeeToAdd.EmployeeId = employee.EmployeeId; logger.LogAction("Employee " + employeeToAdd.NameAndSurname + " created. ID: " + employeeToAdd.EmployeeId + " JMBG: " + employeeToAdd.JMBG); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This method creates a list of data from view of all absences of employee. /// </summary> /// <returns>List of absences.</returns> public List <vwAbsence> GetEmployeeRequests(vwEmployee employee) { try { using (HotelEntities context = new HotelEntities()) { return(context.vwAbsences.Where(x => x.UserId == employee.UserId).ToList()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This method creates a list of possible managers of employee. /// </summary> /// <param name="employee">Employee.</param> /// <returns>List of possible managers.</returns> public List <vwEmployee> GetAllManagers(vwEmployee employee) { try { using (Employee_DataEntities context = new Employee_DataEntities()) { List <vwEmployee> employees = new List <vwEmployee>(); //inserting into list all employees except forwarded employee (finding him based on jmbg) employees = context.vwEmployees.Where(x => x.JMBG != employee.JMBG).ToList(); return(employees); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public bool SetSalary(vwEmployee employee) { try { using (HotelEntities context = new HotelEntities()) { tblEmployee employeeToEdit = context.tblEmployees.Where(x => x.EmployeeId == employee.EmployeeId).FirstOrDefault(); employeeToEdit.Salary = employee.Salary; context.SaveChanges(); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This method adds employees to DbSet and then save changes to database. /// </summary> /// <param name="employeeToAdd">Employee.</param> /// <returns>True if added, false if not.</returns> public bool AddEmployee(vwEmployee employeeToAdd) { try { using (HotelEntities context = new HotelEntities()) { tblUser user = new tblUser { DateOfBirth = employeeToAdd.DateOfBirth, Email = employeeToAdd.Email, Name = employeeToAdd.Name, Password = employeeToAdd.Password, Surname = employeeToAdd.Surname, Username = employeeToAdd.Username }; context.tblUsers.Add(user); context.SaveChanges(); employeeToAdd.UserId = user.UserId; tblEmployee employee = new tblEmployee { UserId = user.UserId, Citizenship = employeeToAdd.Citizenship, Engagement = employeeToAdd.Engagement, Gender = employeeToAdd.Gender, HotelFloor = employeeToAdd.HotelFloor, Salary = null }; context.tblEmployees.Add(employee); context.SaveChanges(); employeeToAdd.EmployeeId = employee.EmployeeId; return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This method checks if employee exists. /// </summary> /// <param name="username">Employee username.</param> /// <returns>True if employee exist, false if not.</returns> public bool IsEmployeeExists(string username) { try { using (Data_RecordsEntities context = new Data_RecordsEntities()) { vwEmployee sector = context.vwEmployees.Where(x => x.Username == username).FirstOrDefault(); if (sector != null) { return(true); } else { return(false); } } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This method checks if employee can be created. /// </summary> /// <param name="employee"></param> /// <returns></returns> public bool CanCreate(vwEmployee employee) { try { using (HotelEntities context = new HotelEntities()) { //checks if exists competent manager for the floor var managers = context.vwManagers.Where(x => x.HotelFloor == employee.HotelFloor).FirstOrDefault(); if (managers != null) { return(true); } else { return(false); } } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }