Ejemplo n.º 1
0
        public IList <Entities.Article> GetArticles(
            int pageIndex,
            int pageSize,
            string searchText,
            out int total,
            out int totalFiltered)
        {
            Expression <Func <Entities.Article, bool> > filter = null;

            filter = x => x.IsActive == true && x.IsDeleted == false && x.Title.Contains(searchText);
            return(_articleRepository.Get(
                       out total,
                       out totalFiltered,
                       filter,
                       x => x.OrderByDescending(b => b.Id),
                       null,
                       null,
                       pageIndex,
                       pageSize));
        }
Ejemplo n.º 2
0
        public void CanDeleteArticlesFromPostgre()
        {
            var articleRepository = new ArticleRepository(dbConnectionString);
            var articleText       = "Test Text";
            var articleTitle      = "Test Title";
            var articleAuthor     = "Bob";

            articleRepository.Add(new Article
            {
                Text   = articleText,
                Title  = articleTitle,
                Author = articleAuthor
            });
            Article article = articleRepository.GetAll().LastOrDefault();

            Assert.NotNull(article);
            articleRepository.Delete(article.Id);
            article = articleRepository.Get(article.Id).Value;

            Assert.IsNull(article);
        }
Ejemplo n.º 3
0
        public ActionResult GetMoveStock_By_ArticleId(int id, string sortOrder, string currentFilter, string searchString, int?page)
        {
            Article entity = _repoArticle.Get(id);

            ViewBag.ArticleRef   = "Article n° " + entity.ArticleId + " - " + entity.Nom;
            ViewBag.BoutonRetour = ($"/Article/Details/{id}");
            ViewBag.CurrentSort  = sortOrder;
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;
            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(_repo.GetMoveStock_By_ArticleId(id).ToPagedList(pageNumber, pageSize)));
        }
Ejemplo n.º 4
0
        public void AddHint(long userId, int articleId)
        {
            var historyHint = ArticleHintRepository.GetAll().Where(model => model.ArticleId == articleId && model.UserId == userId).FirstOrDefault();

            if (historyHint != null)
            {
                return;
            }
            var hint = new ArticleHint()
            {
                ArticleId    = articleId,
                UserId       = userId,
                CreationTime = DateTime.Now,
            };

            ArticleHintRepository.Insert(hint);
            var article = ArticleRepository.Get(articleId);

            article.Hint++;
            ArticleRepository.Update(article);
            CurrentUnitOfWork.SaveChanges();
        }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Exclude = "Category.Name,Category.SefName")] ArticleViewModel model)
 {
     try
     {
         ModelState.Remove("Category.Name");
         ModelState.Remove("Category.SefName");
         if (ModelState.IsValid)
         {
             Article article = ArticleRepository.Get(model.Id);
             article.CategoryId       = model.Category.Id;
             article.IsDraft          = model.IsDraft ? 1 : 0;
             article.PublishEndDate   = model.PublishEndDate;
             article.PublishStartDate = model.PublishStartDate;
             article.Edited           = DateTime.Now;
             article.Title            = model.Title;
             article.Content          = model.Content;
             article.Author           = KBVaultHelperFunctions.UserAsKbUser(User).Id;
             article.SefName          = model.SefName;
             ArticleRepository.Update(article, model.Tags);
             if (article.IsDraft == 0)
             {
                 KbVaultLuceneHelper.AddArticleToIndex(article);
             }
             else
             {
                 KbVaultLuceneHelper.RemoveArticleFromIndex(article);
             }
             ShowOperationMessage(UIResources.ArticleCreatePageEditSuccessMessage);
         }
         return(View("Create", model));
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         ModelState.AddModelError("Exception", ex.Message);
         return(View("Create", model));
     }
 }
        public void Get_Returns_Product_When_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository = new ProductRepository(context);
                var articleRepository = new ArticleRepository(context);

                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var articleToAdd = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(articleToAdd);
                context.SaveChanges();

                //Act
                var article = articleRepository.Get(articleToAdd.Id);

                //Assert
                Assert.IsNotNull(article);
            }
        }
Ejemplo n.º 7
0
        public void CanAddArticleToPostgre()
        {
            var articleRepository = new ArticleRepository(dbConnectionString);
            var articleText       = "Test Text";
            var articleTitle      = "Test Title";
            var articleAuthor     = "Bob";

            articleRepository.Add(new Article
            {
                Text   = articleText,
                Title  = articleTitle,
                Author = articleAuthor
            });

            List <Article> articles = articleRepository.GetAll();

            Assert.IsNotEmpty(articles);

            var article = articleRepository.Get(articles.First().Id).Value;

            Assert.AreEqual(articleText, article.Text);
            Assert.AreEqual(articleTitle, article.Title);
            Assert.AreEqual(articleAuthor, article.Author);
        }
