public void GetAll_Returns_10_Products()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository = new ProductRepository(context);
                var articleRepository = new ArticleRepository(context);
                for (int i = 0; i < 10; i++)
                {
                    var product = ProductFactory.CreateValidEntity();
                    productRepository.Add(product);
                    var articleToAdd = ArticleFactory.CreateValidEntity(product);
                    articleRepository.Add(articleToAdd);
                }
                context.SaveChanges();

                //Act
                var articles = articleRepository.GetAll();

                //Assert
                Assert.AreEqual(10, articles.Count());
            }
        }
Example #2
0
        public ActionResult AllArticles(int?page)
        {
            int                 pageSize    = 10;
            int                 pageIndex   = (page ?? 1);
            List <Article>      allArticles = articleRepository.GetAll().ToList();
            List <ArticleModel> articles    = new List <ArticleModel>();

            foreach (var item in allArticles)
            {
                if (item.IsRemove != true)
                {
                    articles.Add(item);
                }
            }
            return(View(articles.ToPagedList(pageIndex, pageSize)));
        }
Example #3
0
        public IActionResult List()
        {
            int memberID = int.Parse(HttpContext.Request.Cookies["ID"]);

            var memberArticles = _articleRepository.GetAll(a => a.MemberID == memberID);

            return(View(memberArticles));
        }
        public void CanLoadArticleDetails()
        {
            var repo = new ArticleRepository();

            var articles = repo.GetAll().ToList();

            Assert.AreEqual(9, articles.Count());

            Assert.AreEqual("Space and you", articles[2].ArticleTitle);
        }
Example #5
0
        public ActionResult Articles()
        {
            IEnumerable <Article> allArticles = articleRepository.GetAll();
            List <ArticleModel>   articles    = new List <ArticleModel>();

            foreach (var a in allArticles)
            {
                articles.Add(a);
            }
            return(View(articles));
        }
Example #6
0
        public void Map_GivenIsValidArticles_ShouldMapCorrectly()
        {
            var articleMapper    = new ArticleMapper();
            var articleRepositry = new ArticleRepository();

            var articles = articleRepositry.GetAll();

            var articlesDto = articleMapper.Map(articles);

            articlesDto.Should().BeEquivalentTo(articles, options =>
                                                options
                                                .Excluding(art => art.LastModified)
                                                .Excluding(art => art.LastModifiedBy)
                                                );
        }
Example #7
0
        // GET: Article
        public ActionResult Index()
        {
            var allArticles = repository.GetAll();
            List <ArticlePreview> articlePreviews = new List <ArticlePreview>();

            foreach (var article in allArticles)
            {
                var articlePreview = new ArticlePreview {
                    Article = article
                };
                articlePreviews.Add(articlePreview);
            }


            return(View(articlePreviews));
        }
        // If fewAticles is true, the method returns as many articles as requested(count). Else returns the number of all articles.
        public List <ArticleListModel> GetArticlesList(bool fewAticles = false, int count = 0)
        {
            List <ArticleListModel> articleListModels;
            List <Article>          articles;

            if (fewAticles && count > 0)
            {
                articles = articleRepository.TakeArticles(count);
            }
            else
            {
                articles = articleRepository.GetAll();
            }
            articleListModels = ArrayMap <Article, ArticleListModel>(articles);
            var result = articleListModels.OrderByDescending(si => si.UpdateDate).ToList();;

            return(result);
        }
