Beispiel #1
0
 private Product AddjoiningTables(Product newProduct, ProductForCreationVm productVm)
 {
     newProduct.ProductIngredients  = new List <ProductIngredient>();
     newProduct.ProductAllergens    = new List <ProductAllergen>();
     newProduct.ProductDietInfoTags = new List <ProductDietInfoTag>();
     foreach (int item in productVm.IngredientsIds)
     {
         newProduct.ProductIngredients.Add(new ProductIngredient()
         {
             IngredientId = item,
         });
     }
     foreach (int item in productVm.AllergensIds)
     {
         newProduct.ProductAllergens.Add(new ProductAllergen()
         {
             AllergenId = item,
         });
     }
     ;
     foreach (int item in productVm.DietInfoIds)
     {
         newProduct.ProductDietInfoTags.Add(new ProductDietInfoTag()
         {
             DietInfoTagId = item,
         });
     }
     ;
     return(newProduct);
 }
        public IActionResult AddNewProduct(ProductForCreationVm product)
        {
            if (product.Btn == "Submit")
            {
                _productService.AddNewProduct(product);
            }

            return(RedirectToAction("index"));
        }
Beispiel #3
0
 private Product PrepareProductForSaving(ProductForCreationVm newProductVm)
 {
     newProductVm.Price = Helper.StringToDouble(newProductVm.PriceString);
     if (newProductVm.File != null)
     {
         newProductVm.ImagePath = SaveImageOnFile(newProductVm.File);
     }
     else
     {
         newProductVm.ImagePath = newProductVm.ImagePath.Substring(8);
     }
     return(AddjoiningTables(_mapper.Map <Product>(newProductVm), newProductVm));
 }
Beispiel #4
0
 public void AddNewProduct(ProductForCreationVm productVm)
 {
     _productRepository.AddNewProduct(PrepareProductForSaving(productVm));
 }