public Allergens CreateAllergen(Allergens allergen)
        {
            //Clone allergensInMenu to new location in memory, so they are not overridden on Attach
            var newAllergenInMenu = new List <AllergensInMenu>(allergen.AllergensInMenu);

            //Attach ingredient so basic properties are updated
            _ctx.Attach(allergen).State = EntityState.Added;
            //Remove all recipelines with updated order information
            _ctx.AllergensInMenu.RemoveRange(
                _ctx.AllergensInMenu.Where(ol => ol.MainFoodId == allergen.Id)
                );
            //Add all orderlines with updated order information
            foreach (var ol in newAllergenInMenu)
            {
                _ctx.Entry(ol).State = EntityState.Added;
            }
            // Save it
            _ctx.SaveChanges();
            //Return it
            return(allergen);
        }
Exemplo n.º 2
0
 public Ingredients CreateIngredient(Ingredients ingredient)
 {
     _ctx.Attach(ingredient).State = EntityState.Added;
     _ctx.SaveChanges();
     return(ingredient);
 }
Exemplo n.º 3
0
 public SpecialOffers CreateSpecialOffers(SpecialOffers specialOffers)
 {
     _ctx.Attach(specialOffers).State = EntityState.Added;
     _ctx.SaveChanges();
     return(specialOffers);
 }
Exemplo n.º 4
0
 public MainFood CreateMainFood(MainFood mainFood)
 {
     _ctx.Attach(mainFood).State = EntityState.Added;
     _ctx.SaveChanges();
     return(mainFood);
 }
Exemplo n.º 5
0
 public MOTD CreateMOTD(MOTD motd)
 {
     _ctx.Attach(motd).State = EntityState.Added;
     _ctx.SaveChanges();
     return(motd);
 }
 public Users CreateUsers(Users user)
 {
     _ctx.Attach(user).State = EntityState.Added;
     _ctx.SaveChanges();
     return(user);
 }