Beispiel #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);
        }
Beispiel #2
0
 private ProductDTO MapProduct(Product p)
 {
     ProductDTO ret = mapper.Map<Product, ProductDTO>(p);
     return SetupProductDTO(ret);
 }
Beispiel #3
0
 public ProductViewModel(Product product)
 {
     this.Product = product;
 }
Beispiel #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);
        }
Beispiel #5
0
 public ProductViewModel()
 {
     Product = new Product();
 }