public async Task <IHttpActionResult> EditJobPosting(JobPostingEditViewModel editedModel) { JobPosting jobPosting = await this._context.JobPostings.FindAsync(editedModel.Id); if (jobPosting == null) { return(BadRequest("This posting doesn't exist in the database.")); } var postingCreator = jobPosting.PostingCreator; if (postingCreator.UserId != RequestContext.Principal.Identity.GetUserId()) { return(BadRequest("You are not authorized to edit this Job Posting.")); } try { jobPosting = AutoMapper.Mapper.Map <JobPosting>(editedModel); this._context.SaveChanges(); } catch (Exception e) { return(InternalServerError(e)); } return(Ok()); }
public async Task <IHttpActionResult> GetEditJobPostingById(int id) { JobPosting jobPosting = await this._context.JobPostings.FindAsync(id); if (jobPosting == null) { return(BadRequest("This posting doesn't exist in the database.")); } var postingCreator = jobPosting.PostingCreator; if (postingCreator.UserId != RequestContext.Principal.Identity.GetUserId()) { return(BadRequest("You are not authorized to edit this Job Posting.")); } JobPostingEditViewModel viewModel = AutoMapper.Mapper.Map <JobPostingEditViewModel>(jobPosting); return(Ok(viewModel)); }