// POST: api/Products public IHttpActionResult Post([FromBody] ProductPostRM product) { var entity = Mapper.Map <Product>(product); db.Add(entity); db.SaveChanges(); return(Ok(Mapper.Map <ProductRM>(entity))); }
// PUT: api/Products/5 public IHttpActionResult Put(int id, [FromBody] ProductPostRM product) { if (id <= 0 || product == null) { return(BadRequest("Bad transaction")); } { var entity = Mapper.Map <Product>(product); entity.Id = id; db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(Ok(Mapper.Map <ProductRM>(entity))); } }