示例#1
0
        // 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)));
        }
示例#2
0
 // 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)));
     }
 }