/// <summary> /// Starts a new session for employee, returns bool val for success state /// </summary> /// <param name="EmployeeID"></param> /// <returns></returns> public bool StartSession(int EmployeeID, int SalaryId) { using (var ctx = new EmployeesContext()) { //Query here to be in the same context EmployeeModel Employee = ctx.Employees.Find(EmployeeID); var Job = ctx.JobModels.Find(Employee.JobId); var query = ctx.Salaries.Where(salary => salary.Jobs.Any(job => job.JobName == Job.JobName)).ToList(); var collection = new ObservableCollection <Salary>(query); if (Employee != null) { //Sets clocked in time to now Employee.ClockedInTime = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")); //Find employee's salary object var indicatedSalary = collection.Where(x => x.SalaryId == SalaryId).First(); //Set current salary object to the one found by indicatedSalary Employee.CurrentSalary = indicatedSalary; Employee.IsClockedIn = true; ctx.SaveChanges(); return(true); } else { return(false); } } }
/// <summary> /// Searchs for an employee based on first name. Note that there are overloads for different search parameters /// </summary> /// <param name="name"></param> /// <returns></returns> public EmployeeModel SearchForEmployeeName(string name) { using (var ctx = new EmployeesContext()) { EmployeeModel query; try { query = (from s in ctx.Employees where s.FirstName == name select s).FirstOrDefault(); } catch (Exception error) { ShowError(error); return(null); } if (query != null) { return(query); } else { return(null); } } }
public EmployeeModel SearchForEmployeeID(int id) { using (var ctx = new EmployeesContext()) { EmployeeModel query; try { query = (from s in ctx.Employees where s.EmployeeId == id select s).First(); } catch (Exception error) { ShowError(error); query = null; } if (query != null) { return(query); } else { return(null); } } }
/// <summary> /// Return the indicated salary of an employee. Does not return a list. /// </summary> /// <param name="employeeID"></param> /// <param name="desiredSalary"></param> /// <returns></returns> public Salary GetSalary(int employeeID, string desiredSalary) { using (var ctx = new EmployeesContext()) { var employee = ctx.Employees.Find(employeeID); var Job = employee.Job; //var SalaryObject = ctx.Salaries Salary query; try { var SalaryObject = ctx.Salaries.Where(x => x.SalaryName.Contains(desiredSalary)).FirstOrDefault(); query = Job.Salarys.Where(salary => salary == SalaryObject).First(); //var query = ctx.JobModels.Where(job => job.Salarys.Any(salary => salary.SalaryId == SalaryObject.SalaryId)); } catch (Exception error) { query = null; ShowError(error); } return(query); } }
/// <summary> /// Returns all employee names, queries all employees, NEEDS TO BE PURPOSE FIXED /// </summary> /// <returns></returns> public ObservableCollection <EmployeeModel> GetAllEmployeeNames() { using (var ctx = new EmployeesContext()) { var query = (from s in ctx.Employees select s).ToList(); var ObservableCollectionEmployeeName = new ObservableCollection <EmployeeModel>(query); return(ObservableCollectionEmployeeName); } }
public ObservableCollection <EmployeeModel> GetAllEmployees() { using (var ctx = new EmployeesContext()) { var query = (from s in ctx.Employees .Include(x => x.Job) .Include(x => x.CurrentSalary.EmployeeModel) .Include(x => x.CurrentSalary) select s).ToList(); var ObservableEmployeeCollection = new ObservableCollection <EmployeeModel>(query); return(ObservableEmployeeCollection); } }
/// <summary> /// Ends a current session, by replacing the clock in time, calculating the hours worked, and inputting that into Employee's totalhours /// </summary> /// <remarks> /// NOTE THAT HOURS ARE NOT ROUNDED AND ANY VALUES NOT IN HOUR'S PLACE ARE TRUNCATED /// </remarks> /// <param name="id"></param> /// <returns></returns> public bool EndSession(int id) { using (var ctx = new EmployeesContext()) { EmployeeModel Employee = ctx.Employees .Include(x => x.CurrentSalary) .Where(x => x.EmployeeId == id).First(); var currentTime = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")); if (Employee != null && Employee.ClockedInTime != null) { if (Employee.ClockedInTime <= currentTime) { //Calculate time worked in hours TimeSpan TimeWorked = ((TimeSpan)(currentTime - Employee.ClockedInTime)); //Add hours worked to employee's record Employee.HoursWorked += TimeWorked.Hours; //Reset employee's clocked in time, note that ClockedInTime is null, as datetime will be assigned by StartSession() Employee.ClockedInTime = null; //Calculate pay for session double TotalPay = (TimeWorked.Hours * Employee.CurrentSalary.PayPerHour); //Assign pay for session to Employee Records Employee.TotalPay += TotalPay; //Remove CurrentSalary to be null Employee.CurrentSalary = null; Employee.IsClockedIn = false; ctx.SaveChanges(); return(true); } else { return(false); } } else { return(false); } } }
/// <summary> /// Determines what to do with a logging in employee, and determines their current salary rates. Returns the employee as indicated by rfid_ID /// </summary> /// <param name="rfid_ID"></param> public void ChooseSessionStart(EmployeeModel employee) { //Query required info regarding salaries var EmployeeSalaries = BusinessLayerDataAccces.GetAllEmployeeSalaries(employee.EmployeeId); var lunchSalary = EmployeeSalaries.Where(x => x.SalaryName.Contains("lunch")).First(); var normalSalary = EmployeeSalaries.Where(x => x.SalaryName.Contains("normalPay")).First(); var currentTime = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")); using (var ctx = new EmployeesContext()) { ctx.Configuration.LazyLoadingEnabled = false; var EmployeeJob = ctx.JobModels.Find(employee.JobId); //workaround to null error if (currentTime >= lunchSalary.StartTime && currentTime <= lunchSalary.EndTime) //is it lunch time? set lunch salary if such { if (employee.ClockedInTime != null) // if employee is currently working... { bool sessionEnded = EndSession(employee.EmployeeId); // end session if (sessionEnded) { StartSession(employee.EmployeeId, lunchSalary.SalaryId); } else { throw new Exception("Session couldn't end"); } } } else if ((currentTime >= normalSalary.StartTime && currentTime <= normalSalary.EndTime)) // if employee is in working hours { if (employee.ClockedInTime == null) { StartSession(employee.EmployeeId, normalSalary.SalaryId); } else { EndSession(employee.EmployeeId); } } else { MessageBox.Show("You are not within working hours"); } } }
public ObservableCollection <Salary> GetAllEmployeeSalaries(int employeeID) { using (var ctx = new EmployeesContext()) { var employee = ctx.Employees.Find(employeeID); JobModel Job = ctx.JobModels.Find(employee.JobId); try { var query = ctx.Salaries.Where(salary => salary.Jobs.Any(job => job.JobName == Job.JobName)).ToList(); return(new ObservableCollection <Salary>(query)); } catch (Exception error) { ShowError(error); return(null); } } }
public EmployeeModel SearchByEmployeeRFID(string rfid_id) { using (var ctx = new EmployeesContext()) { //Cleans rfid_id from carriage returns or newlines char[] charsToTrim = { '\r', '\n' }; string cleanID = rfid_id.Trim(charsToTrim); var query = (from s in ctx.Employees where s.RFID_ID == cleanID select s).First(); if (query != null) { return(query); } else { return(null); } } }