public HttpResponseMessage Create(int id, Product product)
 {
     var proposition = propositionRepository.Find(id);
     if (product == null)
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
     proposition.Products.Add(product);
     propositionRepository.InsertOrUpdate(proposition);
     propositionRepository.Save();
     return new HttpResponseMessage(HttpStatusCode.OK);
 }
        public HttpResponseMessage Edit(Product model)
        {
            if (ModelState.IsValid)
            {
                productRepository.InsertOrUpdate(model);
                productRepository.Save();

                var response = new HttpResponseMessage(HttpStatusCode.Accepted);
                return response;
            }
            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
 public void InsertOrUpdate(Product product)
 {
     if (product.Id == default(int)) {
         // New entity
         context.Products.Add(product);
     } else {
         // Existing entity
         if (context.Entry(product).State == EntityState.Detached)
             context.Set<Product>().Attach(product);
         context.Entry(product).State = EntityState.Modified;
     }
 }
        public string Edit(Product model)
        {
            if (Request.IsAjaxRequest())
            {
                try
                {
                    if (!ModelState.IsValid)
                        return "Fail";

                    productRepository.InsertOrUpdate(model);
                    productRepository.Save();
                }
                catch
                {
                    return "Fail";
                }
                return "Success";
            }
            return null;
        }
 private dynamic Product_(Product product)
 {
     dynamic json_product = new JsonObject();
     json_product.Id = product.Id;
     json_product.isComplex = product.isComplex;
     json_product.Price = product.Price;
     json_product.Summary = product.Summary;
     json_product.Title = product.Title;
     return json_product;
 }