//To generate new passcode public string generateNewPasscode(string dep) { //DepartmentRepresentative depRep = context.DepartmentRepresentatives // .First(dr => dr.Employee.DepartmentID == dep); DepartmentRepresentative currentRepresentative = getCurrentDepartmentRepresentative(dep); DepartmentRepresentative depRep = context.DepartmentRepresentatives.Where(x => x.DeptRepID == currentRepresentative.DeptRepID).First(); Random num = new Random(); int passcode = num.Next(1000, 9999); depRep.Passcode = Convert.ToString(passcode); context.SaveChanges(); return(Convert.ToString(passcode)); }
public List <Employee> getEligibleDelegatedAuthority(string deptId) { List <Employee> employees = getEmployeesOfDepartment(deptId); List <Employee> ineligibleEmployees = new List <Employee>(); ineligibleEmployees.Add(context.Departments.First(d => d.DepartmentID == deptId).DepartmentHead); DepartmentRepresentative currentDeptRepresentative = getCurrentDepartmentRepresentative(deptId); if (currentDeptRepresentative != null) { ineligibleEmployees.Add(currentDeptRepresentative.Employee); } return(employees.Where(e => !ineligibleEmployees.Contains(e)).ToList()); }
//update old representative enddate and add new departmentRepresentative public void updateDepartmentRepresentative(int currentDeptRepId, string newRepEmpId) { DepartmentRepresentative currentDeptRepresentative = context.DepartmentRepresentatives .Where(d => d.DeptRepID == currentDeptRepId).FirstOrDefault(); if (currentDeptRepresentative != null) { currentDeptRepresentative.EndDate = DateTime.Today; } DepartmentRepresentative newDepRep = new DepartmentRepresentative(); newDepRep.EmployeeID = newRepEmpId; String deptID = getDepartmentID(newDepRep.EmployeeID); newDepRep.StartDate = DateTime.Today.AddDays(1); newDepRep.Passcode = generateNewPasscode(deptID); context.DepartmentRepresentatives.Add(newDepRep); context.SaveChanges(); }
public bool verifyPassCode(string passcode, string dep) { DepartmentRepresentative depRep = getCurrentDepartmentRepresentative(dep); return(depRep.Passcode == passcode); }
public static DepartmentRepresentativePayload ConvertToDepartmentRepresentativePayload(DepartmentRepresentative d) { if (d != null) { return(new DepartmentRepresentativePayload(d)); } else { return(null); } }
public DepartmentRepresentativePayload(DepartmentRepresentative d) { DeptRepID = d.DeptRepID; EmployeeName = d.Employee.EmployeeName; }