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() }); } }
static DataController() { recipes = new recipeEntities(); //nutritional_value n = recipes.nutritional_value.Where(nt => nt.name == "sugar").First(); //n.mustable = false; //recipes.SaveChanges(); }
public JsonResult addRecipe(recipe recipe,equipment_in_recipe[] equipments, products_in_recipe[] products_in_recipe) { using (recipes = new recipeEntities()) { try { recipes.SaveChanges(); } catch (DbEntityValidationException ex) { catch_errors(ex); // Retrieve the error messages as a list of strings. } var r = recipes.Entry(recipe); r.State = EntityState.Added; r.Entity.equipment_in_recipe = equipments; r.Entity.isApproved(); r.Entity.products_in_recipe = products_in_recipe; try { recipes.SaveChanges(); } catch (DbEntityValidationException ex) { catch_errors(ex); // Retrieve the error messages as a list of strings. } return Json(new { success = true, recipe = recipe.getSerialize() }); } }
public JsonResult existUser(string name, string password,string email) { using (re = new recipeEntities()) { bool can = true; user user = null; string reason = "This User doen't exists"; var c = re.users.Where(u => u.name == name && u.password == password).Count(); if (c != 0) { can = false; reason = "This user already exist"; user = re.users.Where(u => u.name == name && u.password == password).First(); Session["user"] = user; } else if (email != null) { c = re.users.Where(u => u.email == email).Count(); if (c != 0) { can = false; reason = "This email address already exists"; } } if (user != null) user = user.getSerialize(); var ob = new { can = can, reason = reason, exist = !can, user = user }; return Json(ob, JsonRequestBehavior.AllowGet); } }
//=========== create new product from class Product from application classes public static product create(Product product) { using(var res = new recipeEntities()){ product p = new product(); List<int> managers = res.users.Where(u => u.user_or_manager == true) .Select(u => u.id).ToList(); p.name = product.name; p.description = product.description; p.user_id = product.userId; p.approved = managers.Any(id => id == p.user_id); p.amount_weight_in_volume = product.weight_in_volume; p.nutritional_per = product.nutritional_per; return p; } }
//=========== create new product from class Product from application classes public static product create(Product product) { using (var res = new recipeEntities()){ product p = new product(); List <int> managers = res.users.Where(u => u.user_or_manager == true) .Select(u => u.id).ToList(); p.name = product.name; p.description = product.description; p.user_id = product.userId; p.approved = managers.Any(id => id == p.user_id); p.amount_weight_in_volume = product.weight_in_volume; p.nutritional_per = product.nutritional_per; return(p); } }
public JsonResult addUser(user user) { using (re = new recipeEntities()) { var success = true; if (TryUpdateModel(user)) { re.users.Add(user); //Membership.CreateUser(user.name, user.password); try { //Membership.CreateUser(user.name, user.password, user.email); re.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } else { success = false; } return Json(new { success = success, id = user.id, user = user.getSerialize() }, JsonRequestBehavior.AllowGet); } }
static products_in_nutritional_value() { re = new recipeEntities(); }
static recipe() { re = new recipeEntities(); }
public JsonResult approvep(int id) { using (recipes = new recipeEntities()) { var pr = recipes.products.FirstOrDefault(p => p.id == id); pr.approved = true; recipes.SaveChanges(); return Json(new { success = "success", product = pr.getSerialize() }, JsonRequestBehavior.AllowGet); } }
static product() { re = new recipeEntities(); }
public JsonResult approver(int id) { using (recipes = new recipeEntities()) { var rec = recipes.recipes.FirstOrDefault(r => r.id == id); rec.approved = true; recipes.SaveChanges(); return Json(new { success = "success", recipe = rec.getSerialize() }, JsonRequestBehavior.AllowGet); } }
public JsonResult getProducts(string where="") { using (recipes = new recipeEntities()) { int id; bool isManager = false; if (Session["user"] is user) { id = (Session["user"] as user).id; isManager = (Session["user"] as user).user_or_manager; } else id = 0; List<nutritional_value_details> nutritionalDetails = recipes.nutritional_value_details.ToList(); List<product> products = recipes.products.Where(p => isManager || p.approved == true || p.user_id == id).ToList(); products = products.Select(p => p.getSerialize()).ToList(); var prod = products.Select(p => new { product = p, nutritional = nutritionalDetails.Where(nv => nv.product_id == p.id).ToList() }).ToList(); return Json(prod, JsonRequestBehavior.AllowGet); } }
public JsonResult product(int id) { using (recipes = new recipeEntities()) { bool ans = false; product product = recipes.products.FirstOrDefault(p => p.id == id); recipes.products.Remove(product); recipes.SaveChanges(); return Json(new { success = ans }, JsonRequestBehavior.AllowGet); } }
public JsonResult getDetails() { using (recipes = new recipeEntities()) { var nvv = recipes.nutritional_value.Where(nv => nv.mustable).ToList(); return Json( new { measureTypes = recipes.measure_type.ToList().Select(t => t.getSerialize()).ToList(), measurements = recipes.measurement_with_type.ToList(), nutritionalValues = nvv.Select(nv => nv.getSerialize()).ToList(), // recipes = recipes.recipes, user = Session["user"] }, JsonRequestBehavior.AllowGet ); } }
public JsonResult product(product p) { using (recipes = new recipeEntities()) { bool ans = false; if (ModelState.IsValid) { //recipes.Entry(p).State = EntityState.Modified; recipes.SaveChanges(); ans = true; } return Json(new { success = ans, product = p }, JsonRequestBehavior.AllowGet); } }
public JsonResult getRecipes() { using (recipes = new recipeEntities()) { int id; bool isManager = false; if (Session["user"] is user) { id = (Session["user"] as user).id; isManager = (Session["user"] as user).user_or_manager; } else id = 0; List<recipe> recipe = recipes.recipes.Where(r => isManager || r.approved == true || r.user_id == id).ToList(); recipe = recipe.Select(r => r.getSerialize()).ToList(); return Json(recipe, JsonRequestBehavior.AllowGet); } }
static RecipeController() { recipes = new recipeEntities(); }
public JsonResult user(int id) { using (recipes = new recipeEntities()) { bool ans = false; user user = recipes.users.FirstOrDefault(p => p.id == id); recipes.users.Remove(user); recipes.SaveChanges(); return Json(new { success = ans }, JsonRequestBehavior.AllowGet); } }
static LoginController() { re = new recipeEntities(); }
public JsonResult users() { using (recipes = new recipeEntities()) { user user = (Session["user"] as user); if (user != null && user.user_or_manager) return Json(new { success = true, users = recipes.users.Select(u => u.getSerialize()).ToList() }, JsonRequestBehavior.AllowGet); return Json(new { success = false, reason = sentences.notAllowedData }, JsonRequestBehavior.AllowGet); } }
public JsonResult recipe(recipe r) { using (recipes = new recipeEntities()) { bool ans = false; if (ModelState.IsValid) { var rec = recipes.Entry(r); //rec.State = EntityState.Modified; recipes.SaveChanges(); ans = true; } return Json(new { success = ans, recipe = r }, JsonRequestBehavior.AllowGet); } }
public JsonResult getLists() { using (recipes = new recipeEntities()) { var cat = recipes.categories.ToList().Select(c => c.getSerialize()).ToList(); var pro = getProducts().Data; var det = getDetails().Data; var rec = getRecipes().Data; var ans = new { success = true, categories = cat, products = pro, details = det, recipes = rec }; return Json(ans, JsonRequestBehavior.AllowGet); } }
public JsonResult recipe(int id) { using (recipes = new recipeEntities()) { bool ans = false; recipe recipe = recipes.recipes.FirstOrDefault(r => r.id == id); recipes.recipes.Remove(recipe); recipes.SaveChanges(); return Json(new { success = ans }, JsonRequestBehavior.AllowGet); } }