public IList <TModel> Lista() { using (var context = new TcUnipContext()) { var modelo = context.Set <TRespository>().ToList(); return(Mapper.Map <IList <TRespository>, IList <TModel> >(modelo)); } }
public TModel Salvar(TRespository modelBD) { using (var context = new TcUnipContext()) { context.Set <TRespository>().Add(modelBD); context.SaveChanges(); return(Mapper.Map <TRespository, TModel>(modelBD)); } }
public IList <TModel> SalvarLista(IList <TModel> listModel) { using (var context = new TcUnipContext()) { var listaModelBD = Mapper.Map <IList <TModel>, IList <TRespository> >(listModel); context.Set <TRespository>().AddRange(listaModelBD); context.SaveChanges(); return(Mapper.Map <IList <TRespository>, IList <TModel> >(listaModelBD)); } }
private void Attach(TcUnipContext context, TRespository entity, EntityState state) { var entry = context.Entry(entity); if (entry.State == EntityState.Detached) { context.Set <TRespository>().Attach(entity); } context.ChangeObjectState(entity, state); }
public bool Excluir(Expression <Func <TModel, bool> > expression) { using (var context = new TcUnipContext()) { var modelo = context.Set <TRespository>().FirstOrDefault(GetMappedSelector(expression)); if (modelo == null) { return(false); } Attach(context, modelo, EntityState.Deleted); return(context.SaveChanges() != 0); } }