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 deletePosting(string key, int id) { if (key != AUTHKEY) { return(StatusCode(HttpStatusCode.InternalServerError)); } JobPostingsModel targetJobPostingModel = db.JobPostings.Find(id); // Check that the type exists in the database if (targetJobPostingModel == null) { return(NotFound()); } try { db.JobPostings.Remove(targetJobPostingModel); db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); } catch (DbUpdateConcurrencyException) { return(StatusCode(HttpStatusCode.InternalServerError)); } }
public IHttpActionResult FindJobPostingsforDepartment(int id) { List <JobPostingsModel> jobPostings = db.JobPostings .Where(j => j.DepartmentId == id) .ToList(); List <JobPostingsModel> jobs = new List <JobPostingsModel> { }; foreach (var jobPosting in jobPostings) { JobPostingsModel job = new JobPostingsModel { ApplicationUserId = jobPosting.ApplicationUserId, PostingDate = jobPosting.PostingDate, PostingExpiryDate = jobPosting.PostingExpiryDate, PostingTitle = jobPosting.PostingTitle, PostingDescription = jobPosting.PostingDescription, PostingRemuneration = jobPosting.PostingRemuneration, DepartmentId = jobPosting.DepartmentId, PostingId = jobPosting.PostingId }; jobs.Add(job); } return(Ok(jobs)); }
public ActionResult Create(JobPostingsModel JobPost) { try { // TODO: Add insert logic here jobPostingsCollection.InsertOne(JobPost); return(RedirectToAction("Index")); } catch { return(View()); } }
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")); } }
public IHttpActionResult createPosting([FromBody] JobPostingsModel newPosting, string key) { if (key != AUTHKEY) { return(StatusCode(HttpStatusCode.InternalServerError)); } //Will Validate according to data annotations specified on model if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.JobPostings.Add(newPosting); db.SaveChanges(); return(Ok()); }
public ActionResult Edit(String id, JobPostingsModel JobPost) { try { // TODO: Add update logic here var filter = Builders <JobPostingsModel> .Filter.Eq("_id", ObjectId.Parse(id)); var update = Builders <JobPostingsModel> .Update .Set("JobTitle", JobPost.JobTitle) .Set("Company", JobPost.Company) .Set("PostedSalary", JobPost.PostedSalary) .Set("PostDate", JobPost.PostDate) .Set("JOblink", JobPost.JOblink); var result = jobPostingsCollection.UpdateOne(filter, update); return(RedirectToAction("Index")); } catch { return(View()); } }
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)); } }