public async Task <IActionResult> Create() { var categories = await this.productsServices.GetAllCategoryNamesAsync(); var model = new InsertCharacteristicsViewModel { Categories = categories.ToList() }; return(View(model)); }
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); }
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")); }
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}" })); }
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(); }