//All employeees under the requested EmployeeId
        public ManageEmployeeResponse ManagerEmployees(ManageEmployeeRequest request)
        {
            ManageEmployeeResponse response = new ManageEmployeeResponse();
            List <Employee_table>  employee = new List <Employee_table>();
            //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email);
            //if (!empId.HasValue)
            //    throw new Exception("Employee does not exist!");
            List <dto> dto = new List <dto>();

            using (var context = new Company_dbEntities())
            {
                employee = (from a in context.Employee_table
                            where a.ManagerID == request.UserName
                            select a).ToList();

                if (employee.Count() > 0)
                {
                    foreach (var entry in employee)
                    {
                        dto d = new dto();
                        d.EmployeeID   = entry.UserName;
                        d.EmployeeName = entry.EmployeeName;

                        dto.Add(d);
                    }

                    response.ManagerEmployees = JsonConvert.SerializeObject(dto);
                }
                else
                {
                    response.ManagerEmployees = null;
                }
            }
            return(response);
        }
        public ManageEmployeeResponse employees(ManageEmployeeRequest request)
        {
            ManageEmployeeResponse response = new ManageEmployeeResponse();

            //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email);
            //if (!empId.HasValue)
            //    throw new Exception("Employee does not exist!");

            // List<dynamic> list = new List<dynamic>();
            //List<Employee_table> employee = new List<Employee_table>();
            using (var context = new Company_dbEntities())
            {
                dto dt = new dto();

                var employee = (from a in context.Employee_table
                                where a.UserName == request.UserName
                                select a).FirstOrDefault();

                if (employee != null)
                {
                    dt.EmployeeName = employee.EmployeeName;
                    dt.EmployeeID   = employee.UserName;
                    // dt.EmployeeID = employee.EmployeeID;
                    dt.ManagerID = employee.ManagerID;
                    //dt.ManagerID = employee.ManagerID;
                    //dt.Department = employee.Department;
                    dt.Designation = employee.Designation;
                    //dt.DOB = employee.DOB;
                    //dt.Address = employee.Address;
                    //dt.Contact = employee.Contact;
                    dt.Email        = employee.Email;
                    dt.EmployeeInfo = employee.EmployeeInfo;

                    //var comp = (from a in context.Company_table where a.CompanyID == employee.CompanyID select a.Prefix).FirstOrDefault();

                    //dt.EmployeeID = comp + employee.EmployeeID;
                }


                response.EmployeeList = JsonConvert.SerializeObject(dt);
            }
            return(response);
        }
        public ManageEmployeeResponse EmployeeDetail(ManageEmployeeRequest request)
        {
            ManageEmployeeResponse response = new ManageEmployeeResponse();

            //List<Employee_table> employee = new List<Employee_table>();

            using (var context = new Company_dbEntities())
            {
                if (request.CompanyName != null)
                {
                    int?compId = AdapterHelper.GetCompanyId(request.CompanyName);
                    if (compId == null)
                    {
                        throw new Exception("No company found. Try again!");
                    }

                    var employee = (from a in context.Employee_table
                                    where a.CompanyID == compId.Value
                                    select a).ToList();


                    List <dto> dt = new List <dto>();

                    if (employee != null)
                    {
                        //response.IsEmployeeExist = true;

                        foreach (var entry in employee)
                        {
                            dto d = new dto();

                            d.EmployeeName = entry.EmployeeName;
                            d.EmployeeID   = entry.UserName;
                            d.Email        = entry.Email;
                            d.Designation  = entry.Designation;
                            //emp.DOB = employee.DOB;
                            //emp.Department = employee.Department;
                            d.ManagerID = entry.ManagerID;
                            d.CompanyID = entry.CompanyID;
                            // emp.CompanyId = employee.CompanyID;
                            //emp.Address = employee.Address;
                            //emp.Contact = employee.Contact;

                            var emp = (from a in context.Employee_table where a.UserName == entry.UserName select a).Count();

                            if (emp > 1)
                            {
                                d.count = 1;
                            }
                            else
                            {
                                d.count = 0;
                            }
                            //var comp = (from a in context.Company_table where a.CompanyID == compId select a.Prefix).FirstOrDefault();

                            //d.EmployeeID = comp + entry.EmployeeID;

                            dt.Add(d);
                        }

                        response.EmployeeInfo = JsonConvert.SerializeObject(dt);
                    }
                }
                else
                {
                    //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email);
                    //if (!empId.HasValue)
                    //    throw new Exception("Employee does not exist!");

                    var employee = (from a in context.Employee_table
                                    where a.UserName == request.UserName && a.Email == request.Email
                                    select a).FirstOrDefault();

                    if (employee != null)
                    {
                        response.IsEmployeeExist = true;

                        dynamic emp = new ExpandoObject();
                        emp.EmployeeName = employee.EmployeeName;
                        emp.UserName     = employee.UserName;
                        emp.Email        = employee.Email;
                        emp.Designation  = employee.Designation;
                        //emp.DOB = employee.DOB;
                        //emp.Department = employee.Department;
                        emp.ManagerId = employee.ManagerID;
                        emp.CompanyId = employee.CompanyID;
                        //emp.Address = employee.Address;
                        //emp.Contact = employee.Contact;
                        emp.EmployeeInfo = employee.EmployeeInfo;

                        response.EmployeeInfo = JsonConvert.SerializeObject(emp);
                    }
                }
            }
            return(response);
        }
        //All employeees under the requested EmployeeId
        public ManageEmployeeResponse ManagerEmployees(ManageEmployeeRequest request)
        {
            ManageEmployeeResponse response = new ManageEmployeeResponse();
            List<Employee_table> employee = new List<Employee_table>();
            //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email);
            //if (!empId.HasValue)
            //    throw new Exception("Employee does not exist!");
            List<dto> dto = new List<dto>();
            using (var context = new Company_dbEntities())
            {
                employee = (from a in context.Employee_table
                            where a.ManagerID == request.UserName
                            select a).ToList();

                if (employee.Count() > 0)
                {
                    foreach (var entry in employee)
                    {
                        dto d = new dto();
                        d.EmployeeID = entry.UserName;
                        d.EmployeeName = entry.EmployeeName;

                        dto.Add(d);
                    }

                    response.ManagerEmployees = JsonConvert.SerializeObject(dto);
                }
                else
                    response.ManagerEmployees = null;
            }
            return response;
        }
        public ManageEmployeeResponse employees(ManageEmployeeRequest request)
        {
            ManageEmployeeResponse response = new ManageEmployeeResponse();

            //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email);
            //if (!empId.HasValue)
            //    throw new Exception("Employee does not exist!");

               // List<dynamic> list = new List<dynamic>();
            //List<Employee_table> employee = new List<Employee_table>();
            using (var context = new Company_dbEntities())
            {
                dto dt = new dto();

                 var employee = (from a in context.Employee_table
                                where a.UserName == request.UserName
                                select a).FirstOrDefault();

                if (employee != null)
                {
                    dt.EmployeeName = employee.EmployeeName;
                    dt.EmployeeID = employee.UserName;
                   // dt.EmployeeID = employee.EmployeeID;
                    dt.ManagerID = employee.ManagerID;
                    //dt.ManagerID = employee.ManagerID;
                    //dt.Department = employee.Department;
                    dt.Designation = employee.Designation;
                    //dt.DOB = employee.DOB;
                    //dt.Address = employee.Address;
                    //dt.Contact = employee.Contact;
                    dt.Email = employee.Email;
                    dt.EmployeeInfo = employee.EmployeeInfo;

                    //var comp = (from a in context.Company_table where a.CompanyID == employee.CompanyID select a.Prefix).FirstOrDefault();

                    //dt.EmployeeID = comp + employee.EmployeeID;

                }

                response.EmployeeList = JsonConvert.SerializeObject(dt);

            }
            return response;
        }
        public ManageEmployeeResponse EmployeeDetail(ManageEmployeeRequest request)
        {
            ManageEmployeeResponse response = new ManageEmployeeResponse();
            //List<Employee_table> employee = new List<Employee_table>();

            using (var context = new Company_dbEntities())
            {
                if(request.CompanyName != null)
                {
                    int? compId = AdapterHelper.GetCompanyId(request.CompanyName);
                    if (compId == null)
                    {
                        throw new Exception("No company found. Try again!");
                    }

                    var employee = (from a in context.Employee_table
                                    where a.CompanyID == compId.Value
                                    select a).ToList();

                    List<dto> dt = new List<dto>();

                    if (employee != null)
                    {
                        //response.IsEmployeeExist = true;

                        foreach(var entry in employee)
                        {

                        dto d = new dto();

                        d.EmployeeName = entry.EmployeeName;
                        d.EmployeeID = entry.UserName;
                        d.Email = entry.Email;
                        d.Designation = entry.Designation;
                        //emp.DOB = employee.DOB;
                        //emp.Department = employee.Department;
                        d.ManagerID = entry.ManagerID;
                        d.CompanyID = entry.CompanyID;
                       // emp.CompanyId = employee.CompanyID;
                        //emp.Address = employee.Address;
                        //emp.Contact = employee.Contact;

                        var emp = (from a in context.Employee_table where a.UserName == entry.UserName select a).Count();

                            if(emp > 1)
                            {
                                d.count = 1;
                            }
                            else
                            {
                                d.count = 0;
                            }
                        //var comp = (from a in context.Company_table where a.CompanyID == compId select a.Prefix).FirstOrDefault();

                        //d.EmployeeID = comp + entry.EmployeeID;

                        dt.Add(d);
                        }

                        response.EmployeeInfo = JsonConvert.SerializeObject(dt);
                    }

                }
                else
                {
                    //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email);
                    //if (!empId.HasValue)
                    //    throw new Exception("Employee does not exist!");

                    var employee = (from a in context.Employee_table
                                    where a.UserName == request.UserName && a.Email == request.Email
                                    select a).FirstOrDefault();

                    if (employee != null)
                    {
                        response.IsEmployeeExist = true;

                        dynamic emp = new ExpandoObject();
                        emp.EmployeeName = employee.EmployeeName;
                        emp.UserName = employee.UserName;
                        emp.Email = employee.Email;
                        emp.Designation = employee.Designation;
                        //emp.DOB = employee.DOB;
                        //emp.Department = employee.Department;
                        emp.ManagerId = employee.ManagerID;
                        emp.CompanyId = employee.CompanyID;
                        //emp.Address = employee.Address;
                        //emp.Contact = employee.Contact;
                        emp.EmployeeInfo = employee.EmployeeInfo;

                        response.EmployeeInfo = JsonConvert.SerializeObject(emp);
                    }
                }

            }
            return response;
        }