public void AddTorrentSoftPost(int idReadyPost)
        {
            autoParsingContext context = new autoParsingContext();

            TorrentSoftPost post = new TorrentSoftPost()
            {
                ReadyPost_idReadyPost = idReadyPost,
                WasAdded = DateTime.Now,
            };

            context.TorrentSoftPost.Add(post);
            context.SaveChanges();
        }
        /// <summary>
        /// Получает из бд уже опубликованные на torrentSoft посты
        /// </summary>
        /// <returns></returns>
        public List <TorrentSoftPost> GetPublisedPost()
        {
            autoParsingContext context = new autoParsingContext();

            var publishedQuery =
                from softPost in context.TorrentSoftPost
                orderby softPost.WasAdded descending
                select softPost;

            List <TorrentSoftPost> torrentSofts = publishedQuery.Take(Settings.PublishedCount).ToList();

            return(torrentSofts);
        }
        /// <summary>
        /// Получает из бд только не опубликованные на торрент софт посты
        /// </summary>
        /// <returns></returns>
        public List <ReadyPost> GetNotPublishedPost()
        {
            autoParsingContext context = new autoParsingContext();

            //Получаем повторяющиеся id
            var publishedQuery =
                from softPost in context.TorrentSoftPost
                from readyPost in context.ReadyPost
                where softPost.ReadyPost_idReadyPost == readyPost.idReadyPost
                orderby readyPost.idReadyPost descending
                select readyPost.idReadyPost;
            List <int> publishedId = publishedQuery.Take(Settings.NotPublishedCount).ToList();

            //Выбираем только те id, которые отсутвуют в повторяющихся
            List <ReadyPost> notPublishedPost = context.ReadyPost
                                                .Where(i => !publishedId.Contains(i.idReadyPost))
                                                .OrderByDescending(i => i.idReadyPost)
                                                .Take(Settings.NotPublishedCount)
                                                .ToList();

            return(notPublishedPost);
        }
        public void AddReadyTest()
        {
            autoParsingContext db        = new autoParsingContext();
            FoundPost          foundPost = db.FoundPost.First();
            ReadyPost          readyPost = null;
            bool eventCall = false;

            ParserRutor parserRutor = new ParserRutor();

            parserRutor.ReadyPostsReceived += delegate(object s, ReadyPostArgs e)
            {
                readyPost = e.ReadyPostRecieved;
                eventCall = true;
            };
            parserRutor.StartGetItem(foundPost);
            CommonFunction.SleepTimer(12, ref eventCall);

            DataBaseControl dataBaseControl = new DataBaseControl();

            Assert.IsNotNull(readyPost);
            int actual = dataBaseControl.AddReady(readyPost);

            Assert.AreEqual(9, actual);
        }
 public DataBaseControl()
 {
     Db = new autoParsingContext();
 }
 public DataBaseSoftController()
 {
     Db = new autoParsingContext();
 }