Ejemplo n.º 1
0
        public static List <PMS.Entities.ProductDTO> GetAllProducts(Boolean pLoadComments = false)
        {
            var query = "Select * from dbo.Products Where IsActive = 1;";

            using (DBHelper helper = new DBHelper())
            {
                var reader = helper.ExecuteReader(query);
                List <PMS.Entities.ProductDTO> list = new List <PMS.Entities.ProductDTO>();

                while (reader.Read())
                {
                    var dto = FillDTO(reader);
                    if (dto != null)
                    {
                        list.Add(dto);
                    }
                }
                if (pLoadComments == true)
                {
                    // var commentsList = CommentDAO.GetAllComments();

                    var commentsList = CommentDAO.GetTopComments(20);

                    foreach (var prod in list)
                    {
                        List <PMS.Entities.CommentDTO> prodComments = commentsList.Where(c => c.ProductID == prod.ProductID).ToList();
                        prod.Comments = prodComments;
                    }
                }
                return(list);
            }
        }