public IHttpActionResult JobDetails(string key, int id)
        {
            if (key != AUTHKEY)
            {
                return(StatusCode(HttpStatusCode.InternalServerError));
            }


            JobPostingsModel JobPosting = new JobPostingsModel();

            JobPosting = db.JobPostings.Find(id);

            JobPostingsViewModel JobPostingViewModel = new JobPostingsViewModel();

            JobPostingViewModel.PostingId           = JobPosting.PostingId;
            JobPostingViewModel.ApplicationUserId   = JobPosting.ApplicationUserId;
            JobPostingViewModel.ContactEmail        = db.Users.Find(JobPosting.ApplicationUserId).UserName;
            JobPostingViewModel.PostingDate         = JobPosting.PostingDate;
            JobPostingViewModel.PostingExpiryDate   = JobPosting.PostingExpiryDate;
            JobPostingViewModel.PostingTitle        = JobPosting.PostingTitle;
            JobPostingViewModel.PostingDescription  = JobPosting.PostingDescription;
            JobPostingViewModel.PostingRemuneration = JobPosting.PostingRemuneration;
            JobPostingViewModel.DepartmentId        = JobPosting.DepartmentId;
            JobPostingViewModel.Department          = db.Departments.Find(JobPosting.DepartmentId).DepartmentName;

            return(Ok(JobPostingViewModel));
        }
        public IHttpActionResult ListJobs(string key)
        {
            if (key != AUTHKEY)
            {
                return(StatusCode(HttpStatusCode.InternalServerError));
            }

            List <JobPostingsModel>     allJobsList          = db.JobPostings.ToList();
            List <JobPostingsViewModel> allJobsViewModelList = new List <JobPostingsViewModel> {
            };

            foreach (var element in allJobsList)
            {
                JobPostingsViewModel jobPost = new JobPostingsViewModel
                {
                    PostingId           = element.PostingId,
                    ApplicationUserId   = element.ApplicationUserId,
                    ContactEmail        = db.Users.Find(element.ApplicationUserId).UserName,
                    PostingDate         = element.PostingDate,
                    PostingExpiryDate   = element.PostingExpiryDate,
                    PostingTitle        = element.PostingTitle,
                    PostingDescription  = element.PostingDescription,
                    PostingRemuneration = element.PostingRemuneration,
                    DepartmentId        = element.DepartmentId,
                    Department          = db.Departments.Find(element.DepartmentId).DepartmentName
                };

                allJobsViewModelList.Add(jobPost);
            }

            return(Ok(allJobsViewModelList));
        }
        public IHttpActionResult searchPostings(string key, string searchParam)
        {
            if (key != AUTHKEY)
            {
                return(StatusCode(HttpStatusCode.InternalServerError));
            }

            // Look for entities with titles or descriptions that contain the search parameter, then filter out entities with an expiry date that has already elapsed, and sort the results by the expiry dates
            List <JobPostingsModel>     searchedJobsList          = db.JobPostings.Where(p => p.PostingTitle.Contains(searchParam) || p.PostingDescription.Contains(searchParam)).Where(p => p.PostingExpiryDate > DateTime.Now).OrderBy(p => p.PostingExpiryDate).ToList();
            List <JobPostingsViewModel> searchedJobsViewModelList = new List <JobPostingsViewModel> {
            };

            foreach (var element in searchedJobsList)
            {
                JobPostingsViewModel jobPost = new JobPostingsViewModel
                {
                    PostingId           = element.PostingId,
                    ApplicationUserId   = element.ApplicationUserId,
                    ContactEmail        = db.Users.Find(element.ApplicationUserId).UserName,
                    PostingDate         = element.PostingDate,
                    PostingExpiryDate   = element.PostingExpiryDate,
                    PostingTitle        = element.PostingTitle,
                    PostingDescription  = element.PostingDescription,
                    PostingRemuneration = element.PostingRemuneration,
                    DepartmentId        = element.DepartmentId,
                    Department          = db.Departments.Find(element.DepartmentId).DepartmentName
                };

                searchedJobsViewModelList.Add(jobPost);
            }

            return(Ok(searchedJobsViewModelList));
        }
예제 #4
0
        public ActionResult adminJobPostingEdit(int id)
        {
            //Get API authenication key by combining the server's public key with the client's private key and then hashing the result using SHA1
            //string AUTHKEY = getAuthKey(CLIENTPRIVATEKEY);

            string url = $"jobspostingsapi/jobdetails/{AUTHKEY}/{id}";
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                JobPostingsViewModel postingViewModel = response.Content.ReadAsAsync <JobPostingsViewModel>().Result;

                string departmentsUrl = $"jobspostingsapi/getalldepartments/{AUTHKEY}";
                HttpResponseMessage departmentsResponse = client.GetAsync(departmentsUrl).Result;
                if (departmentsResponse.IsSuccessStatusCode)
                {
                    postingViewModel.DepartmentsList = departmentsResponse.Content.ReadAsAsync <IEnumerable <DepartmentsModel> >().Result;
                    return(View(postingViewModel));
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                return(View("Error"));
            }
        }
