public IHttpActionResult GetJobPosts() { List <JobPosting> JobPosts = db.JobPostings.ToList(); List <JobPostingDto> JobPostsDtos = new List <JobPostingDto> { }; //Here you can choose which information is exposed to the API foreach (var JobPost in JobPosts) { JobPostingDto NewJobPost = new JobPostingDto { JobId = JobPost.JobId, JobTitle = JobPost.JobTitle, JobDescription = JobPost.JobDescription, JobCategory = JobPost.JobCategory, JobLocation = JobPost.JobLocation, PositionType = JobPost.PositionType, SalaryRange = JobPost.SalaryRange, DatePosted = JobPost.DatePosted.Date, Email = JobPost.Email, DepartmentName = JobPost.Department.DepartmentName }; JobPostsDtos.Add(NewJobPost); } return(Ok(JobPostsDtos)); }
// GET: JobPosting/Details/5 public ActionResult Details(int id) { ShowJobPosting ViewModel = new ShowJobPosting(); ViewModel.isadmin = User.IsInRole("Admin"); string url = "jobpostingdata/findjobposting/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. Debug.WriteLine("Details:" + response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into department data transfer object JobPostingDto SelectedJobPosting = response.Content.ReadAsAsync <JobPostingDto>().Result; ViewModel.jobposting = SelectedJobPosting; url = "jobpostingdata/finddepartmentforjobposting/" + id; response = client.GetAsync(url).Result; DepartmentDto SelectedDepartment = response.Content.ReadAsAsync <DepartmentDto>().Result; ViewModel.department = SelectedDepartment; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindPost(int id) { //Find the data JobPosting jobPosting = db.JobPostings.Find(id); //if not found, return 404 status code. if (jobPosting == null) { return(NotFound()); } //put into a 'friendly object format' JobPostingDto jobPostingDto = new JobPostingDto { JobId = jobPosting.JobId, JobTitle = jobPosting.JobTitle, JobDescription = jobPosting.JobDescription, JobCategory = jobPosting.JobCategory, JobLocation = jobPosting.JobLocation, PositionType = jobPosting.PositionType, SalaryRange = jobPosting.SalaryRange, DatePosted = jobPosting.DatePosted.Date, Email = jobPosting.Email, DepartmentName = jobPosting.Department.DepartmentName, }; //pass along data as 200 status code OK response return(Ok(jobPostingDto)); }
public ActionResult Edit(int id) { UpdateJobPosting ViewModel = new UpdateJobPosting(); string url = "jobpostingdata/findpost/" + 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 jobposting data transfer object JobPostingDto SelectedJobPostings = response.Content.ReadAsAsync <JobPostingDto>().Result; ViewModel.JobPosting = SelectedJobPostings; url = "DepartmentData/GetDepartments"; response = client.GetAsync(url).Result; IEnumerable <DepartmentDto> departments = response.Content.ReadAsAsync <IEnumerable <DepartmentDto> >().Result; ViewModel.AllDepartments = departments; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public ActionResult Edit(int id) { UpdateJobPosting ViewModel = new UpdateJobPosting(); string url = "jobpostingdata/findjobposting/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. Debug.WriteLine("edit: " + response.StatusCode); if (response.IsSuccessStatusCode) { JobPostingDto SelectedJobPosting = response.Content.ReadAsAsync <JobPostingDto>().Result; ViewModel.jobposting = SelectedJobPosting; url = "departmentdata/getdepartments"; response = client.GetAsync(url).Result; IEnumerable <DepartmentDto> PotentialDepartments = response.Content.ReadAsAsync <IEnumerable <DepartmentDto> >().Result; Debug.WriteLine("Jobposting before getDepartment:"); ViewModel.alldepartments = PotentialDepartments; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindJobPostingsForDepartment(int id) { List <JobPosting> JobPostings = db.JobPostings .Where(t => t.DepartmentID == id) .ToList(); List <JobPostingDto> JobPostingDtos = new List <JobPostingDto> { }; foreach (var JobPosting in JobPostings) { JobPostingDto NewJobPosting = new JobPostingDto { JobId = JobPosting.JobId, JobTitle = JobPosting.JobTitle, JobDescription = JobPosting.JobDescription, JobCategory = JobPosting.JobCategory, JobLocation = JobPosting.JobLocation, PositionType = JobPosting.PositionType, SalaryRange = JobPosting.SalaryRange, DatePosted = JobPosting.DatePosted.Date, Email = JobPosting.Email, DepartmentName = JobPosting.Department.DepartmentName }; JobPostingDtos.Add(NewJobPosting); } return(Ok(JobPostingDtos)); }
public ActionResult DeleteConfirm(int id) { string url = "jobpostingdata/findpost/" + 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 Jobposting data transfer object JobPostingDto SelectedPost = response.Content.ReadAsAsync <JobPostingDto>().Result; return(View(SelectedPost)); } else { return(RedirectToAction("Error")); } }
public ActionResult Details(int id) { ShowJobPosting ViewModel = new ShowJobPosting(); string url = "jobpostingdata/findpost/" + id; HttpResponseMessage response = client.GetAsync(url).Result; // If the response is a success, proceed if (response.IsSuccessStatusCode) { // Fetch the response content into IEnumerable<JobPostingDto> JobPostingDto SelectedPost = response.Content.ReadAsAsync <JobPostingDto>().Result; ViewModel.JobPosting = SelectedPost; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult GetJobPostings() { List <JobPosting> JobPostings = db.jobPostings.ToList(); List <JobPostingDto> JobPostingDtos = new List <JobPostingDto> { }; Debug.WriteLine("Files Received"); foreach (var JobPosting in JobPostings) { Department Department = db.departments .Where(s => s.jobpostings.Any(m => m.departmentId == JobPosting.departmentId)) .FirstOrDefault(); // if not found, return 404 status code. if (Department == null) { return(NotFound()); } JobPostingDto NewJobPosting = new JobPostingDto { jobPostingId = JobPosting.jobPostingId, jobNumber = JobPosting.jobNumber, jobTitle = JobPosting.jobTitle, jobType = JobPosting.jobType, jobDescription = JobPosting.jobDescription, salary = JobPosting.salary, closingDate = JobPosting.closingDate, departmentId = Department.departmentId, departmentName = Department.departmentName }; JobPostingDtos.Add(NewJobPosting); } return(Ok(JobPostingDtos)); }
public IHttpActionResult FindJobPosting(int id) { JobPosting JobPosting = db.jobPostings.Find(id); if (JobPosting == null) { return(NotFound()); } Department Department = db.departments .Where(t => t.jobpostings.Any(p => p.jobPostingId == id)) .FirstOrDefault(); // if not found, return 404 status code. if (Department == null) { return(NotFound()); } JobPostingDto JobPostingDto = new JobPostingDto { jobPostingId = JobPosting.jobPostingId, jobNumber = JobPosting.jobNumber, jobTitle = JobPosting.jobTitle, jobType = JobPosting.jobType, jobDescription = JobPosting.jobDescription, salary = JobPosting.salary, closingDate = JobPosting.closingDate, departmentId = Department.departmentId, departmentName = Department.departmentName }; //pass along data as 200 status code OK response return(Ok(JobPostingDto)); }