/// <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 method changes status of absence to approved. /// </summary> /// <param name="request">Request to be approved.</param> /// <returns>True if approved, false if not.</returns> public bool ApproveRequest(vwAbsence request) { try { using (HotelEntities context = new HotelEntities()) { tblAbsence requestToApprove = context.tblAbsences.Where(x => x.AbsenceId == request.AbsenceId).FirstOrDefault(); requestToApprove.Status = "approved"; context.SaveChanges(); 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); } }
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); } }