Ejemplo n.º 1
0
 public int AddEntries(List<AnimeEntry> entries)
 {
     using (var dbContext = new AnimeTempEntities())
     {
         foreach (var entry in entries)
         {
             var dbObj = AutoMapper.Mapper.Map<Anime>(entry);
             dbObj.DataUpdatedDate = DateTime.Now;
             dbContext.Animes.Add(dbObj);
             dbContext.SaveChanges();
         }
         return entries.Count;
     }
 }
Ejemplo n.º 2
0
        public List<AnimeEntry> GetNewEntriesToGenerate()
        {
            using (var dbContext = new AnimeTempEntities())
            {

                var dbResults =
                    dbContext.Animes.Where(x => x.StartDate != null && x.SynopsisFileLastGenerated == null).ToList();
                return dbResults.Select(x =>
                    {
                        var animePoco = new AnimeEntry();
                        AutoMapper.Mapper.Map(x, animePoco);
                        return animePoco;
                    })
                                .ToList();
            }
        }
Ejemplo n.º 3
0
        public List<AnimeEntry> GetDetailsToUpdate()
        {
            using (var dbContext = new AnimeTempEntities())
            {
                var dbObjs = dbContext.Animes.Where(x => x.DataUpdatedDate == null).ToList();

                return dbObjs.Select(x => new AnimeEntry(x.Id, x.Title, x.EnglishTitle, x.Synonyms,
                                                         Convert.ToString(x.Score), x.Status,
                                                         x.StartDate == null
                                                             ? ""
                                                             : x.StartDate.Value.ToString("yyyy-MM-dd"),
                                                         x.EndDate == null
                                                             ? ""
                                                             : x.EndDate.Value.ToString("yyyy-MM-dd")
                                                         , x.Synopsis, x.ImageUrl, x.SynopsisFileLastGenerated)).ToList();
            }
        }
Ejemplo n.º 4
0
        public string AddNewSearchTerm(string searchTerm)
        {
            using (var dbContext = new AnimeTempEntities())
            {
                var existing = dbContext.AnimeHomes.Any(x => x.AnimeTitle == searchTerm.Trim());
                if (existing)
                    return searchTerm + " already in db";

                dbContext.AnimeHomes.Add(new AnimeHome()
                {
                    AnimeTitle = searchTerm,
                    downloaded = false,
                });
                dbContext.SaveChanges();

               return searchTerm   + " saved";

            }
        }
Ejemplo n.º 5
0
        public List<AnimeEntry> GetNotInDb(List<AnimeEntry> entries)
        {
            var entryIds = entries.Select(x => x.Id).ToList();

            using (var dbContext = new AnimeTempEntities())
            {

                return  entries.Where(x => entryIds.Except(dbContext.Animes.Select(y => y.Id)).Contains(x.Id)).ToList();
            }
        }
Ejemplo n.º 6
0
 public void UpdateSynopsisFileLastGenerated(int id, DateTime date)
 {
     using (var dbContext = new AnimeTempEntities())
     {
         var dbObj = dbContext.Animes.First(x => x.Id == id);
         dbObj.SynopsisFileLastGenerated = DateTime.Now;
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 7
0
        public void UpdateDetails(AnimeEntry anime)
        {
            using (var dbContext = new AnimeTempEntities())
            {
                //var dbObjs = dbContext.Animes.Where(x => x.DataUpdatedDate == null).ToList();

                var dbObj = dbContext.Animes.First(x => x.Id == anime.Id);
                AutoMapper.Mapper.Map(anime, dbObj);
                dbObj.DataUpdatedDate = DateTime.Now;
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 8
0
        public List<AnimeEntry> Search(string query)
        {
            using (var dbContext = new AnimeTempEntities())
            {
                var dbObjs =
                    dbContext.Animes.Where(
                        x => x.Title.Contains(query) || x.Synonyms.Contains(query) || x.EnglishTitle.Contains(query)).
                              OrderBy(x => x.Title).ToList();

                var animeList = new List<AnimeEntry>();
                foreach (var anime in dbObjs)
              {
                  var animePoco = new AnimeEntry();
                  AutoMapper.Mapper.Map(anime, animePoco);
                    animeList.Add(animePoco);
                }
                return animeList;

            }
        }
Ejemplo n.º 9
0
 public void MarkQueryDownloaded(string query)
 {
     using (var dbContext = new AnimeTempEntities())
     {
         var dbObjs = dbContext.AnimeHomes.Where(x => x.AnimeTitle == query).ToList();
         foreach (var obj in dbObjs)
         {
             obj.downloaded = true;
         }
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public string MarkForDataUpdate(int id)
 {
     using (var dbContext = new AnimeTempEntities())
     {
         var dbObj = dbContext.Animes.First(x => x.Id == id);
         dbObj.SynopsisFileLastGenerated = null;
         dbObj.DataUpdatedDate = null;
         dbContext.SaveChanges();
         return  id + " flag set for refresh";
     }
 }
Ejemplo n.º 11
0
 public List<string> GetSearchTerms()
 {
     using (var dbContext = new AnimeTempEntities())
     {
         return dbContext.AnimeHomes.Where(
                 x => (x.downloaded == null || x.downloaded == false))
                      .OrderBy(x => x.AnimeTitle)
                      .Select(x => x.AnimeTitle)
                      .Distinct()
                      .ToList();
     }
 }