Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(BrewsViewModel brew)
        {
            if (!ModelState.IsValid && !ValidateBrew(brew))
            {
                brew.IsValid = false;
                return(View(brew));
            }
            else
            {
                BrewModel updatedBrew = brewService.Update(mapper.BrewsViewModelToBrew(brew));
                if (updatedBrew == null)
                {
                    NotFound();
                }
                else
                {
                    await recipeService.AddOrUpdateAsync(brew.Recipes, brew.BrewId);
                }

                brew.IsValid = true;
            }

            if (brew.IsValid.Value)
            {
                return(RedirectToAction(RoutingConstants.BrewsManagementIndex));
            }
            else
            {
                return(View(brew));
            }
        }