public void SaveOrUpdateEntitiesList(IList <T> pLstObjEntity) { if (pLstObjEntity != null && pLstObjEntity.Count > 0) { foreach (var lObjEntity in pLstObjEntity) { if (lObjEntity.Id == 0) { lObjEntity.Status = GetStatus(lObjEntity); lObjEntity.ChangeStatus = ChangeStatusEnum.AUTHORIZED; lObjEntity.CreationDate = DateTime.Now; lObjEntity.ModificationDate = DateTime.Now; mLstObjSet.AddObject(lObjEntity); SaveChange(ChangeTypeEnum.INSERT, lObjEntity); } else { T lObjCurrentEntity = GetEntity(lObjEntity.Id); if (lObjCurrentEntity != null) { if (lObjCurrentEntity.Protected == false) { lObjEntity.Status = GetStatus(lObjEntity); lObjEntity.ChangeStatus = ChangeStatusEnum.AUTHORIZED; lObjEntity.CreationDate = lObjCurrentEntity.CreationDate; lObjEntity.ModificationDate = DateTime.Now; mObjContext.Entry(lObjCurrentEntity).CurrentValues.SetValues(lObjEntity); SaveChange(ChangeTypeEnum.UPDATE, lObjEntity); } else { throw new Exception("Registro protegido contra escritura."); } } } } SaveChanges(); } }
/// <summary> /// Atualiza item 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 atualizada</param> public void Edit(TEntity entity) { Context.Entry <TEntity>(entity).State = System.Data.Entity.EntityState.Modified; }