예제 #1
0
 public ActionResult Add(WhatsNewItem model)
 {
     if (ModelState.IsValid == true)
     {
         model.DatePosted = DateTime.UtcNow;
         Db.WhatsNewItems.Add(model);
         Db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
예제 #2
0
        private void BindData()
        {
            List<NewsItem> newsItems = new List<NewsItem>();

            Item[] items = ContextItem.InnerItem.Axes.SelectItems(String.Format("descendant::*[@@tid='{0}']", NewsItem.TemplateId));

            if (SharedRoot != null)
            {
                Item[] sharedNews = SharedRoot.InnerItem.Axes.SelectItems(String.Format("descendant::*[@@tid='{0}' and @#Publish to all clubs#='1']", SharedNewsItem.TemplateId));

                if (sharedNews != null)
                {
                    List<NewsItem> convertedItems = sharedNews.ToList().ConvertAll(X => new NewsItem(X));

                    WhatsNewItem whatsNewItem = new WhatsNewItem(Sitecore.Context.Item);
                    if (!String.IsNullOrEmpty(whatsNewItem.Sharednewscutoff.Raw))
                    {
                        convertedItems =
                            convertedItems.Where(x => x.Date.DateTime >= whatsNewItem.Sharednewscutoff.DateTime).ToList();
                    }

                    newsItems.AddRange(convertedItems);
                }
            }

            if (items != null)
            {
                newsItems.AddRange(items.ToList().ConvertAll(X => new NewsItem(X)));
            }

            if (newsItems.Count > 0)
            {
                //Hide pager if we can show all items in one page.
                if (newsItems.Count <= pageSize)
                {
                    ArticlePager.Visible = false;
                }

                //Latest news items first
                newsItems.Sort(delegate(NewsItem itmY, NewsItem itmX)
                {
                    return itmX.Date.DateTime.CompareTo(itmY.Date.DateTime);
                });

                NewList.DataSource = newsItems;
                NewList.DataBind();
            }
            else
            {
                ArticlePager.Visible = false;
                NewList.DataSource = newsItems;
                NewList.DataBind();
            }
        }