Esempio n. 1
0
 public JsonResult addProduct(Product addProduct, NutritonalValue_for_product[] nutritionals)
 {
     using (recipes = new recipeEntities())
     {
         try
         {
             recipes.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             catch_errors(ex);
         }
         product p = addProduct.getEntity();
         var pr = recipes.Entry(p);
         pr.State = EntityState.Added;
         List<products_in_nutritional_value> nutritionalsVal = nutritionals.Select(n => n.getEntity()).ToList();
         pr.Entity.products_in_nutritional_value = nutritionalsVal;
         try
         {
             recipes.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             catch_errors(ex);
         }
         return Json(new { success = true, p = p.getSerialize() });
     }
 }
 //========= Constructors
 public static products_in_nutritional_value create(NutritonalValue_for_product nutritional_for_product)
 {
     var pn = new products_in_nutritional_value();
     pn.amount_per_100 = nutritional_for_product.amount;
     pn.nutritional_value_id = nutritional_for_product.idNutritional;
     pn.product_id = nutritional_for_product.productId;
     return pn;
 }
        //========= Constructors

        public static products_in_nutritional_value create(NutritonalValue_for_product nutritional_for_product)
        {
            var pn = new products_in_nutritional_value();

            pn.amount_per_100       = nutritional_for_product.amount;
            pn.nutritional_value_id = nutritional_for_product.idNutritional;
            pn.product_id           = nutritional_for_product.productId;
            return(pn);
        }