public ActionResult <ProductTemplateDTO> GetProjectTemplate(long productTemplateId)
 {
     try
     {
         return(new ProductTemplateDTO(_productTemplates.GetById(productTemplateId)));
     }
     catch (ArgumentNullException)
     {
         return(NotFound(new CustomErrorDTO("Product concept niet gevonden")));
     }
 }
示例#2
0
        public void UpdateProductTemplates(long id, ICollection <ProductTemplateDTO> prts)
        {
            var project = _projectTemplates.GetById(id);

            foreach (var item in project.ProductTemplateProjectTemplates.ToList())
            {
                var productTemplateMatch = prts.FirstOrDefault(g => g.ProductTemplateId == item.ProductTemplateId);
                if (productTemplateMatch == null) // the product has been removed by the user
                {
                    project.RemoveProductTemplate(item);
                }
                else // the product is still present in both arrays so update the product
                {
                    item.ProductTemplate.ProductName  = productTemplateMatch.ProductName;
                    item.ProductTemplate.Description  = productTemplateMatch.Description;
                    item.ProductTemplate.ProductImage = productTemplateMatch.ProductImage;

                    item.ProductTemplate.CategoryTemplateId = productTemplateMatch.CategoryTemplateId;


                    item.ProductTemplate.UpdateVariations(productTemplateMatch.ProductVariationTemplates);
                }
            }

            foreach (var item in prts.ToList()) // adds products that have been added to this template
            {
                var productTemplateMatch = project.ProductTemplateProjectTemplates.FirstOrDefault(g => g.ProductTemplateId == item.ProductTemplateId);
                if (productTemplateMatch == null) // the product is just added
                {
                    project.AddProductTemplate(_productTemplates.GetById(item.ProductTemplateId));
                }
            }
        }
        public void InitProductTemplates(ICollection <ProductTemplateDTO> prts)
        {
            var project = currentTemplate;

            foreach (var item in prts.ToList()) // adds products that have been added to this template
            {
                project.AddProductTemplate(_productTemplateRepo.GetById(item.ProductTemplateId));
            }
        }