Exemplo n.º 1
0
        public async Task <int> Create(Category category)
        {
            try
            {
                category.Created = DateTime.Now;

                _context.Add(category);

                await _context.SaveChangesAsync();

                return(category.Id);
            }
            catch (DbUpdateException)
            {
                throw new Exception("Não foi possível criar a categoria. Tente novamente.");
            }
        }
Exemplo n.º 2
0
        public async Task <int> Create(Product Product)
        {
            try
            {
                Product.Created = DateTime.Now;

                _context.Add(Product);

                await _context.SaveChangesAsync();

                return(Product.Id);
            }
            catch (DbUpdateException)
            {
                throw new Exception("Não foi possível criar o produto. Tente novamente.");
            }
        }