Exemplo n.º 1
0
    private List <string> GetRespectivePublishedVersions(string versionGroupId, string versionNumber)
    {
        IList <VersionItem> versions = VersionManager.GetAllVersions(versionGroupId);
        string versionMajorSuffix    = versionNumber.Split('.').First();

        List <string> publishedNewsItems = new List <string>();

        foreach (VersionItem version in versions)
        {
            string tempVerMajorSuffix = version.VersionNumber.Split('.').First();
            if (versionMajorSuffix.Equals(tempVerMajorSuffix))
            {
                string pubId = ItemApprovalStatusManager.GetStatusByName("Published").Id;
                Item   itemX = NewsManager.GetItem(version.ItemId);

                if (itemX != null)
                {
                    if (itemX.ApprovalStatus != null && itemX.ApprovalStatus.Id.Equals(pubId))
                    {
                        //add only published items
                        publishedNewsItems.Add(itemX.Id);
                    }
                }
            }
        }
        return(publishedNewsItems);
    }
        public override void DeleteItemByGroup(string groupID)
        {
            IList <VersionItem> versionsToDelete = VersionManager.GetAllVersions(groupID);

            foreach (VersionItem versToDelete in versionsToDelete)
            {
                Item item = NewsManager.GetItem(versToDelete.ItemId);
                NewsManager.DeleteItem(item);
                VersionManager.DeleteVersionItem(versToDelete);
            }
        }
