コード例 #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));
        }
コード例 #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);
 }
コード例 #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));
        }
コード例 #4
0
        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));
        }
コード例 #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));
        }
コード例 #6
0
        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));
        }
コード例 #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);
        }