Example #9
0
        public void CanGetAllArticlesFromPostgre()
        {
            var articleRepository = new ArticleRepository(dbConnectionString);
            var articleText       = "Test Text";
            var articleTitle      = Guid.NewGuid().ToString();
            var articleAuthor     = "Bob";

            articleRepository.Add(new Article
            {
                Text   = articleText,
                Title  = articleTitle,
                Author = articleAuthor
            });
            IList <Article> articles = articleRepository.GetAll();

            Assert.NotNull(articles);
            Assert.AreEqual(2, articles.Count);
            Assert.IsTrue(articles.Any(x => x.Title == articleTitle));
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
0
        public ActionResult Articles()
        {
            var repo  = new ArticleRepository();
            var model = repo.GetAll().ToList();

            if (User.Identity.IsAuthenticated)
            {
                var user = User.Identity;
                ViewBag.Name = user.Name;

                ViewBag.displayMenu = "No";

                if (IsAdminUser())
                {
                    ViewBag.displayMenu = "Yes";
                }
                return(View(model));
            }
            else
            {
                ViewBag.Name = "Not Logged IN";
            }
            return(View());
        }
Example #13
0
 // GET: Articles/Articles
 public IActionResult Index()
 {
     return(View(_articleRepository.GetAll()));
 }
Example #14
0
 public List <Article> GetAll()
 {
     return(_repository.GetAll());
 }
Example #15
0
 public IEnumerable <IArticle> GetAll() => _articleRepository.GetAll();
Example #16
0
 public IEnumerable <ArticleViewModel> GetArticles()
 {
     return(_articleRepository.GetAll());
 }
Example #17
0
 public virtual IEnumerable <Article> GetAll(object p1, object p2, object p3)
 {
     return(_articleRepository.GetAll((DateTime?)p1, (int?)p2, (int?)p3));
 }
Example #18
0
        public ActionResult Articles()
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Default"));
            }
            List <Article>    articleList              = new List <Article>();
            ArticleRepository articleRepository        = new ArticleRepository();
            Dictionary <int, List <Comment> > comments = new Dictionary <int, List <Comment> >();
            CommentRepository        commentRepository = new CommentRepository();
            Dictionary <int, string> userDictionary    = new Dictionary <int, string>();
            List <int>        subjectId         = new List <int>();
            Teacher           teacher           = new Teacher();
            TeacherRepository teacherRepository = new TeacherRepository();
            Student           student           = new Student();
            StudentRepository studentRepository = new StudentRepository();
            List <Article>    list = new List <Article>();

            if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
                foreach (var item in teacher.CourseSubject)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            else if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Student)))
            {
                student = studentRepository.GetById(AuthenticationManager.LoggedUser.Id);
                List <CourseSubject>    courseSubjectList       = new List <CourseSubject>();
                CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
                courseSubjectList = courseSubjectRepository.GetAll(filter: cs => cs.CourseID == student.CourseID);
                foreach (var item in courseSubjectList)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            subjectId = subjectId.Distinct().ToList();
            foreach (var item in subjectId)
            {
                List <Article> article = articleRepository.GetAll(filter: s => s.Subject.Id == item);
                if (article != null)
                {
                    articleList.AddRange(article);
                }
            }
            articleList = articleList.OrderBy(d => d.DateCreated.TimeOfDay).ToList();
            articleList.Reverse();
            ArticleControllerArticlesVM model              = new ArticleControllerArticlesVM();
            LikeRepository            likeRepository       = new LikeRepository();
            Dictionary <Article, int> ArticlesAndLikeCount = new Dictionary <Article, int>();
            Dictionary <int, bool>    Liked = new Dictionary <int, bool>();
            int    articleId = 0;
            string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
            int    start     = type.LastIndexOf(".") + 1;
            int    positions = type.Length - start;

            type = type.Substring(start, positions);
            foreach (var item in articleList)
            {
                List <Comment> commentedCommentList = new List <Comment>();
                commentedCommentList = commentRepository.GetAll(filter: c => c.Article.Id == item.Id);
                commentedCommentList.OrderBy(c => c.DateCreated.TimeOfDay).ToList();
                commentedCommentList.Reverse();
                foreach (var comment in commentedCommentList)
                {
                    string userName = "";
                    if (comment.UserType == "Teacher")
                    {
                        teacher = teacherRepository.GetById(comment.UserID);
                        if (teacher != null)
                        {
                            userName = teacher.FirstName + " " + teacher.LastName;
                            userDictionary.Add(comment.Id, userName);
                        }
                    }
                    else
                    {
                        student  = studentRepository.GetById(comment.UserID);
                        userName = student.FirstName + " " + student.LastName;
                        userDictionary.Add(comment.Id, userName);
                    }
                }
                comments.Add(item.Id, commentedCommentList);
                int count = likeRepository.GetAll(filter: a => a.ArticleID == item.Id).Count;
                ArticlesAndLikeCount.Add(item, count);
                List <Like> likes = new List <Like>();

                likes = likeRepository.GetAll(l => l.ArticleID == item.Id);
                foreach (var like in likes.Where(l => l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type))
                {
                    Liked.Add(item.Id, true);
                }
                model.ArticleId = item.Id;
                if (Liked.Count != ArticlesAndLikeCount.Count)
                {
                    foreach (var dictionary in ArticlesAndLikeCount.Where(a => a.Key.Id == item.Id))
                    {
                        articleId = item.Id;
                    }
                    Liked.Add(articleId, false);
                }
            }
            model.UserType       = type;
            model.IsLiked        = Liked;
            model.UserID         = AuthenticationManager.LoggedUser.Id;
            model.Articles       = ArticlesAndLikeCount;
            model.CommentList    = comments;
            model.UserDictionary = userDictionary;
            return(View(model));
        }
        public ActionResult Articles()
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return RedirectToAction("Login", "Default");
            }
            List<Article> articleList = new List<Article>();
            ArticleRepository articleRepository = new ArticleRepository();
            Dictionary<int, List<Comment>> comments = new Dictionary<int, List<Comment>>();
            CommentRepository commentRepository = new CommentRepository();
            Dictionary<int, string> userDictionary = new Dictionary<int, string>();
            List<int> subjectId = new List<int>();
            Teacher teacher = new Teacher();
            TeacherRepository teacherRepository = new TeacherRepository();
            Student student = new Student();
            StudentRepository studentRepository = new StudentRepository();
            List<Article> list = new List<Article>();
            if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
                foreach (var item in teacher.CourseSubject)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            else if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Student)))
            {
                student = studentRepository.GetById(AuthenticationManager.LoggedUser.Id);
                List<CourseSubject> courseSubjectList = new List<CourseSubject>();
                CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
                courseSubjectList = courseSubjectRepository.GetAll(filter: cs => cs.CourseID == student.CourseID);
                foreach (var item in courseSubjectList)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            subjectId = subjectId.Distinct().ToList();
            foreach (var item in subjectId)
            {
                List<Article> article = articleRepository.GetAll(filter: s => s.Subject.Id == item);
                if (article != null)
                {
                    articleList.AddRange(article);
                }
            }
            articleList = articleList.OrderBy(d => d.DateCreated.TimeOfDay).ToList();
            articleList.Reverse();
            ArticleControllerArticlesVM model = new ArticleControllerArticlesVM();
            LikeRepository likeRepository = new LikeRepository();
            Dictionary<Article, int> ArticlesAndLikeCount = new Dictionary<Article, int>();
            Dictionary<int, bool> Liked = new Dictionary<int, bool>();
            int articleId = 0;
            string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
            int start = type.LastIndexOf(".") + 1;
            int positions = type.Length - start;
            type = type.Substring(start, positions);
            foreach (var item in articleList)
            {
                List<Comment> commentedCommentList = new List<Comment>();
                commentedCommentList = commentRepository.GetAll(filter: c => c.Article.Id == item.Id);
                commentedCommentList.OrderBy(c => c.DateCreated.TimeOfDay).ToList();
                commentedCommentList.Reverse();
                foreach (var comment in commentedCommentList)
                {
                    string userName = "";
                    if (comment.UserType == "Teacher")
                    {
                        teacher = teacherRepository.GetById(comment.UserID);
                        if (teacher != null)
                        {
                            userName = teacher.FirstName + " " + teacher.LastName;
                            userDictionary.Add(comment.Id, userName);
                        }
                    }
                    else
                    {
                        student = studentRepository.GetById(comment.UserID);
                        userName = student.FirstName + " " + student.LastName;
                        userDictionary.Add(comment.Id, userName);
                    }
                }
                comments.Add(item.Id, commentedCommentList);
                int count = likeRepository.GetAll(filter: a => a.ArticleID == item.Id).Count;
                ArticlesAndLikeCount.Add(item, count);
                List<Like> likes = new List<Like>();

                likes = likeRepository.GetAll(l => l.ArticleID == item.Id);
                foreach (var like in likes.Where(l => l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type))
                {
                    Liked.Add(item.Id, true);
                }
                model.ArticleId = item.Id;
                if (Liked.Count != ArticlesAndLikeCount.Count)
                {
                    foreach (var dictionary in ArticlesAndLikeCount.Where(a => a.Key.Id == item.Id))
                    {
                        articleId = item.Id;
                    }
                    Liked.Add(articleId, false);
                }
            }
            model.UserType = type;
            model.IsLiked = Liked;
            model.UserID = AuthenticationManager.LoggedUser.Id;
            model.Articles = ArticlesAndLikeCount;
            model.CommentList = comments;
            model.UserDictionary = userDictionary;
            return View(model);
        }
