Пример #1
0
        private static ProductFamilly CreateProductFamily(ApplicationDbContext context, ProductType type, string name, string imageName = null, bool canBeRemoved = true)
        {
            ProductFamilly family = context.ProductFamillys.FirstOrDefault(x => x.FamillyName == name);

            if (family == null)
            {
                family = new ProductFamilly(type, name);
                family.CanBeRemoved = canBeRemoved;
                if (imageName != null)
                {
                    family.Image = Path.Combine(Configurations.ProductsTypeAndFamillyIconsStockagesPath, imageName);
                }
                context.ProductFamillys.Add(family);
            }
            return(family);
        }
        public IActionResult CreateFamily(Guid categoryId, string familyName)
        {
            if (!AuthorizedWebAdmin())
            {
                return(Unauthorized());
            }
            var productCategory = _context.ProductTypes.FirstOrDefault(x => x.Id == categoryId);

            if (productCategory == null)
            {
                return(StatusCode(400));
            }
            var productFamily = new ProductFamilly(productCategory, familyName);

            _context.ProductFamillys.Add(productFamily);
            _context.SaveChanges();
            return(Ok());
        }