예제 #1
0
 public Film GetFilInfo(int id)
 {
     using (StarWarsEntities1 ent = new StarWarsEntities1())
     {
         return(ent.Film.Where(x => x.Id == id).FirstOrDefault());
     }
 }
예제 #2
0
 public List <Film> GetLastVisited()
 {
     using (StarWarsEntities1 ent = new StarWarsEntities1())
     {
         return(ent.Film.Where(x => x.visited).OrderByDescending(x => x.edited).Take(2).ToList());
     }
 }
예제 #3
0
 public bool CheckLastUpdate()
 {
     using (StarWarsEntities1 ent = new StarWarsEntities1())
     {
         var Check = ent.Film.OrderBy(x => x.edited).Select(x => x.edited).FirstOrDefault();
         if (Check == null)
         {
             return(true);
         }
         return(DateTime.Parse(Check.Value.ToShortDateString()) < DateTime.Parse(DateTime.UtcNow.ToShortDateString()));
     }
 }
예제 #4
0
 public void UpdateData()
 {
     try
     {
         if (_dataAcces.CheckLastUpdate())
         {
             string json = _dataAcces.GetData();
             var    data = MapData(json);
             using (Data.Entity.StarWarsEntities1 ent = new StarWarsEntities1())
             {
                 foreach (var item in data)
                 {
                     var id   = int.Parse(item.episode_id);
                     var film = ent.Film.Where(x => x.Id == id).FirstOrDefault();
                     if (film != null)
                     {
                         film.opening_crawl = item.opening_crawl;
                         film.director      = item.director;
                         film.producer      = item.producer;
                         film.url           = item.url;
                         film.Title         = item.title;
                         film.edited        = DateTime.Now;
                         film.releasedate   = DateTime.Parse(item.release_date.Replace('-', '/'));
                         film.visited       = false;
                     }
                     else
                     {
                         ent.Film.Add(new Film()
                         {
                             Id            = int.Parse(item.episode_id),
                             opening_crawl = item.opening_crawl,
                             director      = item.director,
                             producer      = item.producer,
                             url           = item.url,
                             Title         = item.title,
                             created       = DateTime.Now,
                             edited        = DateTime.Now,
                             releasedate   = DateTime.Parse(item.release_date.Replace('-', '/'))
                         });
                     }
                 }
                 ent.SaveChanges();
             }
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             string mess = e.InnerException.ToString();
         }
     }
 }
예제 #5
0
 public List <Film> GetResults(String Title)
 {
     using (StarWarsEntities1 ent = new StarWarsEntities1())
     {
         var List = ent.Film.Where(x => x.Title.ToLower().Contains(Title.ToLower())).ToList();
         if (List.Count > 0)
         {
             foreach (var it in List)
             {
                 var film = ent.Film.Where(x => x.Id == it.Id).FirstOrDefault();
                 film.edited  = DateTime.Now;
                 film.visited = true;
             }
         }
         ent.SaveChanges();
         return(List);
     }
 }