public async Task <IActionResult> Create(BaseJobCategoryInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.baseJobCategoriesService.CreateAsync(inputModel); return(this.RedirectToAction(nameof(this.Index))); }
public async Task <int> CreateAsync(BaseJobCategoryInputModel inputModel) { var newBaseJobCategory = new BaseJobCategory { Description = inputModel.Description, CategoryName = inputModel.CategoryName, }; await this.baseJobCategoriesRepository.AddAsync(newBaseJobCategory); await this.baseJobCategoriesRepository.SaveChangesAsync(); return(newBaseJobCategory.Id); }
public async Task CreateAsync_ShouldCreateBaseCategoryProperly() { var inputModel = new BaseJobCategoryInputModel { CategoryName = "тест", Description = "Тествам теста", }; var newCategoryId = await this.service.CreateAsync(inputModel); var expectedId = 4; Assert.Equal(expectedId, newCategoryId); }
public async Task UpdateAsync(BaseJobCategoryInputModel inputModel) { var category = await this.baseJobCategoriesRepository.All().FirstOrDefaultAsync(x => x.Id == inputModel.Id); if (category == null) { throw new ArgumentNullException(); } category.Description = inputModel.Description; category.CategoryName = inputModel.CategoryName; this.baseJobCategoriesRepository.Update(category); await this.baseJobCategoriesRepository.SaveChangesAsync(); }
public async Task <IActionResult> Edit(BaseJobCategoryInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } try { await this.baseJobCategoriesService.UpdateAsync(inputModel); } catch (DbUpdateConcurrencyException) { return(this.CustomNotFound()); } return(this.RedirectToAction(nameof(this.Index))); }
public async Task UpdateAsync_ShouldWorkProperly() { AutoMapperConfig.RegisterMappings(typeof(SimpleBaseJobCategoryViewModel).Assembly); var model = new BaseJobCategoryInputModel { Id = 1, CategoryName = "Test", Description = "Making test here and there", }; await this.service.UpdateAsync(model); var updatedCategory = await this.service.GetBaseJobCategoryById <SimpleBaseJobCategoryViewModel>(1); var expectedId = 1; var expectedCategoryName = "Test"; var expectedDescription = "Making test here and there"; Assert.Equal(expectedId, updatedCategory.Id); Assert.Equal(expectedCategoryName, updatedCategory.CategoryName); Assert.Equal(expectedDescription, updatedCategory.Description); }
// GET: Administration/BaseJobCategories/Edit/5 public async Task <IActionResult> Edit(int id) { if (id == 0) { return(this.CustomNotFound()); } var baseJobCategory = await this.baseJobCategoriesService.GetBaseJobCategoryById <SingleBaseJobCategoryViewModel>(id); if (baseJobCategory == null) { return(this.CustomNotFound()); } var inputModel = new BaseJobCategoryInputModel { Id = baseJobCategory.Id, CategoryName = baseJobCategory.CategoryName, Description = baseJobCategory.Description, }; return(this.View(inputModel)); }