Exemplo n.º 3
0
    protected void AddNewsToList(List <NewsGridItem> newsGridItems, string categoryName, IList <NewsGridItem> itemList)
    {
        if (!string.IsNullOrEmpty(categoryName))
        {
            //get all grid items which match the filter.
            IList <NewsGridItem> gridItems = GetCategoryByLikeName(categoryName, itemList);

            foreach (NewsGridItem gItem in gridItems)
            {
                List <Item> newsItems = new List <Item>();
                //get all versions by groupID

                IList <VersionItem> versionedItems = VersionManager.GetAllVersions(gItem.Draft.GroupId);

                //get the published news item for the version and add it to the list.
                foreach (VersionItem item in versionedItems)
                {
                    //add all published ones to newsItems list
                    string pubId = ItemApprovalStatusManager.GetStatusByName("Published").Id;
                    Item   itemX = NewsManager.GetItem(item.ItemId);
                    if (itemX != null)
                    {
                        if (itemX.Category.Id.Equals(gItem.NewsItem.Category.Id))
                        {
                            if (itemX.ApprovalStatus.Id.Equals(pubId))
                            {
                                newsItems.Add(itemX);
                            }
                        }
                    }
                }
                //sort the published versions by date inserted- DESC and get the first one.
                if (newsItems.Count > 0)
                {
                    //if the grid item does not exist
                    Item newsItem = newsItems.OrderByDescending(x => x.InsertDate).First <Item>();
                    if (newsItem.Category.Id.Equals(gItem.NewsItem.Category.Id))
                    {
                        if (newsGridItems.Exists(x => x.Draft.GroupId.Equals(gItem.Draft.GroupId)) == false)
                        {
                            newsGridItems.Add(new NewsGridItem()
                            {
                                Draft = gItem.Draft, NewsItem = newsItem, TrafficLightUrl = GetUserStatus(newsItem, gItem.Draft.GroupId)
                            });
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
        public static int CountItems(IList <Item> items, string username)
        {
            if (items != null && items.Count > 0)
            {
                IList <VersionItem> vItems = new List <VersionItem>();
                foreach (Item item1 in items)
                {
                    VersionItem v = VersionManager.GetVersionByItemId(item1.Id);
                    if (v != null)
                    {
                        VersionItem         latest   = new VersionItem();
                        IList <VersionItem> versions = VersionManager.GetAllVersions(v.GroupId);

                        foreach (VersionItem version in versions)
                        {
                            if (VersionManager.IsLatestVersion(version.Id))
                            {
                                latest = version;
                            }
                        }
                        if (latest == null)
                        {
                            if (SecurityHelper.CanUserEdit(username, item1.Category.Id) || SecurityHelper.CanUserContribute(username, item1.Category.Id))
                            {
                                vItems.Add(v);
                            }
                        }
                        else
                        {
                            Item item2 = NewsManager.GetItem(latest.ItemId);
                            if ((SecurityHelper.CanUserView(username, item2.Category.Id) && item2.ApprovalStatus.Name == "Published") ||
                                (SecurityHelper.CanUserContribute(username, item2.Category.Id) && item2.Owner.ToLower() == username.ToLower()) ||
                                (SecurityHelper.CanUserEdit(username, item2.Category.Id)))
                            {
                                if (item1.Category.Id == item2.Category.Id)
                                {
                                    vItems.Add(v);
                                }
                            }
                        }
                    }
                }
                IEnumerable <VersionItem> disItems = vItems.Distinct(new KeyEqualityComparer <VersionItem>(x => x.GroupId));

                return(disItems.Count());
            }
            return(0);
        }
Exemplo n.º 5
0
        public static Item GetPublishedItem(string groupId)
        {
            IList <VersionItem> versions       = VersionManager.GetAllVersions(groupId);
            List <Item>         publishedItems = new List <Item>();

            foreach (VersionItem version in versions)
            {
                Item newsItem = GetItem(version.ItemId);
                ItemApprovalStatus approvalStatus = ItemApprovalStatusManager.GetStatusByName("Published");
                if (newsItem.ApprovalStatus.Id.Equals(approvalStatus.Id))
                {
                    publishedItems.Add(newsItem);
                }
            }
            if (publishedItems.Count > 0)
            {
                return(publishedItems.OrderByDescending(x => x.InsertDate).First <Item>());
            }
            else
            {
                return(new Item());
            }
        }
Exemplo n.º 6
0
    public void Bind(IList <Category> categories)
    {
        var items = new List <Item>();
        List <NewsGridItem> gridItems = new List <NewsGridItem>();

        //change this to include ItemTypeId(news,Doco,Forum) so it only search selected versions.
        List <VersionItem> latestDrafts = VersionManager.GetAllLatestDrafts();

        //Binding all Published news with their corresponding latest version.

        foreach (VersionItem draft in latestDrafts)
        {
            List <Item> newsItems = new List <Item>();
            //get all versions by groupID
            IList <VersionItem> versionedItems = VersionManager.GetAllVersions(draft.GroupId);

            foreach (VersionItem item in versionedItems)
            {
                //add all published ones to newsItems list
                string pubId = ItemApprovalStatusManager.GetStatusByName("Published").Id;
                Item   itemX = NewsManager.GetItem(item.ItemId);
                if (itemX != null)
                {
                    if (itemX.ApprovalStatus != null)
                    {
                        if (itemX.ApprovalStatus.Id.Equals(pubId) && item.Deleted == false)
                        {
                            newsItems.Add(itemX);
                        }
                    }
                }
            }
            //sort them by date inserted- DESC and get the first one.
            if (newsItems.Count > 0)
            {
                Item newsItem = newsItems.OrderByDescending(x => x.InsertDate).First <Item>();
                gridItems.Add(new NewsGridItem()
                {
                    Draft = draft, NewsItem = newsItem
                });
            }
            else//no published item found - get the latest draft and its corresponding newsItem
            {
                VersionItem latestDraft = VersionManager.GetVersionByGroupId(draft.GroupId);
                Item        newsItem    = NewsManager.GetItem(latestDraft.ItemId);
                gridItems.Add(new NewsGridItem()
                {
                    Draft = draft, NewsItem = newsItem
                });
            }
        }

        //do a 1-1 news & draft comparison to check whether all news have corresponding draft or not if not then add it to the grid. Pressing edit will create its first version.
        foreach (Category category in categories)
        {
            IList <Item> childItems = NewsManager.GetItems(category, false);

            foreach (Item newsItem in childItems)
            {
                VersionItem versionItem = VersionManager.GetVersionByItemId(newsItem.Id);
                if (versionItem == null && newsItem.ApprovalStatus == null)
                {
                    versionItem         = new VersionItem();
                    versionItem.ItemId  = newsItem.Id;
                    versionItem.GroupId = newsItem.Id;
                    gridItems.Add(new NewsGridItem()
                    {
                        Draft = versionItem, NewsItem = newsItem
                    });
                }
            }
        }

        List <NewsGridItem> gridItemsPermission = new List <NewsGridItem>();

        foreach (var gi in gridItems)
        {
            if (gi.NewsItem != null)
            {
                if (SecurityHelper.CanUserEdit(Page.User.Identity.Name, gi.NewsItem.Category.Id) ||
                    SecurityHelper.CanUserContribute(Page.User.Identity.Name, gi.NewsItem.Category.Id))
                {
                    gridItemsPermission.Add(gi);
                }
            }
        }

        RadGridManage.DataSource = gridItemsPermission;
    }
Exemplo n.º 7
0
    protected void BindVersions()
    {
        IList <VersionItem> versions = VersionManager.GetAllVersions(GroupId);

        ctrlVersionHistory.SetDataSource(versions);
    }