/// <summary> /// This method adds absence to DbSet and then save changes to database. /// </summary> /// <param name="absence">Absence.</param> /// <returns>True if added, false if not.</returns> public bool AddAbsence(vwAbsence absence) { try { using (HotelEntities context = new HotelEntities()) { tblAbsence newAbsence = new tblAbsence { FirstDay = absence.FirstDay, LastDay = absence.LastDay, Status = "on hold", Reason = absence.Reason, UserId = absence.UserId }; context.tblAbsences.Add(newAbsence); context.SaveChanges(); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This methods finds manager based on forwarded username and password. /// </summary> /// <param name="username">Manager username.</param> /// <param name="password">Manager password.</param> /// <returns>Manager.</returns> public vwManager FindManager(string username, string password) { try { using (HotelEntities context = new HotelEntities()) { return(context.vwManagers.Where(x => x.Username == username && x.Password == password).FirstOrDefault()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This method creates a list of data from view of all users. /// </summary> /// <returns>List of users.</returns> public List <tblUser> GetAllUsers() { try { using (HotelEntities context = new HotelEntities()) { return(context.tblUsers.ToList()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <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 checks if manager exists in database. /// </summary> /// <returns>True if exists, false if not.</returns> public bool CheckIfManagerExists() { try { using (HotelEntities context = new HotelEntities()) { return(context.vwManagers.Any()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This method creates a list of employees of forwarded manager. /// </summary> /// <param name="manager">manager.</param> /// <returns>List of employees.</returns> public List <vwEmployee> GetEmployees(vwManager manager) { try { using (HotelEntities context = new HotelEntities()) { return(context.vwEmployees.Where(x => x.HotelFloor == manager.HotelFloor).ToList()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This methods finds employee based on forwarded username and password. /// </summary> /// <param name="username">Employee username.</param> /// <param name="password">Employee password.</param> /// <returns>Employee.</returns> public vwEmployee FindEmployee(string username, string password) { string encryptedPassword = Encryption.EncryptPassword(password); try { using (HotelEntities context = new HotelEntities()) { return(context.vwEmployees.Where(x => x.Username == username && x.Password == encryptedPassword).FirstOrDefault()); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// This method changes status of absence to rejected. /// </summary> /// <param name="request">Request to be rejected.</param> /// <returns>True if rejected, false if not.</returns> public bool RejectRequest(vwAbsence request) { try { using (HotelEntities context = new HotelEntities()) { tblAbsence requestToReject = context.tblAbsences.Where(x => x.AbsenceId == request.AbsenceId).FirstOrDefault(); requestToReject.Status = "rejected"; context.SaveChanges(); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
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 adds managers to DbSet and then save changes to database. /// </summary> /// <param name="managerToAdd">Manager.</param> /// <returns>True if added, false if not.</returns> public bool AddManager(vwManager managerToAdd) { try { using (HotelEntities context = new HotelEntities()) { tblUser user = new tblUser { DateOfBirth = managerToAdd.DateOfBirth, Email = managerToAdd.Email, Name = managerToAdd.Name, Password = managerToAdd.Password, Surname = managerToAdd.Surname, Username = managerToAdd.Username }; context.tblUsers.Add(user); context.SaveChanges(); managerToAdd.UserId = user.UserId; tblManager manager = new tblManager { UserId = managerToAdd.UserId, ExperienceWorkingInHotels = managerToAdd.ExperienceWorkingInHotels, HotelFloor = managerToAdd.HotelFloor, ProfessionalQualifications = managerToAdd.ProfessionalQualifications }; context.tblManagers.Add(manager); context.SaveChanges(); managerToAdd.ManagerId = manager.ManagerId; return(true); } } 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); } }