Пример #1
0
        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>()));
        }
Пример #2
0
        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>());
        }
Пример #3
0
        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);
        }
Пример #4
0
 public async Task AddCategoryAsync(CategoryBuy categoryBuy)
 {
     await _context.Set <CategoryBuy>().AddAsync(categoryBuy);
 }