Example #20
0
        public List <ArticleDto> GetAll()
        {
            List <Article> articles = _articleRepository.GetAll();

            return(_articleMapper.Map(articles));
        }
Example #21
0
        public void EditProductJustDocument()
        {
            var inizio = DateTime.Now;

            IDocumentRepository docRep = new DocumentRepository();
            IProductRepository prodRep = new ProductRepository();

            PapiroService p = new PapiroService();
            p.DocumentRepository = docRep;
            p.CostDetailRepository = new CostDetailRepository();
            p.TaskExecutorRepository = new TaskExecutorRepository();
            p.ArticleRepository = new ArticleRepository();

            Document doc = docRep.GetEstimateEcommerce("000001");
            doc.EstimateNumber = "0";

            DocumentProduct dp = docRep.GetDocumentProductsByCodProduct("").FirstOrDefault();

            //work with product
            Product prod = p.InitProduct("SuppRigidi", new ProductTaskNameRepository(), new FormatsNameRepository(), new TypeOfTaskRepository());

            //------passaggio del prodotto inizializzato all'ecommerce o alla view
            prod.CodProduct = prodRep.GetNewCode(prod);
            prod.ProductParts.FirstOrDefault().Format = "15x21";
            prod.ProductParts.FirstOrDefault().SubjectNumber = 1;

            var art = prod.ProductParts.FirstOrDefault().ProductPartPrintableArticles.FirstOrDefault();

            #region Printable Article

            IArticleRepository artRep = new ArticleRepository();
            var artFormList = artRep.GetAll().OfType<RigidPrintableArticle>().FirstOrDefault();

            art.TypeOfMaterial = artFormList.TypeOfMaterial;
            art.NameOfMaterial = artFormList.NameOfMaterial;
            art.Weight = artFormList.Weight;
            art.Color = artFormList.Color;
            #endregion

            //------ritorno del prodotto modificato!!!!

            //rigenero
            prodRep.Add(prod);
            prodRep.Save();

            #region ViewModel
            ProductViewModel pv = new ProductViewModel();
            pv.Product = prod;
            //            prod.ProductCodeRigen();

            pv.Quantity = 10;
            #endregion

            p.EditOrCreateAllCost(dp.CodDocumentProduct);

            var fine = DateTime.Now.Subtract(inizio).TotalSeconds;

            Assert.IsTrue(fine < 4);
        }
Example #22
0
        // GET: Articles
        public ActionResult Index()
        {
            IEnumerable <Article> articles = articleRepository.GetAll();

            return(View(articles));
        }