Exemple #1
0
        public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != product.Id)
            {
                return BadRequest();
            }

            db.Entry(product).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemple #2
0
 private ProductDTO MapProduct(Product p)
 {
     ProductDTO ret = mapper.Map<Product, ProductDTO>(p);
     return SetupProductDTO(ret);
 }
Exemple #3
0
 public ProductViewModel(Product product)
 {
     this.Product = product;
 }
Exemple #4
0
        public IHttpActionResult PostProduct(Product product)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Products.Add(product);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = product.Id }, product);
        }
Exemple #5
0
 public ProductViewModel()
 {
     Product = new Product();
 }