Ejemplo n.º 1
0
        private IngredientDomModel ConvertToDomModel(Guid id, IngredientBindingModel model)
        {
            var result = new IngredientDomModel
            {
                Id       = id,
                Name     = model.Name,
                Quantity = model.Quantity
            };

            return(result);
        }
Ejemplo n.º 2
0
        private ICollection <IngredientDomModel> IngredientToDom(ICollection <IngredientForRecipe> ingredients)
        {
            var ingredientModels = new List <IngredientDomModel>();

            foreach (var i in ingredients)
            {
                var ingredient = new IngredientDomModel
                {
                    Id       = i.IngredientId,
                    Name     = i.Ingredient.Name,
                    Quantity = i.RequiredAmmount
                };

                ingredientModels.Add(ingredient);
            }
            return(ingredientModels);
        }
Ejemplo n.º 3
0
        public ActionResult Edit(Guid id, IngredientBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", "Ingredient", id));
            }
            try
            {
                IngredientDomModel ingredient = this.ConvertToDomModel(id, model);
                this.manager.Edit(ingredient);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Error", e.Message);
                return(View());
            }
        }
Ejemplo n.º 4
0
        public ActionResult Create(IngredientBindingModel model)           //IFormCollection collection
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            try
            {
                var ingredientDomModel = new IngredientDomModel
                {
                    Name     = model.Name,
                    Quantity = model.Quantity
                };

                var result = this.manager.Add(ingredientDomModel);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Error", e.Message);
                return(View());
            }
        }
Ejemplo n.º 5
0
 public IngredientViewModel(IngredientDomModel ingredient)
 {
     this.Name     = ingredient.Name;
     this.Id       = ingredient.Id.ToString();
     this.Quantity = ingredient.Quantity;
 }
Ejemplo n.º 6
0
 public RecipeIngredientBindingModel(IngredientDomModel ingredient)
 {
     this.Name     = ingredient.Name;
     this.Id       = ingredient.Id.ToString();
     this.Quantity = ingredient.Quantity;
 }
Ejemplo n.º 7
0
 public RecipeIngredientViewModel(IngredientDomModel model)
 {
     this.Id       = model.Id.ToString();
     this.Name     = model.Name;
     this.Quantity = model.Quantity;
 }