// POST: api/Resource
        //[ResponseType(typeof(TEntity))]
        public virtual async System.Threading.Tasks.Task <System.Web.Http.IHttpActionResult> Post(TEntity resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _dbSet.Add(resource);
            await Database.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = GetIdentifier(resource) }, resource));
        }
Exemple #2
0
 /// <summary>
 /// Adiciona item no banco utilizando o contexto do entity framework. Necessário utilizar o método Commit para confirmar a transação.
 /// </summary>
 /// <param name="entity">Entidade a ser adicionada</param>
 /// <returns></returns>
 public TEntity Add(TEntity entity)
 {
     return(DbSet.Add(entity));
 }
 public void Add(T entry)
 {
     _dbSet.Add(entry);
 }
Exemple #4
0
 public virtual void Add(T model)
 {
     _dbset.Add(model);
 }
 public virtual void Insert(TEntity entity)
 {
     _entitySet.Add(entity);
 }
Exemple #6
0
 public void Insert(T t)
 {
     dbSet.Add(t);
 }
Exemple #7
0
 //增
 #region 1.0 新增实体,返回受影响的行数 +  int Add(TEntity model)
 /// <summary>
 /// 1.0 新增实体,返回受影响的行数
 /// </summary>
 /// <param name="model"></param>
 /// <returns>返回受影响的行数</returns>
 public int Add(TEntity model)
 {
     entities.Add(model);
     //保存成功后,会将自增的id设置给model的主键属性,并返回受影响的行数。
     return(dbContext.SaveChanges());
 }
Exemple #8
0
 public void Insert(TEntity item)
 {
     _dbSet.Add(item);
     _dbContext.SaveChanges();
 }