public IQueryable<EmployeeViewModel> GetEmployees()
 {
     List<EmployeeViewModel> employees = new List<EmployeeViewModel>();
         
        foreach(Employee emp in db.Employees)
        {
            var branch = db.BranchOffices.Find(emp.BranchId);
            var status = GetStatus(emp.EmployementStatusId);
            var type = GetType(emp.EmployementTypeId);
            var wrksp =  (from ws in db.Workspaces join empws in db.EmployeeWorkspaces on ws.WorkspaceId equals empws.WorkspaceId
                          where empws.EmployeeId == emp.EmployeeId select ws).ToList();
            //var titles = (from tl in db.Title
            //              join emptl in db.EmployeeTitles on tl.TitleId equals emptl.TitleId
            //              where emptl.EmployeeId == emp.EmployeeId
            //              select ws).ToList();
            var empview = new EmployeeViewModel
            {
                EmployeeId = emp.EmployeeId,
                FirstName = emp.FirstName,
                LastName = emp.LastName,
                OtherName = emp.OtherName,
                Email = emp.Email,
                PhoneNumber = emp.PhoneNumber,
                Passport = emp.Passport,
                Birthdate = emp.Birthdate,
                Gender = emp.Gender,
                ResidentialAddress = emp.ResidentialAddress,
                Nationality = emp.Nationality,
                Branch = new BranchOffice { BranchId = branch.BranchId, BranchName = branch.BranchName },
                CompanyEmail = emp.CompanyEmail,
                CompanyPhoneNumber = emp.CompanyPhoneNumber,
                EmployementStatus = status.Status,
                EmployementType = type.Type,
                Workspaces = wrksp
            };
            employees.Add(empview);
        }
    
     return employees.AsQueryable();
 }
        public async Task<IHttpActionResult> GetEmployee(int id)
        {
           var employee =  await db.Employees.FindAsync(id);
            //if employee not found return a 404 error
            if (employee == null)
            {
                return NotFound();
            }

            //else get the other details associated with the employee
            var branch = await db.BranchOffices.FindAsync(employee.BranchId);
            var status = GetStatus(employee.EmployementStatusId);
            var type = GetType(employee.EmployementTypeId);


            List<string> str = new List<string>();
            str.Add("MCTS");
            str.Add("Faculty");
            var emp = new EmployeeViewModel
            {
                EmployeeId = id,
                FirstName = employee.FirstName,
                LastName = employee.LastName,
                OtherName = employee.OtherName,
                Email = employee.Email,
                PhoneNumber = employee.PhoneNumber,
                Passport = employee.Passport,
                Birthdate = employee.Birthdate,
                Gender = employee.Gender,
                ResidentialAddress = employee.ResidentialAddress,
                Nationality = employee.Nationality,
                Branch = new BranchOffice { BranchId = branch.BranchId, BranchName = branch.BranchName },
                CompanyEmail = employee.CompanyEmail,
                CompanyPhoneNumber = employee.CompanyPhoneNumber,
                EmployementStatus = status.Status,
                EmployementType = type.Type,
               // Roles = str
            };
           

            return Ok(emp);
        }
        public async Task<IHttpActionResult> PostEmployee(EmployeeViewModel emp)
        {
            
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var branch = GetBranch(emp.Branch);//getting branch data
            var empstatus = GetStatus(emp.EmployementStatus);//getting employee status
            var emptype = GetType(emp.EmployementType);//getting employement status of employee

            //creating a new employee
            var employee = new Employee();
            employee.FirstName = emp.FirstName;
            employee.LastName = emp.LastName;
            employee.OtherName = emp.OtherName;
            employee.Email = emp.Email;
            employee.PhoneNumber = emp.PhoneNumber;
            employee.Passport = emp.Passport;
            employee.Birthdate = emp.Birthdate;
            employee.Gender = emp.Gender;
            employee.ResidentialAddress = emp.ResidentialAddress;
            employee.Nationality = emp.Nationality;
            employee.BranchId = branch.BranchId;
            employee.CompanyEmail = emp.CompanyEmail;
            employee.CompanyPhoneNumber = emp.CompanyPhoneNumber;
            employee.EmployementStatusId = empstatus.EmployementStatusdId;
            employee.EmployementTypeId = emptype.EmploymentTypeId;

            //adding the employee to roles

            //adding titles to emloyee

            //adding a user profile
           
            db.Employees.Add(employee);
            var profile = new EmployeeProfile
            {
                EmployeeId = employee.EmployeeId,
                Name = employee.FirstName.Substring(0,3)+employee.LastName.Substring(employee.LastName.Length-3)
            };
            db.EmployeeProfile.Add(profile);
            await db.SaveChangesAsync();
            emp.EmployeeId = employee.EmployeeId;

            //returning back back employee along with his/her branch details
            //avoiding circular reference exception by returning from the model
            BranchOffice b = new BranchOffice
            {
                BranchId = branch.BranchId,
                BranchName = branch.BranchName
            };
            emp.Branch = b;
            return CreatedAtRoute("DefaultApi", new { id = employee.EmployeeId }, emp);
        }