示例#1
0
 public IList <TModel> Lista()
 {
     using (var context = new TcUnipContext())
     {
         var modelo = context.Set <TRespository>().ToList();
         return(Mapper.Map <IList <TRespository>, IList <TModel> >(modelo));
     }
 }
示例#2
0
        public TModel Salvar(TRespository modelBD)
        {
            using (var context = new TcUnipContext())
            {
                context.Set <TRespository>().Add(modelBD);
                context.SaveChanges();

                return(Mapper.Map <TRespository, TModel>(modelBD));
            }
        }
示例#3
0
        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));
            }
        }
示例#4
0
        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);
        }
示例#5
0
 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);
     }
 }