public IHttpActionResult PutAreaOfExpertise(int id, AreaOfExpertiseViewModel AreaOfExpertiseViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != AreaOfExpertiseViewModel.Id) { return(BadRequest()); } AreaOfExpertise AreaOfExpertise = new AreaOfExpertise(); Mapper.CreateMap <AreaOfExpertiseViewModel, AreaOfExpertise>(); AreaOfExpertise = Mapper.Map <AreaOfExpertiseViewModel, AreaOfExpertise>(AreaOfExpertiseViewModel); db.Entry(AreaOfExpertise).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AreaOfExpertiseExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
//public IHttpActionResult GetAreaOfExpertise(int id) public AreaOfExpertiseViewModel GetAreaOfExpertise(int id) { AreaOfExpertiseViewModel AreaOfExpertiseViewModel = new AreaOfExpertiseViewModel(); NGOdata.AreaOfExpertise GetAreaOfExpertise; GetAreaOfExpertise = db.AreaOfExpertise.Where(x => x.Id == id).FirstOrDefault(); Mapper.CreateMap <AreaOfExpertise, AreaOfExpertiseViewModel>(); AreaOfExpertiseViewModel = Mapper.Map <AreaOfExpertise, AreaOfExpertiseViewModel>(GetAreaOfExpertise); return(AreaOfExpertiseViewModel); }
public IHttpActionResult PostAreaOfExpertise(AreaOfExpertiseViewModel AreaOfExpertiseViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } AreaOfExpertise AreaOfExpertise = new AreaOfExpertise(); Mapper.CreateMap <AreaOfExpertiseViewModel, AreaOfExpertise>(); AreaOfExpertise = Mapper.Map <AreaOfExpertiseViewModel, AreaOfExpertise>(AreaOfExpertiseViewModel); db.AreaOfExpertise.Add(AreaOfExpertise); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = AreaOfExpertise.Id }, AreaOfExpertise)); }
// GET: api/AreaOfExpertise public List <AreaOfExpertiseViewModel> GetAreaOfExpertise() { var AreaOfExpertiseList = db.AreaOfExpertise.ToList(); List <AreaOfExpertiseViewModel> AreaOfExpertiseViewModelList = new List <AreaOfExpertiseViewModel>(); foreach (var item in AreaOfExpertiseList) { AreaOfExpertiseViewModel AreaOfExpertiseViewModel = new AreaOfExpertiseViewModel(); Mapper.CreateMap <AreaOfExpertise, AreaOfExpertiseViewModel>(); AreaOfExpertiseViewModel = Mapper.Map <AreaOfExpertise, AreaOfExpertiseViewModel>(item); AreaOfExpertiseViewModelList.Add(AreaOfExpertiseViewModel); } return(AreaOfExpertiseViewModelList); }