public IHttpActionResult GetAllApplications()
        {
            //List of the applications from the database
            List <EmployeeApplicant> EmployeeApplicants = db.EmployeeApplicant.ToList();

            //Data transfer object to show information about the application
            List <ShowEmployeeApplicant> EmployeeApplicantDtos = new List <ShowEmployeeApplicant> {
            };

            foreach (var EmployeeApplicant in EmployeeApplicants)
            {
                ShowEmployeeApplicant EmployeeApplication = new ShowEmployeeApplicant();

                //Get the user to which the application belongs to
                ApplicationUser user = db.Users.Where(c => c.EmployeeApplicants.Any(m => m.EmployeeApplicantId == EmployeeApplicant.EmployeeApplicantId)).FirstOrDefault();

                ApplicationUserDto parentUser = new ApplicationUserDto
                {
                    Id             = user.Id,
                    FirstName      = user.FirstName,
                    LastName       = user.LastName,
                    EmployeeNumber = user.EmployeeNumber,
                    Email          = user.Email
                };
                //Get the course of application
                Courses Course = db.Courses.Where(l => l.EmployeeApplicant.Any(m => m.EmployeeApplicantId == EmployeeApplicant.EmployeeApplicantId)).FirstOrDefault();


                CoursesDto Courses = new CoursesDto
                {
                    CourseId   = Course.CourseId,
                    CourseCode = Course.CourseCode,
                    CourseName = Course.CourseName
                };


                EmployeeApplicantDto NewEmployeeApplicant = new EmployeeApplicantDto
                {
                    EmployeeApplicantId = EmployeeApplicant.EmployeeApplicantId,
                    Id       = EmployeeApplicant.Id,
                    CourseId = EmployeeApplicant.CourseId
                };



                EmployeeApplication.EmployeeApplicant = NewEmployeeApplicant;
                EmployeeApplication.Courses           = Courses;
                EmployeeApplication.User = parentUser;
                EmployeeApplicantDtos.Add(EmployeeApplication);
            }

            return(Ok(EmployeeApplicantDtos));
        }
        public ActionResult Edit(int id)
        {
            EditEmployeeApplicant NewEmployeeApplicant = new EditEmployeeApplicant();

            //Get the selected employee application from the database
            string url = "EmployeeApplicantsData/FindApplication/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                EmployeeApplicantDto SelectedApplication = response.Content.ReadAsAsync <EmployeeApplicantDto>().Result;
                NewEmployeeApplicant.EmployeeApplicant = SelectedApplication;
            }
            else
            {
                return(RedirectToAction("Error"));
            }

            //Get all users from the database for dropdown list
            url      = "EmployeeApplicantsData/GetUsers";
            response = client.GetAsync(url).Result;
            if (response.IsSuccessStatusCode)
            {
                IEnumerable <ApplicationUserDto> SelectedUsers = response.Content.ReadAsAsync <IEnumerable <ApplicationUserDto> >().Result;
                NewEmployeeApplicant.AllUsers = SelectedUsers;
            }
            else
            {
                return(RedirectToAction("Error"));
            }

            //Get all courses from the database for dropdown list
            url      = "EmployeeApplicantsData/GetCourses";
            response = client.GetAsync(url).Result;
            if (response.IsSuccessStatusCode)
            {
                IEnumerable <CoursesDto> SelectedJobs = response.Content.ReadAsAsync <IEnumerable <CoursesDto> >().Result;
                NewEmployeeApplicant.AllCourses = SelectedJobs;
            }
            else
            {
                return(RedirectToAction("Error"));
            }
            return(View(NewEmployeeApplicant));
        }
        public ActionResult DeleteConfirm(int id)
        {
            //Get current employee application from the database
            string url = "EmployeeApplicantsData/FindApplication/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into EmployeeApplicant data transfer object
                EmployeeApplicantDto SelectedApplication = response.Content.ReadAsAsync <EmployeeApplicantDto>().Result;
                return(View(SelectedApplication));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        public IHttpActionResult GetCourseApplications(int id)
        {
            List <EmployeeApplicant> EmployeeApplicants = db.EmployeeApplicant.Where(a => a.CourseId == id)
                                                          .ToList();
            List <EmployeeApplicantDto> EmployeeApplicantDtos = new List <EmployeeApplicantDto> {
            };

            //Here you can choose which information is exposed to the API
            foreach (var EmployeeApplicant in EmployeeApplicants)
            {
                EmployeeApplicantDto NewEmployeeApplication = new EmployeeApplicantDto
                {
                    EmployeeApplicantId = EmployeeApplicant.EmployeeApplicantId,
                    Id = EmployeeApplicant.Id
                };
                EmployeeApplicantDtos.Add(NewEmployeeApplication);
            }

            return(Ok(EmployeeApplicantDtos));
        }
        public IHttpActionResult FindApplication(int id)
        {
            EmployeeApplicant EmployeeApplicant = db.EmployeeApplicant.Find(id);

            if (EmployeeApplicant == null)
            {
                return(NotFound());
            }

            //A data transfer object model used to show only most relevant information
            EmployeeApplicantDto TempEmployeeApplicant = new EmployeeApplicantDto
            {
                EmployeeApplicantId = EmployeeApplicant.EmployeeApplicantId,
                Reason   = EmployeeApplicant.Reason,
                Id       = EmployeeApplicant.Id,
                CourseId = EmployeeApplicant.CourseId
            };

            return(Ok(TempEmployeeApplicant));
        }
        /// <summary>
        /// Returns a list of applications for a given user.
        /// </summary>
        /// <param name="id">The input UserID (string)</param>
        /// <returns>A list of applications applied by that user</returns>
        /// <example>
        /// GET api/EmployeeApplicantData/GetApplicationsForUser/abcedf-12345-ghijkl
        /// </example>
        public IHttpActionResult GetApplicationsForUser(string id)
        {
            IEnumerable <EmployeeApplicant> EmployeeApplicantId      = db.EmployeeApplicant.Where(s => s.Id == id);
            List <EmployeeApplicantDto>     EmployeeApplicationsDtos = new List <EmployeeApplicantDto>()
            {
            };

            foreach (var applications in EmployeeApplicantId)
            {
                EmployeeApplicantDto AppliedcoursesDto = new EmployeeApplicantDto
                {
                    EmployeeApplicantId = applications.EmployeeApplicantId,
                    Reason   = applications.Reason,
                    CourseId = applications.CourseId,
                    Id       = applications.Id
                };
                EmployeeApplicationsDtos.Add(AppliedcoursesDto);
            }

            return(Ok(EmployeeApplicationsDtos));
        }
        public IHttpActionResult GetEmployeeApplicant()
        {
            //Getting the list of application  objects from the databse
            List <EmployeeApplicant>    EmployeeApplicants    = db.EmployeeApplicant.ToList();
            List <EmployeeApplicantDto> EmployeeApplicantDtos = new List <EmployeeApplicantDto> {
            };

            //Transfering application to data transfer object
            foreach (var EmployeeApplicant in EmployeeApplicants)
            {
                EmployeeApplicantDto NewEmployeeApplicant = new EmployeeApplicantDto
                {
                    EmployeeApplicantId = EmployeeApplicant.EmployeeApplicantId,
                    Reason   = EmployeeApplicant.Reason,
                    Id       = EmployeeApplicant.Id,
                    CourseId = EmployeeApplicant.CourseId
                };
                EmployeeApplicantDtos.Add(NewEmployeeApplicant);
            }

            return(Ok(EmployeeApplicantDtos));
        }
        public ActionResult Details(int id)
        {
            GetApplicationCookie();

            ShowEmployeeApplicant ShowEmployeeApplicant = new ShowEmployeeApplicant();

            ShowEmployeeApplicant.isadmin = User.IsInRole("Admin");

            //Find the Employee application from the database
            string url = "EmployeeApplicantsData/FindApplication/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                EmployeeApplicantDto SelectedApplication = response.Content.ReadAsAsync <EmployeeApplicantDto>().Result;
                ShowEmployeeApplicant.EmployeeApplicant = SelectedApplication;

                //Associated Employee Application with User
                url      = "EmployeeApplicantsData/GetApplicationUser/" + id;
                response = client.GetAsync(url).Result;
                ApplicationUserDto SelectedUser = response.Content.ReadAsAsync <ApplicationUserDto>().Result;
                ShowEmployeeApplicant.User = SelectedUser;

                //Associated Employee application with Course
                url      = "EmployeeApplicantsData/GetCourseForApplication/" + id;
                response = client.GetAsync(url).Result;
                CoursesDto SelectedCourse = response.Content.ReadAsAsync <CoursesDto>().Result;
                ShowEmployeeApplicant.Courses = SelectedCourse;

                return(View(ShowEmployeeApplicant));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }