示例#1
0
 public List <T> ListAll()
 {
     using (CriminalContext context = new CriminalContext())
     {
         return(context.Set <T>().ToList());
     }
 }
        public List <Criminal> Search(Criminal criterio)
        {
            using (CriminalContext context = new CriminalContext())
            {
                var query = from c in context.Criminal.Include("SexType").Include("Adress").Include("Adress.City").Include("Adress.City.State").Include("Adress.City.State.Country")
                            where c.Name.Contains(criterio.Name) ||
                            c.Adress.Street.Contains(criterio.Adress.Street)
                            select c;

                return(query.ToList());
            }
        }
        public List <Criminal> Search(string searchTerm)
        {
            using (CriminalContext context = new CriminalContext())
            {
                var query = from c in context.Criminal.Include("CrimesHistory").Include("CrimesHistory.Adress").Include("CrimesHistory.Adress.City").Include("CrimesHistory.Adress.City.State").Include("CrimesHistory.Adress.City.State.Country").Include("SexType").Include("Adress").Include("Adress.City").Include("Adress.City.State").Include("Adress.City.State.Country")
                            where c.Name.Contains(searchTerm) ||
                            c.Adress.Street.Contains(searchTerm) ||
                            (c.Adress.Number != null && c.Adress.Number.Value.ToString().Contains(searchTerm))
                            select c;

                return(query.ToList());
            }
        }
示例#4
0
 public T Get(ID id)
 {
     try
     {
         using (CriminalContext context = new CriminalContext())
         {
             return(context.Set <T>().Find(id));
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, ex.Message, null);
         return(null);
     }
 }
        public List <Criminal> CustomSearch(string searchTerm, string name, int?ageStart, int?ageEnd, int?idSex, int?idCountry)
        {
            using (CriminalContext context = new CriminalContext())
            {
                var query = from c in context.Criminal.Include("CrimesHistory").Include("CrimesHistory.CrimeTypes").Include("CrimesHistory.Adress").Include("CrimesHistory.Adress.City").Include("CrimesHistory.Adress.City.State").Include("CrimesHistory.Adress.City.State.Country").Include("SexType").Include("Adress").Include("Adress.City").Include("Adress.City.State").Include("Adress.City.State.Country")
                            where  (c.Name.Contains(searchTerm) || c.Adress.Street.Contains(searchTerm)) &&
                            (c.Name.Contains(name)) &&
                            ((ageStart == null || c.Age >= ageStart) && (ageEnd == null || c.Age <= ageEnd)) &&
                            (idSex == null || c.IdSexType == idSex) &&
                            (idCountry == null || c.Adress.City.State.IdCountry == idCountry)
                            select c;

                return(query.ToList());
            }
        }
示例#6
0
 public virtual bool DeleteItem(T item)
 {
     try
     {
         using (CriminalContext context = new CriminalContext())
         {
             context.Entry <T>(item).State = System.Data.Entity.EntityState.Deleted;
             return(context.SaveChanges() > 0);
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, ex.Message, null);
         return(false);
     }
 }