public async Task <ActionResult <CategoryBuyDto> > AddCategory([FromBody] CategoryBuy categoryBuy) { await _repository.AddCategoryAsync(categoryBuy); await _repository.CommitAsync(); return(CreatedAtAction(nameof(GetCategory), new { id = categoryBuy.CategoryId }, categoryBuy.Adapt <CategoryBuyDto>())); }
public async Task <CategoryBuyDto> UpdateCategoryAsync(CategoryBuy categoryBuy) { var category = await _context.Set <CategoryBuy>() .FirstOrDefaultAsync(c => c.CategoryId == categoryBuy.CategoryId); if (category != null) { category.CategoryName = categoryBuy.CategoryName; } return(category.Adapt <CategoryBuyDto>()); }
public async Task <ActionResult <CategoryBuyDto> > UpdateCategory([FromBody] CategoryBuy categoryBuy) { var category = await _repository.UpdateCategoryAsync(categoryBuy); if (category == null) { return(NotFound()); } await _repository.CommitAsync(); return(category); }
public async Task AddCategoryAsync(CategoryBuy categoryBuy) { await _context.Set <CategoryBuy>().AddAsync(categoryBuy); }