public async Task <CategoryDetailsViewModel> CreateAsync(CategoryCreateInputModel categoryCreateInputModel) { var category = new Category { Name = categoryCreateInputModel.Name, Description = categoryCreateInputModel.Description, }; bool doesCategoryExist = await this.categoriesRepository .All() .AnyAsync(c => c.Name == category.Name); if (doesCategoryExist) { throw new ArgumentException( string.Format(ExceptionMessages.CategoryAlreadyExists, category.Name)); } await this.categoriesRepository.AddAsync(category); await this.categoriesRepository.SaveChangesAsync(); var viewModel = await this.GetViewModelByIdAsync <CategoryDetailsViewModel>(category.Id); return(viewModel); }
public IActionResult Create(CategoryCreateInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } this.categoryService.Create(inputModel.Name, inputModel.Description); return(this.Redirect(nameof(All))); }
public async Task <IActionResult> Create(CategoryCreateInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.categoryService.CreateAsync(input.Name, input.WareHouseId); return(this.RedirectToAction(RedirectIndex, RedirectWareHouse)); }
public async Task <IActionResult> Create(CategoryCreateInputModel categoryCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(categoryCreateInputModel)); } await this.categoriesService.CreateAsync(categoryCreateInputModel); return(this.RedirectToAction("GetAll", "Categories", new { area = "Administration" })); }
public async Task CreateCategoryAsync(CategoryCreateInputModel inputModel) { var category = new Category() { Title = inputModel.Title, Description = inputModel.Description, }; await this.categoryRepository.AddAsync(category); await this.categoryRepository.SaveChangesAsync(); }
public async Task <IActionResult> Create(CategoryCreateInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var categoryId = await this.categoriesService.CreateAsync(input.Name, input.Title, input.Description, input.ImageUrl); this.TempData["InfoMessage"] = "The category is created!"; return(this.RedirectToAction("Index", "Forums")); }
public async Task TestAddingCategory() { var model = new CategoryCreateInputModel { Name = "Lenses", Description = "Different lenses for your cameras", }; await this.categoriesService.CreateAsync(model); var count = await this.categoriesRepository.All().CountAsync(); Assert.Equal(1, count); }
public async Task CheckIfAddingCategoryThrowsArgumentException() { this.SeedDatabase(); var category = new CategoryCreateInputModel { Name = this.firstCategory.Name, Description = this.firstCategory.Description, }; var exception = await Assert .ThrowsAsync<ArgumentException>(async () => await this.categoriesService.CreateAsync(category)); Assert.Equal(string.Format(ExceptionMessages.CategoryAlreadyExists, category.Name), exception.Message); }
public async Task TestAddingCategory() { var model = new CategoryCreateInputModel { Name = "Wips", Description = "Some description...", }; await this.categoriesService.CreateAsync(model); var count = await this.categoriesRepository.All().CountAsync(); Assert.Equal(1, count); }
public async Task CheckSettingOfCategoryProperties() { var model = new CategoryCreateInputModel { Name = "Tripods", Description = "Different tripods and more", }; await this.categoriesService.CreateAsync(model); var cateogry = await this.categoriesRepository.All().FirstOrDefaultAsync(); Assert.Equal("Tripods", cateogry.Name); Assert.Equal("Different tripods and more", cateogry.Description); }
public async Task <IActionResult> Create(CategoryCreateInputModel createInputModel) { if (!this.ModelState.IsValid) { this.ViewData["mainCategories"] = this.mainCategoryService .GetAllMainCategories() .To <CreateCategoryMainCategoryViewModel>(); return(this.View()); } await this.categoryService.CreateCategoryAsync(createInputModel.To <CategoryServiceModel>()); return(this.Redirect("All")); }
public async Task CheckIfAddingCategoryReturnsViewModel() { var brand = new CategoryCreateInputModel { Name = "Filters", Description = "Different filters for lenses", }; var viewModel = await this.categoriesService.CreateAsync(brand); var dbEntry = await this.categoriesRepository.All().FirstOrDefaultAsync(); Assert.Equal(dbEntry.Id, viewModel.Id); Assert.Equal(dbEntry.Name, viewModel.Name); Assert.Equal(dbEntry.Description, viewModel.Description); }
public async Task <IActionResult> Add(CategoryCreateInputModel categoryCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(categoryCreateInputModel)); } if (!await this.categoryService.CreateCategoryAsync(categoryCreateInputModel.Name)) { this.TempData["Error"] = ValidationMessages.CategoryUniqieNameErrorMessage; return(this.View()); } return(this.RedirectToAction("All")); }
public async Task <Category> CreateAsync(CategoryCreateInputModel categoryCreateInputModel) { var category = Mapper.Map <Category>(categoryCreateInputModel); category.IsDeleted = false; var lastCategoryOrder = this.db.Categories.OrderByDescending(c => c.Order).FirstOrDefault()?.Order ?? 0; category.Order = lastCategoryOrder + 1; await this.db.Categories.AddAsync(category); await this.db.SaveChangesAsync(); return(category); }
public async Task <IActionResult> Create(CategoryCreateInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } if (await this.categoriesService.CategoryExistsByName(inputModel.Title)) { this.ModelState.AddModelError(inputModel.Title, $"Title - {inputModel.Title} already exists"); return(this.View(inputModel)); } await this.categoriesService.CreateCategoryAsync(inputModel); return(this.RedirectToAction(nameof(this.Active))); }
public async Task <IActionResult> Add(CategoryCreateInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var categoryId = await this.categoriesService.CreateAsync(input.Name, input.Description); if (categoryId == -1) { this.ModelState.AddModelError("Name", "Category already exists"); return(this.View(input)); } return(this.Redirect("/Categories/All")); }
public async Task <IActionResult> Create(CategoryCreateInputModel categoryCreateInputModel) { if (!this.ModelState.IsValid) { this.SetAlertMessage(AlertMessageLevel.Error, this.GetModelStateErrorMessages()); return(RedirectToAction(nameof(Index))); } var createdCategory = await this.categoryService .CreateAsync(categoryCreateInputModel); var message = $"Категорията \"{createdCategory.Name}\" беше добавена успешно."; this.logger.LogInformation((int)LoggingEvents.InsertItem, message); this.SetAlertMessage(AlertMessageLevel.Success, message); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(CategoryCreateInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } var categoryId = await this.categoriesService.CreateAsync( inputModel.CategoryName, inputModel.Description); if (categoryId == null) { return(this.RedirectToAction("Error", "Home")); } this.TempData[Key] = SuccessfullyCreatedCategory; return(this.RedirectToAction(nameof(this.All), new { id = categoryId })); }
public async Task <IActionResult> Create(CategoryCreateInputModel categoryCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(categoryCreateInputModel)); } var categoryServiceModel = categoryCreateInputModel.To <CategoryServiceModel>(); if (!await this.categoryService.CreateAsync(categoryServiceModel)) { this.TempData["Error"] = CreateErrorMessage; return(this.View()); } var categoryId = await this.categoryService.GetIdByTitleAsync(categoryServiceModel.Title); return(this.Redirect($"/Categories/Recipes/{categoryId}")); }
public async Task <IActionResult> Create(CategoryCreateInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } var categoryId = await this.categoriesService.CreateAsync(inputModel.Name, inputModel.Description); if (categoryId == 0) { this.ModelState.AddModelError( nameof(inputModel.Name), string.Format(GlobalConstants.CategoryNameAlreadyExistsErrorMessage, inputModel.Name)); } if (!this.ModelState.IsValid) { return(this.View(inputModel)); } this.TempData["InfoMessage"] = "Category created successfully!"; return(this.RedirectToAction(nameof(this.Index))); }
public Task <int> CreateAsync(CategoryCreateInputModel input, string userId) { throw new NotImplementedException(); }
public IActionResult Create() { var viewModel = new CategoryCreateInputModel(); return(this.View(viewModel)); }