コード例 #1
0
 public int Contar(Expression <Func <T, bool> > where)
 {
     using (var db = new AplicacionDbContext())
     {
         return(db.Set <T>().Where(where).Count());
     }
 }
コード例 #2
0
        public JsonResult BuscaPersonas(string term)
        {
            AplicacionDbContext db = new AplicacionDbContext();
            var resultado          = db.Personas.Where(x => x.Nombre.Contains(term)).ToList();

            return(Json(resultado, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult Index()
        {
            AplicacionDbContext db = new AplicacionDbContext();

            ////var persona1 = new Persona() { Nombre = "Edwin", Edad = 29 };
            ////var persona2 = new Persona() { Nombre = "Omar", Edad = 26 };
            //var persona3 = new Persona() { Nombre = "Frankely", Edad = 21 };
            //var persona4 = new Persona() { Nombre = "Rossi", Edad = 28 };
            //var persona6 = new Persona() {Id=6, Nombre = "Deivi", Edad = 29 };
            ////var persona2 = db.Personas.Where(x => x.Id == 2).FirstOrDefault();
            //db.Personas.Add(persona3);
            //db.Personas.Add(persona4);
            //db.Personas.Add(persona5);
            //db.SaveChanges();

            //var detalle6 = new DetallePersona() { Peso = 150, Altura = 5.8,Sexo="Femenino",Persona=persona6};
            ////var detalle4 = new DetallePersona() { Peso = 160, Altura = 5.8,Sexo="Masculino", Persona = persona4 };
            ////var detalle5 = new DetallePersona() { Peso = 170, Altura = 5.11, Sexo = "Masculino", Persona = persona5 };
            ////db.DetallePersonas.Add(detalle3);
            ////db.DetallePersonas.Add(detalle4);
            //db.DetallePersonas.Add(detalle6);
            //db.SaveChanges();
            //var personas = db.Personas.Include("Detalle").ToList();
            return(View());
        }
コード例 #4
0
        public PartialViewResult CargarSeccion()
        {
            AplicacionDbContext db = new AplicacionDbContext();

            var personas = db.Personas.Include("Detalle").ToList();

            return(PartialView("_Prueba", personas));
        }
コード例 #5
0
        public PartialViewResult DetallePersona(int PersonaId)
        {
            AplicacionDbContext db = new AplicacionDbContext();
            var PersonaDetalles    = db.DetallePersonas.Where(x => x.PersonaId == PersonaId).FirstOrDefault();

            return(PartialView("_DetallePersona", PersonaDetalles));
            //return PartialView();
        }
コード例 #6
0
 public void Actualizar(T tabla)
 {
     using (var db = new AplicacionDbContext())
     {
         tabla.FechaModificacion = DateTime.Now;
         db.Entry(tabla).State   = EntityState.Modified;
         db.SaveChanges();
     }
 }
コード例 #7
0
 public void Agregar(T tabla)
 {
     using (var db = new AplicacionDbContext())
     {
         tabla.FechaCreacion   = DateTime.Now;
         db.Entry(tabla).State = System.Data.Entity.EntityState.Added;
         db.SaveChanges();
     }
 }
コード例 #8
0
 public JsonResult BusquedaRapida(string term)
 {
     using (AplicacionDbContext db = new AplicacionDbContext())
     {
         var resultado = db.localidades.Where(x => x.Nombre.Contains(term)).OrderBy(x => x.Nombre)
                         .Select(x => x.Nombre).Take(5).ToList();
         return(Json(resultado, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #9
0
        public T ObtenerPorId(int id, ParametrosDeQuery <T> parametrosDeQuery)
        {
            var include = (parametrosDeQuery.Include);

            using (var db = new AplicacionDbContext())
            {
                return(db.Set <T>().Include(include).FirstOrDefault(x => x.Id == id));
            }
        }
コード例 #10
0
 public void Eliminar(int id)
 {
     using (var db = new AplicacionDbContext())
     {
         var tabla = new T()
         {
             Id = id
         };
         db.Entry(tabla).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #11
0
        public IEnumerable <SelectListItem> ObtenerListado()
        {
            using (AplicacionDbContext db = new AplicacionDbContext())
            {
                List <SelectListItem> c_provincias = db.provincias.AsNoTracking()
                                                     .OrderBy(n => n.Nombre)
                                                     .Select(n =>
                                                             new SelectListItem
                {
                    Value = n.Id.ToString(),
                    Text  = n.Nombre
                }).ToList();

                //var nuevo = new SelectListItem()
                //{
                //    Value = null,
                //    Text = ""
                //};
                //c_provincias.Insert(0, nuevo);

                return(new SelectList(c_provincias, "Value", "Text"));
            }
        }
コード例 #12
0
        public IEnumerable <T> EncontrarPor(ParametrosDeQuery <T> parametrosDeQuery)
        {
            var orderByClass = ObtenerOrderBy(parametrosDeQuery);
            Expression <Func <T, bool> > whereTrue = x => true;

            var where = (parametrosDeQuery.Where == null) ? whereTrue : parametrosDeQuery.Where;
            var include = (parametrosDeQuery.Include);

            using (AplicacionDbContext db = new AplicacionDbContext())
            {
                if (orderByClass.IsAscending)
                {
                    return(db.Set <T>().Include(include).Where(where).OrderBy(orderByClass.OrderBy)
                           .Skip((parametrosDeQuery.Pagina - 1) * parametrosDeQuery.Top)
                           .Take(parametrosDeQuery.Top).ToList());
                }
                else
                {
                    return(db.Set <T>().Include(include).Where(where).OrderByDescending(orderByClass.OrderBy)
                           .Skip((parametrosDeQuery.Pagina - 1) * parametrosDeQuery.Top)
                           .Take(parametrosDeQuery.Top).ToList());
                }
            }
        }
コード例 #13
0
 public PersonaController(AplicacionDbContext contexto)
 {
     _context = contexto;
 }
コード例 #14
0
 public InventarioBicicletaRepository(AplicacionDbContext db) : base(db)
 {
 }
コード例 #15
0
 public ProductosRepositorio(AplicacionDbContext context)
 {
     this._contexto = context;
 }
コード例 #16
0
 public RegistroVentaRepository(AplicacionDbContext db) : base(db)
 {
 }
コード例 #17
0
 public InventarioRepositorio(AplicacionDbContext context)
 {
     this._contexto = context;
 }
コード例 #18
0
 public FacturasController(AplicacionDbContext context)
 {
     _context = context;
 }
コード例 #19
0
 public AutoesController(AplicacionDbContext context)
 {
     _context = context;
 }
コード例 #20
0
 public SexoController(AplicacionDbContext contexto)
 {
     _context = contexto;
 }
コード例 #21
0
        public static async Task InsertDatosEjemplo(AplicacionDbContext context)
        {
            if (!context.Bodegas.Any())
            {
                List <Bodega> bodegasDefault = new List <Bodega>
                {
                    new Bodega
                    {
                        Id              = Guid.Parse("40e05749-8b35-42c3-b68e-1232da850baf"),
                        Nombre          = "Bodega 1",
                        Descripcion     = "Bodega de prueba 1",
                        Ubicacion       = "Ubicacion 1",
                        CapacidadMaxima = 100
                    },
                    new Bodega
                    {
                        Id              = Guid.Parse("03d734ad-4bd8-444f-b9dd-d497d1fa3974"),
                        Nombre          = "Bodega 2",
                        Descripcion     = "Bodega de prueba 2",
                        Ubicacion       = "Ubicacion 1",
                        CapacidadMaxima = 150
                    },
                    new Bodega
                    {
                        Id              = Guid.Parse("460f54b0-0555-4ae5-a119-47cffd8b5d33"),
                        Nombre          = "Bodega 3",
                        Descripcion     = "Bodega de prueba 3",
                        Ubicacion       = "Ubicacion 2",
                        CapacidadMaxima = 200
                    }
                };
                context.Bodegas.AddRange(bodegasDefault);
            }

            if (!context.Productos.Any())
            {
                List <Producto> productosDefault = new List <Producto>
                {
                    new Producto
                    {
                        Id          = Guid.Parse("d73b1452-fc54-4920-a796-a10f25b48715"),
                        Nombre      = "Producto de prueba 1",
                        Descripcion = "Esto es un producto de prueba 1",
                        sku         = "PRO-PRU-1"
                    },
                    new Producto
                    {
                        Id          = Guid.Parse("9ae171ea-c81a-454c-8dd8-c5d0ca433f5c"),
                        Nombre      = "Producto de prueba 2",
                        Descripcion = "Esto es un producto de prueba 2",
                        sku         = "PRO-PRU-2"
                    },
                    new Producto
                    {
                        Id          = Guid.Parse("81eafc34-4146-468b-b830-30010ed840f6"),
                        Nombre      = "Producto de prueba 3",
                        Descripcion = "Esto es un producto de prueba 3",
                        sku         = "PRO-PRU-3"
                    }
                };
                context.Productos.AddRange(productosDefault);
            }

            await context.SaveChangesAsync();
        }
コード例 #22
0
 public ProgramadorController(AplicacionDbContext context)
 {
     _context = context;
 }
コード例 #23
0
 public TipoIdentificacionController(AplicacionDbContext contexto)
 {
     _context = contexto;
 }
コード例 #24
0
 public BodegaRepositorio(AplicacionDbContext context)
 {
     this._contexto = context;
 }
コード例 #25
0
 public ClienteRepository(AplicacionDbContext db) : base(db)
 {
 }
コード例 #26
0
 public LibroRepositorio(AplicacionDbContext db, IMapper mapper)
 {
     _db     = db;
     _mapper = mapper;
 }
コード例 #27
0
 public ClienteController(AplicacionDbContext context)
 {
     _context = context;
 }