public int AddFood(FoodModel food, string email) { db.Connection.Open(); var foods = db.Foods; var user = db.Users.SingleOrDefault(x => x.Email == email); var foodToInsert = new Food { Description = food.Description, ExpDate = food.ExpDate, Guid = food.GuidLine, PicPath = food.PhotoPath, UserID = user.ID }; try { foods.InsertOnSubmit(foodToInsert); db.SubmitChanges(); } catch (Exception e) { return(0); } var foodInDB = db.Foods.SingleOrDefault(x => x.Guid == food.GuidLine); if (foodInDB == null) { return(0); } else { foreach (var a in food.Allergies) { FoodAllergy foodAllergy = new FoodAllergy { AllergyID = a, FoodID = foodInDB.ID }; try { db.FoodAllergies.InsertOnSubmit(foodAllergy); db.SubmitChanges(); } catch (Exception e) { return(0); } } db.Connection.Close(); return(1); } }
private void detach_FoodAllergies(FoodAllergy entity) { this.SendPropertyChanging(); entity.Food = null; }
private void attach_FoodAllergies(FoodAllergy entity) { this.SendPropertyChanging(); entity.Food = this; }
partial void DeleteFoodAllergy(FoodAllergy instance);
partial void UpdateFoodAllergy(FoodAllergy instance);
partial void InsertFoodAllergy(FoodAllergy instance);