public bool Excluir(TModel model)
 {
     using (var context = new AgdCtContext())
     {
         var modelo = Mapper.Map <TModel, TRespository>(model);
         Attach(context, modelo, EntityState.Deleted);
         return(context.SaveChanges() != 0);
     }
 }
        public bool Atualizar(TModel model)
        {
            using (var context = new AgdCtContext())
            {
                var modeloBD = Mapper.Map <TModel, TRespository>(model);
                Attach(context, modeloBD, EntityState.Modified);

                return(context.SaveChanges() != 0);
            }
        }
        public IList <TModel> SalvarLista(IList <TModel> listModel)
        {
            using (var context = new AgdCtContext())
            {
                var listaModelBD = Mapper.Map <IList <TModel>, IList <TRespository> >(listModel);
                context.Set <TRespository>().AddRange(listaModelBD);
                context.SaveChanges();

                return(Mapper.Map <IList <TRespository>, IList <TModel> >(listaModelBD));
            }
        }
        public TModel Salvar(TModel model)
        {
            using (var context = new AgdCtContext())
            {
                var modelBD = Mapper.Map <TModel, TRespository>(model);
                context.Set <TRespository>().Add(modelBD);
                context.SaveChanges();

                return(Mapper.Map <TRespository, TModel>(modelBD));
            }
        }
Exemplo n.º 5
0
        public bool Excluir(int id)
        {
            bool excluido = false;

            using (var context = new AgdCtContext())
            {
                var registro = context.Contato.Where(x => x.Id == id).FirstOrDefault();
                context.Contato.Remove(registro);
                excluido = context.SaveChanges() != 0;
            }

            return(excluido);
        }
 public bool Excluir(Expression <Func <TModel, bool> > expression)
 {
     using (var context = new AgdCtContext())
     {
         var modelo = context.Set <TRespository>().FirstOrDefault(GetMappedSelector(expression));
         if (modelo == null)
         {
             return(false);
         }
         Attach(context, modelo, EntityState.Deleted);
         return(context.SaveChanges() != 0);
     }
 }