예제 #5
0
        public ActionResult postAdminJobPostingCreate(JobPostingsViewModel newPostingViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Error"));
            }

            // Validate incoming form data to ensure that all necessary fields have been completed
            if (newPostingViewModel.PostingExpiryDate == null ||
                newPostingViewModel.PostingTitle == null ||
                newPostingViewModel.PostingTitle == "" ||
                newPostingViewModel.PostingDescription == null ||
                newPostingViewModel.PostingDescription == "" ||
                newPostingViewModel.DepartmentId <= 0)
            {
                return(View("IncompleteForm"));
            }


            JobPostingsModel newPostingModel = new JobPostingsModel
            {
                ApplicationUserId   = User.Identity.GetUserId(),
                PostingDate         = DateTime.Now,
                PostingExpiryDate   = newPostingViewModel.PostingExpiryDate,
                PostingTitle        = newPostingViewModel.PostingTitle,
                PostingDescription  = newPostingViewModel.PostingDescription,
                PostingRemuneration = newPostingViewModel.PostingRemuneration,
                DepartmentId        = newPostingViewModel.DepartmentId
            };


            //Get API authenication key by combining the server's public key with the client's private key and then hashing the result using SHA1
            //string AUTHKEY = getAuthKey(CLIENTPRIVATEKEY);

            string      url     = $"jobspostingsapi/createposting/{AUTHKEY}";
            HttpContent content = new StringContent(jss.Serialize(newPostingModel));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = client.PostAsync(url, content).Result;

            if (response.IsSuccessStatusCode)
            {
                return(View());
            }
            else
            {
                return(View("Error"));
            }
        }
예제 #6
0
        public ActionResult postAdminJobPostingEdit(JobPostingsViewModel editedPostingViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Error"));
            }

            // Validate incoming form data to ensure that all necessary fields have been completed
            if (editedPostingViewModel.PostingId <= 0 ||
                editedPostingViewModel.ApplicationUserId == "" ||
                editedPostingViewModel.ApplicationUserId == null ||
                editedPostingViewModel.PostingExpiryDate == null ||
                editedPostingViewModel.PostingTitle == null ||
                editedPostingViewModel.PostingTitle == "" ||
                editedPostingViewModel.PostingDescription == null ||
                editedPostingViewModel.PostingDescription == "" ||
                editedPostingViewModel.DepartmentId <= 0)
            {
                return(View("IncompleteForm"));
            }

            // Update information of user responsible for the job posting with the information of the user who edited the posting
            editedPostingViewModel.ApplicationUserId = User.Identity.GetUserId();



            //Get API authenication key by combining the server's public key with the client's private key and then hashing the result using SHA1
            //string AUTHKEY = getAuthKey(CLIENTPRIVATEKEY);

            string      url     = $"jobspostingsapi/editposting/{AUTHKEY}";
            HttpContent content = new StringContent(jss.Serialize(editedPostingViewModel));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = client.PostAsync(url, content).Result;

            if (response.IsSuccessStatusCode)
            {
                return(View(editedPostingViewModel));
            }
            else
            {
                return(View("Error"));
            }
        }
예제 #7
0
        public ActionResult JobPostingDetails(int id)
        {
            //Get API authenication key by combining the server's public key with the client's private key and then hashing the result using SHA1
            //string AUTHKEY = getAuthKey(CLIENTPRIVATEKEY);

            string url = $"jobspostingsapi/jobdetails/{AUTHKEY}/{id}";
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                JobPostingsViewModel JobPosting = response.Content.ReadAsAsync <JobPostingsViewModel>().Result;

                return(View(JobPosting));
            }
            else
            {
                return(View("Error"));
            }
        }
        public IHttpActionResult editPosting([FromBody] JobPostingsViewModel editedPostingViewModel, string key)
        {
            if (key != AUTHKEY)
            {
                return(StatusCode(HttpStatusCode.InternalServerError));
            }


            //Will Validate according to data annotations specified on model
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            JobPostingsModel targetPostingModel = db.JobPostings.Find(editedPostingViewModel.PostingId);


            targetPostingModel.PostingTitle        = editedPostingViewModel.PostingTitle;
            targetPostingModel.PostingDescription  = editedPostingViewModel.PostingDescription;
            targetPostingModel.PostingRemuneration = editedPostingViewModel.PostingRemuneration;
            targetPostingModel.PostingDate         = editedPostingViewModel.PostingDate;
            targetPostingModel.PostingExpiryDate   = editedPostingViewModel.PostingExpiryDate;
            targetPostingModel.DepartmentId        = editedPostingViewModel.DepartmentId;
            targetPostingModel.ApplicationUserId   = editedPostingViewModel.ApplicationUserId;

            try
            {
                db.SaveChanges();
                return(StatusCode(HttpStatusCode.NoContent));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(StatusCode(HttpStatusCode.InternalServerError));
            }
        }