Exemplo n.º 1
0
        public ActionResult Index(HomeContentPublishedListModel listModel)
        {
            var keywords = "";

            if (!String.IsNullOrEmpty(listModel.Keywords))
            {
                keywords = listModel.Keywords.Trim();
            }

            var models = (from c in db.contents
                          join u in db.users on c.CreatedBy equals u.CreatedBy
                          where c.IsPublished && (c.Title.Contains(keywords) || c.page.PageName.Contains(keywords) || c.Subtitle.Contains(keywords))
                          orderby c.CreatedDate descending
                          select new ContentPublishedEntryViewModel
            {
                Page = c.page.PageName,
                Title = c.Title,
                Url = c.ContentUrl,
                Subtitle = c.Subtitle,
                ImageUrl = c.ImageUrl,
                CreatedBy = u.Email,
                CreatedDate = c.CreatedDate
            });

            listModel.Entries = models.ToPagedList(
                listModel.Page > 0 ? listModel.Page : 1,
                listModel.PageSize > 0 ? listModel.PageSize : 10);

            return(View(listModel));
        }
Exemplo n.º 2
0
        public ActionResult Page(string permalink)
        {
            var urlSplit = permalink.Split('/');

            if (urlSplit.Length > 1)
            {
                var model = (from c in db.contents
                             join u in db.users on c.CreatedBy equals u.CreatedBy
                             where c.ContentUrl == permalink
                             orderby c.CreatedDate descending
                             select new ContentPublishedEntryViewModel
                {
                    Page = c.page.PageName,
                    Title = c.Title,
                    Url = c.ContentUrl,
                    Subtitle = c.Subtitle,
                    ImageUrl = c.ImageUrl,
                    Content = c.Content1,
                    CreatedBy = u.Email,
                    CreatedDate = c.CreatedDate
                }).FirstOrDefault();

                #region HTTP
                var key = ConfigurationManager.AppSettings["VisionKey"];
                ViewBag.Key = key;

                //var url = ConfigurationManager.AppSettings["VisionEndPoint"];

                //var json_serializer = new JavaScriptSerializer();
                //var encoder = new ASCIIEncoding();

                //var jsonData = json_serializer.Serialize(new { url = model.ImageUrl });
                //byte[] data = encoder.GetBytes(jsonData);

                //var jsonParams = json_serializer.Serialize(new {
                //    visualFeatures = "Categories,Description,Color",
                //    details = "",
                //    language = "en" });


                //var request = WebRequest.Create(url + "?" + jsonParams) as HttpWebRequest;
                //request.Method = "POST";
                //request.ContentType = "application/json";
                //request.ContentLength = data.Length;
                //request.GetRequestStream().Write(data, 0, data.Length);
                //request.Headers.Add("Ocp-Apim-Subscription-Key", key);

                //HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                //var responseText = new StreamReader(response.GetResponseStream()).ReadToEnd();
                #endregion

                ViewBag.Title = model.Title;
                return(View("Content", model));
            }
            else
            {
                var page = db.pages.Where(x => x.PageUrl == permalink).FirstOrDefault();
                if (page == null)
                {
                    return(View("NotFound"));
                }

                ViewBag.Title = page.PageName;

                var listModel = new HomeContentPublishedListModel();

                var models = (from c in db.contents
                              join u in db.users on c.CreatedBy equals u.CreatedBy
                              where c.IsPublished && c.page.PageUrl == permalink
                              orderby c.CreatedDate descending
                              select new ContentPublishedEntryViewModel
                {
                    Page = c.page.PageName,
                    Title = c.Title,
                    Url = c.ContentUrl,
                    Subtitle = c.Subtitle,
                    ImageUrl = c.ImageUrl,
                    CreatedBy = u.Email,
                    CreatedDate = c.CreatedDate
                });

                listModel.Entries = models.ToPagedList(
                    listModel.Page > 0 ? listModel.Page : 1,
                    listModel.PageSize > 0 ? listModel.PageSize : 10);

                return(View("Index", listModel));
            }
        }