Beispiel #1
0
        public ActionResult Edit(RecipeViewModel model)
        {
            List <IngredientLink>    ingredients = new List <IngredientLink>();
            IngredientLinkRepository ingredientLinkRepository = new IngredientLinkRepository();
            ChefRepository           chefRepository           = new ChefRepository();

            foreach (int id in model.IngredientIds)
            {
                ingredients.Add(new IngredientLink
                {
                    RecipeID     = model.ID,
                    IngredientID = id
                });
            }

            Recipe recipe = repo.GetByID(model.ID);

            if (model.ID == 0)
            {
                recipe    = new Recipe();
                recipe.ID = 0;
            }


            recipe.Name        = model.Name;
            recipe.ChefID      = model.ChefID;
            recipe.Description = model.Description;
            recipe.Ingredients = ingredients;

            repo.Save(recipe);

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public JsonResult Create(ChefModel model)
        {
            var repo = new ChefRepository();

            repo.Create(model.ToDomain());
            return(new JsonResult
            {
                Data = new { IsOk = true }
            });
        }
Beispiel #3
0
        public ChefService()
        {
            _chefRepository = new ChefRepository();

            var mapperConfig = new MapperConfiguration(cfg =>
            {
                var map = cfg.CreateMap <UserModel, User>().ReverseMap();
                cfg.CreateMap <ChefModel, Chef>().ReverseMap();
                cfg.CreateMap <CateringOrderModel, CateringOrder>().ReverseMap();
            });

            _mapper = new Mapper(mapperConfig);
        }
Beispiel #4
0
        public ActionResult Edit(int id = 0)
        {
            RecipeViewModel model = new RecipeViewModel();

            if (id != 0)
            {
                model = new RecipeViewModel(repo.GetByID(id));
            }

            ChefRepository chefRepo = new ChefRepository();
            SelectList     chefList = new SelectList(chefRepo.GetAll(), "ID", "Name");

            ViewBag.chefList = chefList;

            IngredientRepository ingredientRepo = new IngredientRepository();
            SelectList           ingredientList = new SelectList(ingredientRepo.GetAll(), "ID", "Name");

            ViewBag.ingredientList = ingredientList;

            return(View(model));
        }