public ServiceProduct(List <Product> products)
        {
            context       = new GpContext();
            this.products = products;

            /*FindProducts = delegate (string c)
             * {
             *  List<Product> list = new List<Product>();
             *  foreach (var p in products)
             *  {
             *      if (p.Name.StartsWith(c))
             *          list.Add(p);
             *  }
             *  return list;
             * };
             * ScanProducts = delegate (Category category)
             * {
             * List<Product> list = new List<Product>();
             * foreach (var p in products)
             * {
             *  if (p.Category.Name == category.Name)
             *      p.ToString();
             * }
             * };*/
        }
Example #2
0
 public UsuarioRepository()
 {
     Context = new GpContext();
 }
Example #3
0
        public void TestContext()
        {
            var target = new GpContext();
            {
                try
                {
                    // Your code...
                    // Could also be before try if you know the exception occurs in SaveChanges


                    /* var persona = new Persona();
                     * persona.FechaNacimiento = new DateTime();
                     */
                    var persona = new Persona {
                        FechaNacimiento = new DateTime(2000, 09, 01)
                    };
                    target.Personas.Add(persona);
                    target.SaveChanges();

                    var policia = new Policia {
                        NumeroPlaca = 5
                    };
                    target.Policias.Add(policia);
                    target.SaveChanges();

                    var detenido = new Detenido {
                        FechaDetencion = new DateTime(2000, 02, 01)
                    };
                    target.Detenidos.Add(detenido);
                    target.SaveChanges();

                    var usuario = new Usuario();
                    target.Usuarios.Add(usuario);
                    target.SaveChanges();

                    var dni = new Dni()
                    {
                        NumeroDocumento = "56904819"
                    };
                    target.Dnis.Add(dni);
                    target.SaveChanges();

                    var nie = new Nie()
                    {
                        NumeroDocumento = "Z5164919K"
                    };
                    target.Nies.Add(nie);
                    target.SaveChanges();

                    var pasaporte = new Pasaporte()
                    {
                        NumeroDocumento = "C35890664"
                    };
                    target.Pasaportes.Add(pasaporte);
                    target.SaveChanges();

                    var policias  = target.Policias.Count();
                    var policias2 = target.Personas.OfType <Policia>().Count();
                }

                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine(
                            "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }