Esempio n. 1
0
        public async Task <IActionResult> Create(
            [Bind("Id,LibraryId,Name,MixTypeId,Instructions,Source")] Recipe recipe,
            RecipeViewModel recipeVM)
        {
            if (ModelState.IsValid)
            {
                recipe.Id = Guid.NewGuid();
                _context.Add(recipe);
                await _context.SaveChangesAsync();

                foreach (var ingredientVM in recipeVM.IngredientViewModels)
                {
                    var ingredient = new Ingredient
                    {
                        Id          = Guid.NewGuid(),
                        RecipeId    = recipe.Id,
                        ComponentId = ingredientVM.ComponentId,
                        Quantity    = ingredientVM.Quantity,
                        UnitId      = ingredientVM.UnitId,
                        Number      = ingredientVM.Number
                    };
                    _context.Add(ingredient);
                }
                await _context.SaveChangesAsync();

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(componentType));
        }
        public async Task <IActionResult> Create([Bind("Id,RecipeId,ComponentId,Quantity,UnitId,Number")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                ingredient.Id = Guid.NewGuid();
                _context.Add(ingredient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ingredient));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("Id,ComponentTypeId,Name,Description")] Component component)
        {
            if (ModelState.IsValid)
            {
                component.Id = Guid.NewGuid();
                _context.Add(component);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(component));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Library library)
        {
            if (ModelState.IsValid)
            {
                library.Id = Guid.NewGuid();
                _context.Add(library);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(library));
        }
Esempio n. 7
0
        public async Task GetFlavorWithCorrectId()
        {
            var id     = Guid.NewGuid();
            var flavor = new Flavor {
                Id = id, Name = "flavor"
            };

            CocktailsContext.Add(flavor);
            CocktailsContext.SaveChanges();

            var result = await _repository.GetSingleAsync(x => x.Where(y => y.Id == id), _token);

            Assert.IsNotNull(result);
            Assert.AreEqual(flavor.Id, result.Id);
            Assert.AreEqual(flavor.Name, result.Name);
        }