Ejemplo n.º 8
0
        public IActionResult Add(string typeId, string actionstr, int mid)
        {
            var vcName = string.Empty;

            (string typeId, string action, dynamic entry)partParam = (typeId, actionstr, null);
            switch (typeId)
            {
            case "1":
                vcName = "_Add";
                if (actionstr == "1")
                {
                    var mc = _categoryService.Get(mid);
                    partParam = (typeId, actionstr, mc);
                }
                if (actionstr == "0")
                {
                    partParam = (typeId, actionstr, null);
                }
                break;

            case "2":
                vcName = "_Add";
                if (actionstr == "1")
                {
                    (Model.BlogArticle article, IEnumerable <Model.BlogCategory> blogCategories)mac = (_articleService.Get(mid), _categoryService.GetCategorys());
                    partParam = (typeId, actionstr, mac);
                }
                if (actionstr == "0")
                {
                    (Model.BlogArticle article, IEnumerable <Model.BlogCategory> blogCategories)mac = (null, _categoryService.GetCategorys());
                    partParam = (typeId, actionstr, mac);
                }
                break;
            }
            return(PartialView(vcName, partParam));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> EditArticle(string id)
        {
            ArticleModel article = _articleRepository.Get(new Guid(id));

            if (article != null)
            {
                ArticleData model = new ArticleData()
                {
                    Text           = article.Text,
                    Description    = article.Description,
                    Specialty      = article.Specialty,
                    Name           = article.Name,
                    UserId         = article.UserId,
                    Id             = article.Id,
                    CreatedDate    = article.CreatedDate,
                    LastModifeDate = article.LastModifeDate,
                    Tags           = article.Tags.Select(t => t.Tag.Title).ToList()
                };
                return(View(model));
            }
            return(RedirectPermanent("~/ArticleManage/ArticleTable"));
        }
Ejemplo n.º 10
0
        public DTOArticle Get(int id)
        {
            Article article = _articleRepository.Get(id).SingleOrDefault();

            return(mapper.Map <Article, DTOArticle>(article));
        }
Ejemplo n.º 11
0
 public virtual Article GetByID(Guid id)
 {
     return(_articleRepository.Get(id));
 }
Ejemplo n.º 12
0
        public IViewComponentResult Invoke(int max)
        {
            articles = _repository.Get().Take(max).ToList();

            return(View(articles));
        }
Ejemplo n.º 13
0
        public ActionResult UpdateArticleSEO(int id)
        {
            var model = (ArticleModel)articleRepository.Get(id);

            return(View(model));
        }
Ejemplo n.º 14
0
 public BlogArticle Get(int id)
 {
     return(articleRepository.Get(id));
 }
        // GET: Catalog/Article/Details/5
        public ActionResult Details(int id)
        {
            var article = dbArticles.Get(id);

            return(PartialView(article));
        }
        public void Run(Stack <string> links)
        {
            try
            {
                // Scrape article view stack.
                while (links.Count > 0)
                {
                    string link = links.Pop();

                    try
                    {
                        if (_useSleep)
                        {
                            // Sleep for a bit before making next call to look human.
                            int sleep = new Random().Next(_sleepMin, _sleepMax);
                            _log.Info($"Sleeping for {sleep} ms.");
                            Thread.Sleep(sleep);
                        }

                        _log.Info($"Scraping view: {link}");

                        // Web request response will be read into this variable.
                        string data;

                        try
                        {
                            data = Proxy.MakeRequest(link);
                        }
                        catch (Exception ex)
                        {
                            _log.Error("Could not get web response for article view.", ex);
                            continue;
                        }

                        // If no response, skip to next.
                        if (String.IsNullOrEmpty(data))
                        {
                            _log.Error("Skipping view page due to null content.");
                            continue;
                        }

                        // Parse response as HTML document.
                        HtmlDocument doc = new HtmlDocument();
                        doc.LoadHtml(data);

                        // If title doesn't exist, then the article has expired.
                        try
                        {
                            new string(doc.DocumentNode.SelectSingleNode(@"//*[@id=""main-content""]/div[1]/h1/span[1]").InnerText.ToCharArray());
                        }
                        catch (Exception)
                        {
                            _log.Info("Setting article as inactive.");
                            Article inactiveArticle = _articleRepo.Get(x => x.Link == link);
                            inactiveArticle.Active    = false;
                            inactiveArticle.DateEnded = DateTime.Now;
                            _articleRepo.Update(inactiveArticle);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error($"Could not scrape link: {link}", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Fatal("Fatal exception(s) occured in Article View Scraper.", ex);
            }
            finally
            {
                _log.Info("Article View Scraper finished scraping.");
            }
        }
Ejemplo n.º 17
0
 // GET: Articles/Details/5
 public ActionResult Details(int id)
 {
     return(View(articleRepository.Get(id)));
 }
Ejemplo n.º 18
0
 public void OnGet()
 {
     Items = _repository.Get();
 }
Ejemplo n.º 19
0
 public async Task <IActionResult> Get()
 {
     return(Ok(await _articleRepository.Get()));
 }