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 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")); } }