Пример #1
0
        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);
            }
        }
Пример #2
0
 private void detach_FoodAllergies(FoodAllergy entity)
 {
     this.SendPropertyChanging();
     entity.Food = null;
 }
Пример #3
0
 private void attach_FoodAllergies(FoodAllergy entity)
 {
     this.SendPropertyChanging();
     entity.Food = this;
 }
Пример #4
0
 partial void DeleteFoodAllergy(FoodAllergy instance);
Пример #5
0
 partial void UpdateFoodAllergy(FoodAllergy instance);
Пример #6
0
 partial void InsertFoodAllergy(FoodAllergy instance);