public void Add(OneAttributeViewModel vm)
 {
     if (vm.Id == 0)
     {
         var newAttr = new OneAttribute
         {
             Name             = vm.Name,
             Description      = vm.Description,
             Type             = vm.Type,
             AttributeGroupId = vm.AttributeGroupId,
             AddedDate        = DateTime.Now,
             UpdatedDate      = DateTime.Now,
             Published        = false,
         };
         _ctx.OneAttributes.Add(newAttr);
     }
     _ctx.SaveChanges();
 }
 /// <summary>
 /// The implementation MUST accept its "source" attribute in its constructor.
 /// </summary>
 /// <param name="a"></param>
 public OneAttributeImpl(OneAttribute a)
 {
     _attribute = a ?? throw new ArgumentNullException(nameof(a));
 }
示例#3
0
        public static void FillIfEmpty(ApplicationDbContext ctx)
        {
            // The list variables created for the Seed():
            var categoryList                  = new List <Category>();
            var subCategoryList               = new List <SubCategory>();
            var productList                   = new List <Product>();
            var attributeGroupList            = new List <AttributeGroup>();
            var oneAttributeList              = new List <OneAttribute>();
            var subCategoryAttributeGroupList = new List <SubCategoryAttributeGroup>();

            // Attribute:
            var oneAttribute = new OneAttribute
            {
                Name        = "Color",
                Description = "The specific color of the product.",
                Type        = "string"
            };

            ctx.OneAttributes.Add(oneAttribute);
            ctx.SaveChanges();

            // AttributeGroup:
            var attributeGroup = new AttributeGroup
            {
                Name          = "Style",
                Description   = "The style of the product.",
                OneAttributes = oneAttributeList
            };

            ctx.AttributeGroups.Add(attributeGroup);
            ctx.SaveChanges();

            // Product:
            var product = new Product
            {
                Name           = "Ralph Lauren",
                Description    = "Slim fit, long sleeved shirt.",
                Price          = "999",
                UpdatedDate    = DateTime.Now.Date,
                AddedDate      = DateTime.Today,
                Published      = false,
                Version        = 1,
                ModifiedByUser = "******"
            };

            productList.Add(product);

            // SubCategory:
            var subCategory = new SubCategory
            {
                Name     = "Long sleeve",
                Products = productList,
                SubCategoryAttributeGroups = subCategoryAttributeGroupList,
                UpdatedDate    = DateTime.Now.Date,
                AddedDate      = DateTime.Today,
                Published      = false,
                Version        = 1,
                ModifiedByUser = "******"
            };

            subCategoryList.Add(subCategory);

            // SubCategoryAttributeGroups:
            var subCategoryAttributeGroups = new SubCategoryAttributeGroup
            {
                SubCategory    = ctx.SubCategories.FirstOrDefault(x => x.Id == 1),
                AttributeGroup = ctx.AttributeGroups.FirstOrDefault(x => x.Id == 1)
            };

            subCategoryAttributeGroupList.Add(subCategoryAttributeGroups);

            // Category:
            if (!ctx.Categories.Any())
            {
                var category = new Category
                {
                    Name           = "Shirts",
                    SubCategories  = subCategoryList,
                    UpdatedDate    = DateTime.Now.Date,
                    AddedDate      = DateTime.Now,
                    Published      = false,
                    Version        = 1,
                    ModifiedByUser = "******"
                };
                ctx.Categories.AddRange(category);
            }
            ;
            ctx.SaveChanges();

            // Connect a product to a attribute to productoneattributevalues:
            if (!ctx.ProductOneAttributeValues.Any())
            {
                var productTryout = ctx.Products.FirstOrDefault(x => x.Id == 1);

                var attributeTryout = ctx.OneAttributes.FirstOrDefault(x => x.Id == 1);

                var productAttributeValue = new ProductOneAttributeValue
                {
                    Value        = "White",
                    Product      = productTryout,
                    OneAttribute = attributeTryout
                };
                ctx.ProductOneAttributeValues.Add(productAttributeValue);
                ctx.SaveChanges();
            }
        }