Ejemplo n.º 1
0
        public async Task <ActionResult <Category> > PostCategory(
            [FromBody] Category category,
            [FromServices] DataContextShopDTO dataContext)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                _context.Categories.Add(category);
                await _context.SaveChangesAsync();

                return(Ok(category));
            }
            catch
            {
                return(BadRequest(new { message = "Não foi possível criar a categoria." }));
            }
        }
Ejemplo n.º 2
0
 public UserController([FromServices] DataContextShopDTO context)
 {
     _context = context;
 }
Ejemplo n.º 3
0
 public CategoryController([FromServices] DataContextShopDTO context)
 {
     _context = context;
 }
 public ProductController([FromServices] DataContextShopDTO context)
 {
     _context = context;
 }