Exemplo n.º 1
0
        public Alocacao Salvar(Alocacao alocacao)
        {
            if (alocacao == null)
            {
                throw new NullReferenceException($"Alocação inválida!");
            }

            var state = alocacao.HasId ? EntityState.Modified : EntityState.Added;

            _context.Entry(alocacao).State = state;
            _context.SaveChanges();
            return(alocacao);
        }
Exemplo n.º 2
0
        public virtual T Salvar(T entity)
        {
            if (entity == null || typeof(T) !is IDefaultCrudEntity)
            {
                throw new NullReferenceException($"{typeof(T).Name} inválida(o)!");
            }

            var defaultCrudIdentity = (IDefaultCrudEntity)entity;
            var state = defaultCrudIdentity.HasId ? EntityState.Modified : EntityState.Added;

            _context.Entry(entity).State = state;
            _context.SaveChanges();
            return(entity);
        }