Exemple #1
0
        public static db.Ingredient Map(lib.Ingredient ingredient)
        {
            db.Ingredient dbIngredient = new db.Ingredient
            {
                Id    = ingredient.Id,
                Name  = ingredient.Name,
                Price = ingredient.Price
            };

            return(dbIngredient);
        }
        public static void SyncFromDatabase()
        {
            lib.Ingredient.Ingredients.Clear();
            List <db.Ingredient> ingredients = ingredientRepo.GetAllIngredients();

            foreach (var ingredient in ingredients)
            {
                lib.Ingredient i = new lib.Ingredient
                {
                    Id    = ingredient.Id,
                    Name  = ingredient.Name,
                    Price = ingredient.Price
                };
            }
        }
        public ActionResult Delete(int id, lib.Ingredient formIngredient)
        {
            try
            {
                lib.Ingredient libIngredient = lib.Ingredient.GetById(formIngredient.Id);
                lib.Ingredient.Ingredients.Remove(formIngredient);
                lib.Ingredient.Ingredients.Remove(libIngredient);
                ingredientRepo.Delete(db.Mapper.Map(libIngredient));
                ingredientRepo.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(lib.Ingredient formIngredient)
        {
            try
            {
                lib.Ingredient libIngredient = new lib.Ingredient
                {
                    Name  = formIngredient.Name,
                    Price = formIngredient.Price
                };
                lib.Ingredient.Ingredients.Remove(formIngredient);
                ingredientRepo.Create(db.Mapper.Map(libIngredient));
                ingredientRepo.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }