Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Variety variety)
        {
            if (ModelState.IsValid)
            {
                _context.Add(variety);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(variety));
        }
        public async Task <IActionResult> Create([Bind("Id,Unit,Quantity")] Amount amount)
        {
            if (ModelState.IsValid)
            {
                _context.Add(amount);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(amount));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,RecipeCategory")] Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipe));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id")] RecipeIngredient recipeIngredient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipeIngredient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipeIngredient));
        }
Esempio n. 5
0
        public async Task CreateTag(Tag tag)
        {
            var tagExists = await _recipeDb.Tags
                            .AnyAsync(t => t.Value.Equals(tag.Value, StringComparison.OrdinalIgnoreCase));

            if (tagExists)
            {
                throw new ArgumentException("Tag already exists.");
            }

            _recipeDb.Attach <Tag>(tag);
            await _recipeDb.SaveChangesAsync();
        }
Esempio n. 6
0
        public async Task CreateRecipe(Recipe recipe)
        {
            _recipeDb.Attach <Recipe>(recipe);

            await _recipeDb.SaveChangesAsync();
        }