public IHttpActionResult PutJobType(int id, JobTypeViewModel jobTypeViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != jobTypeViewModel.JobTypeId) { return(BadRequest()); } JobType jobType = ViewModelMapper.ToModelJobTypes(jobTypeViewModel); db.Entry(jobType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!JobTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostJobType(JobTypeViewModel jobTypeViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } JobType jobType = ViewModelMapper.ToModelJobTypes(jobTypeViewModel); db.JobTypes.Add(jobType); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = jobType.JobTypeId }, ViewModelMapper.ToViewModelJobTypes(jobType))); }