コード例 #1
0
        public async Task <IActionResult> Create()
        {
            var categories = await this.productsServices.GetAllCategoryNamesAsync();

            var model = new InsertCharacteristicsViewModel {
                Categories = categories.ToList()
            };

            return(View(model));
        }
コード例 #2
0
        public async Task TestIfCreateCharacteristicsWorksAccordingly()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var characteristicsService = new Areas.Administration.Services.AdminCharacteristicsServices(context);



            var categoryForm = new InsertCharacteristicsCategoryViewModel();

            categoryForm.CategoryName = "Laptops";

            await characteristicsService.CreateCharacteristicsCategoryAsync(categoryForm);

            var form = new InsertCharacteristicsViewModel();

            form.BasicCharacteristics.AddRange(new List <string>
            {
                "Acer",
                "Lenovo",
                "Dell",
                "Ombre",
            });

            form.Category = "Laptops";

            form.FullCharacteristics.AddRange(new List <string>
            {
                "Acer",
                "Lenovo",
                "Dell",
                "Ombre",
            });

            await characteristicsService.CreateCharacteristicsAsync(form);


            var result = await context.AdminCharacteristicsCategories.FirstOrDefaultAsync(x => x.CategoryName == form.Category);

            Assert.NotEmpty(result.FullCharacteristics);
            Assert.NotEmpty(result.BasicCharacteristics);
        }
コード例 #3
0
        public async Task TestIfCharacteristicsExistsWorksAccordingly()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var characteristicsService = new Areas.Administration.Services.AdminCharacteristicsServices(context);



            var categoryForm = new InsertCharacteristicsCategoryViewModel();

            categoryForm.CategoryName = "Laptops";

            await characteristicsService.CreateCharacteristicsCategoryAsync(categoryForm);

            var form = new InsertCharacteristicsViewModel();

            form.BasicCharacteristics.AddRange(new List <string>
            {
                "Acer",
                "Lenovo",
                "Dell",
                "Ombre",
            });

            form.Category = "Laptops";

            form.FullCharacteristics.AddRange(new List <string>
            {
                "Acer",
                "Lenovo",
                "Dell",
                "Ombre",
            });

            await characteristicsService.CreateCharacteristicsAsync(form);


            Assert.True(await characteristicsService.CharacteristicsExistsAsync("Laptops"));
        }
コード例 #4
0
        public async Task <IActionResult> Create(InsertCharacteristicsViewModel form)
        {
            var categories = await this.productsServices.GetAllCategoryNamesAsync();

            if (!categories.Contains(form.Category))
            {
                this.ModelState.AddModelError("Category", "Invalid Category Name");
            }
            if (await this.characteristicsServices.CharacteristicsExistsAsync(form.Category))
            {
                this.ModelState.AddModelError("Characteristics", "Characteristcs Already Exist Only One Characteristc per Category");
            }
            if (!this.ModelState.IsValid)
            {
                form.Categories = categories.ToList();
                return(View(form));
            }

            await this.characteristicsServices.CreateCharacteristicsAsync(form);

            return(this.RedirectToAction("Success", "Blacksmith", new { message = $"Successfully Create Characteristics for category {form.Category}" }));
        }
コード例 #5
0
        public async Task CreateCharacteristicsAsync(InsertCharacteristicsViewModel form)
        {
            var category = await this.context.AdminCharacteristicsCategories.FirstOrDefaultAsync(x => x.CategoryName == form.Category);

            foreach (var bc in form.BasicCharacteristics.Where(x => !string.IsNullOrEmpty(x)))
            {
                category.BasicCharacteristics.Add(new AdminCharacteristic
                {
                    Name = bc
                });
            }

            foreach (var fc in form.FullCharacteristics.Where(x => !string.IsNullOrEmpty(x)))
            {
                category.FullCharacteristics.Add(new AdminCharacteristic
                {
                    Name = fc
                });
            }

            await this.context.SaveChangesAsync();
        }