Exemplo n.º 1
0
        // GET: Recipes/Create
        public ActionResult Create()
        {
            var vm = new RecipesCreateViewModel
            {
                TypeOfDisches = db.Typeofdish.Select
                                    (x =>
                                    new SelectListItem
                {
                    Value = x.TypeofdishID.ToString(),
                    Text  = x.Type
                }
                                    ),

                TypeOfMeals = db.Typeofmeal.Select
                                  (x =>
                                  new SelectListItem
                {
                    Value = x.TypeofmealID.ToString(),
                    Text  = x.Mealstype
                }
                                  ),

                Equipment = db.Equipment.Select
                                (x =>
                                new SelectListItem
                {
                    Value = x.EquipmentV2ID.ToString(),
                    Text  = x.Equipmentname
                }
                                )
            };

            ViewBag.UserID = new SelectList(db.Users, "Id", "Email");
            return(View(vm));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create([Bind(Include = "RecipeName,Ingredients,Instructions,IsPublic,CookBookName,UploadedFile,Description")] RecipesCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await new RecipeHandler()
                .CreateAndSaveRecipe(viewModel, new CurrentUserIdRetriever().GetUserId(User.Identity as ClaimsIdentity));
                return(RedirectToAction("Index", "CookBooks"));
            }

            return(View(viewModel));
        }
Exemplo n.º 3
0
 public Recipe(RecipesCreateViewModel viewModel, string ownerId, CookBook cookBook)
 {
     RecipeName   = viewModel.RecipeName;
     Ingredients  = viewModel.Ingredients;
     Instructions = viewModel.Instructions;
     IsPublic     = viewModel.IsPublic;
     OwnerId      = ownerId;
     CookBooksContainingRecipe.Add(cookBook);
     ImageReference = viewModel.ImageReference;
     Description    = viewModel.Description;
 }
Exemplo n.º 4
0
        internal async Task <int> CreateAndSaveRecipe(RecipesCreateViewModel viewModel, string userId)
        {
            HttpPostedFileBase file = viewModel.UploadedFile;

            if (UploadedFileExists(file))
            {
                if (IsImage(file))
                {
                    viewModel.ImageReference = new ImageHandler().SaveInitialImageAndGetReference(viewModel.UploadedFile);
                }
            }
            CookBook selectedCookBook = new CookBookRetriever()
                                        .GetUserCookBookByName(userId, viewModel.CookBookName);
            Recipe recipe = new Recipe(viewModel, userId, selectedCookBook);

            repository.AttachCookBookAndAddRecipe(selectedCookBook, recipe);
            return(await repository.SaveChangesAsync());
        }