public async Task <ActionResult <CategoryDTO> > PostCategory(CategoryDTO categoryDTO) { var category = CategoryDTO.FromDTO(categoryDTO); _context.Categories.Add(category); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCategory), new { id = category.Id }, CategoryDTO.ToDTO(category))); }
public async Task <ActionResult <CategoryDTO> > GetCategory(long id) { var category = await _context.Categories.FindAsync(id); if (category == null) { return(NotFound()); } return(CategoryDTO.ToDTO(category)); }
public async Task <ActionResult <IEnumerable <CategoryDTO> > > GetGategories() { return(await _context.Categories.Select(x => CategoryDTO.ToDTO(x)).ToListAsync()); }