public async Task Create(CategoryListServiceModel model) { var category = Mapper.Map <CategoryListServiceModel, Category>(model); await appRepository.InsertAsync(category); await appRepository.UnitOfWork.CommitAsync(); }
public bool Edit(CategoryListServiceModel model) { var getCategory = Mapper.Map <CategoryListServiceModel, Category>(model); appRepository.Update(getCategory); appRepository.UnitOfWork.CommitAsync(); return(true); }
public async Task <IActionResult> Create(CategoryListServiceModel category) { if (ModelState.IsValid) { await categoryService.Create(category); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <CategoryListServiceModel> ById(int id) { var category = await appRepository.GetByIdAsync(id); var categoryDto = new CategoryListServiceModel(); if (category != null) { categoryDto = Mapper.Map <Category, CategoryListServiceModel>(category); return(categoryDto); } return(categoryDto); }
public async Task <IActionResult> Edit(int id, CategoryListServiceModel category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { try { categoryService.Edit(category); } catch (DbUpdateConcurrencyException) { } return(RedirectToAction(nameof(Index))); } return(View(category)); }